79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { toGuideStopInfo } from '@/data/adapters/guideStopInfoAdapter'
|
|
|
|
describe('guide stop-info adapter', () => {
|
|
it('normalizes aggregated language variants and exposes only displayable languages', () => {
|
|
const result = toGuideStopInfo({
|
|
available: true,
|
|
targetType: 'STOP',
|
|
targetId: '9001',
|
|
lang: 'zh-CN',
|
|
imageStatus: 'READY',
|
|
coverImageUrl: '/museum-assets/cover.webp',
|
|
languageVariants: [
|
|
{
|
|
lang: 'zh',
|
|
enabled: true,
|
|
playable: true,
|
|
audioStatus: 'READY',
|
|
playUrl: '/museum-assets/audio/zh.mp3',
|
|
duration: '50',
|
|
audioId: 12,
|
|
hasText: true,
|
|
textAvailable: true,
|
|
text: '普通话讲解词',
|
|
textLength: '6',
|
|
textHash: 'zh-hash'
|
|
},
|
|
{
|
|
lang: 'yue-HK',
|
|
enabled: true,
|
|
playable: false,
|
|
audioStatus: 'MISSING',
|
|
textAvailable: true,
|
|
text: '粤语使用普通话文案',
|
|
reason: 'NO_PUBLISHED_AUDIO'
|
|
},
|
|
{
|
|
lang: 'en-US',
|
|
enabled: false,
|
|
playable: true,
|
|
playUrl: '/museum-assets/audio/en.mp3'
|
|
}
|
|
]
|
|
}, {
|
|
targetType: 'STOP',
|
|
targetId: '9001',
|
|
lang: 'zh-CN'
|
|
})
|
|
|
|
expect(result.supportedLanguages).toEqual(['zh-CN', 'yue-HK'])
|
|
expect(result.languageVariants['zh-CN']).toMatchObject({
|
|
playable: true,
|
|
playUrl: '/museum-assets/audio/zh.mp3',
|
|
duration: 50,
|
|
audioId: '12',
|
|
text: '普通话讲解词',
|
|
textLength: 6
|
|
})
|
|
expect(result.languageVariants['yue-HK']).toMatchObject({
|
|
playable: false,
|
|
textAvailable: true,
|
|
reason: 'NO_PUBLISHED_AUDIO'
|
|
})
|
|
})
|
|
|
|
it('keeps supportedLanguages as the compatibility fallback when variants are absent', () => {
|
|
const result = toGuideStopInfo({
|
|
supportedLanguages: ['zh-CN', 'en-US']
|
|
}, {
|
|
targetType: 'STOP',
|
|
targetId: '9001',
|
|
lang: 'zh-CN'
|
|
})
|
|
|
|
expect(result.supportedLanguages).toEqual(['zh-CN', 'en-US'])
|
|
expect(result.languageVariants).toEqual({})
|
|
})
|
|
})
|