Files
frontend-miniapp/tests/unit/AudioPlayInfoRepository.spec.ts
lyf 9ea1bfab71
Some checks failed
CI / verify (push) Has been cancelled
同步 sgs-frontend-mobile 源码
2026-07-27 11:26:01 +08:00

48 lines
1.6 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { DefaultAudioPlayInfoRepository } from '@/repositories/AudioPlayInfoRepository'
const stopInfoResponse = {
code: 0,
data: {
available: true,
targetType: 'STOP',
targetId: 'stop-1',
resolvedStopId: 'stop-1',
lang: 'zh-CN',
title: '测试讲解点',
description: '测试简介',
imageStatus: 'READY',
imageSource: 'STOP',
galleryUrls: '[]',
playTargetType: 'STOP',
playTargetId: 'stop-1',
hasAudio: false,
hasText: true,
supportedLanguages: ['zh-CN'],
audioStatus: 'MISSING',
audioOptions: []
}
}
describe('DefaultAudioPlayInfoRepository stop-info loading mode', () => {
afterEach(() => vi.unstubAllGlobals())
it('defaults H5 detail requests to lightweight mode and keeps its cache separate from legacy mode', async () => {
const requestUrls: string[] = []
vi.stubGlobal('uni', {
request: ({ url, success }: { url: string, success: (response: unknown) => void }) => {
requestUrls.push(url)
success({ statusCode: 200, data: stopInfoResponse })
}
})
const repository = new DefaultAudioPlayInfoRepository()
await repository.getStopInfo({ targetType: 'STOP', targetId: 'stop-1', lang: 'zh-CN' })
await repository.getStopInfo({ targetType: 'STOP', targetId: 'stop-1', lang: 'zh-CN', lightweight: false })
expect(requestUrls).toHaveLength(2)
expect(new URL(requestUrls[0], 'http://localhost').searchParams.get('lightweight')).toBe('true')
expect(new URL(requestUrls[1], 'http://localhost').searchParams.get('lightweight')).toBe('false')
})
})