适配讲解详情聚合接口
This commit is contained in:
@@ -25,6 +25,7 @@ const createStopInfo = (overrides: Partial<GuideStopInfo> = {}): GuideStopInfo =
|
||||
hasAudio: false,
|
||||
hasText: false,
|
||||
supportedLanguages: [],
|
||||
languageVariants: {},
|
||||
audioStatus: 'MISSING',
|
||||
...overrides
|
||||
})
|
||||
@@ -99,4 +100,60 @@ describe('ExplainUseCase stop image policy', () => {
|
||||
expect(detail.image).toBe('/guide-stop.jpg')
|
||||
expect(detail.galleryUrls).toEqual(['/guide-stop-gallery.jpg'])
|
||||
})
|
||||
|
||||
it('uses stop-info language variants locally without requesting play-info or text-info', async () => {
|
||||
const audio = {
|
||||
getStopInfo: vi.fn().mockResolvedValue(createStopInfo({
|
||||
hasAudio: true,
|
||||
hasText: true,
|
||||
supportedLanguages: ['zh-CN', 'yue-HK'],
|
||||
languageVariants: {
|
||||
'zh-CN': {
|
||||
lang: 'zh-CN',
|
||||
enabled: true,
|
||||
playable: true,
|
||||
playUrl: '/audio/zh.mp3',
|
||||
duration: 50,
|
||||
hasText: true,
|
||||
textAvailable: true,
|
||||
text: '普通话讲解词',
|
||||
fallback: false,
|
||||
audioStatus: 'READY'
|
||||
},
|
||||
'yue-HK': {
|
||||
lang: 'yue-HK',
|
||||
enabled: true,
|
||||
playable: true,
|
||||
playUrl: '/audio/yue.mp3',
|
||||
duration: 52,
|
||||
hasText: true,
|
||||
textAvailable: true,
|
||||
text: '粤语通道使用普通话文案',
|
||||
fallback: false,
|
||||
audioStatus: 'READY'
|
||||
}
|
||||
} as GuideStopInfo['languageVariants']
|
||||
})),
|
||||
getPlayInfo: vi.fn(),
|
||||
getTextInfo: vi.fn()
|
||||
} as unknown as AudioPlayInfoRepository
|
||||
const explain = {
|
||||
getExhibitById: vi.fn(),
|
||||
listExplainExhibits: vi.fn()
|
||||
} as unknown as ExplainRepository
|
||||
const useCase = new ExplainUseCase(explain, audio)
|
||||
|
||||
const detail = await useCase.enterExplainDetail({
|
||||
exhibitId: 'stop-1', targetType: 'STOP', targetId: 'stop-1', lang: 'zh-CN'
|
||||
})
|
||||
const cantonese = useCase.selectExplainDetailLanguage(detail, 'yue-HK')
|
||||
|
||||
expect(detail.guideText).toBe('普通话讲解词')
|
||||
expect(detail.audioUrl).toBe('/audio/zh.mp3')
|
||||
expect(cantonese.guideText).toBe('粤语通道使用普通话文案')
|
||||
expect(cantonese.audioUrl).toBe('/audio/yue.mp3')
|
||||
expect(cantonese.audioDuration).toBe(52)
|
||||
expect((audio as any).getPlayInfo).not.toHaveBeenCalled()
|
||||
expect((audio as any).getTextInfo).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user