按接口能力展示讲解语言
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-17 18:05:23 +08:00
parent 3d4f4c1d9a
commit 7267dfcac1
2 changed files with 88 additions and 5 deletions

View File

@@ -86,7 +86,8 @@ const exhibit = {
audioLanguage: 'en-US',
audioHasText: false,
playTargetType: 'STOP',
playTargetId: 'stop-1'
playTargetId: 'stop-1',
supportedLanguages: ['zh-CN', 'yue-HK', 'en-US']
}
describe('讲解详情音频优先布局', () => {
@@ -148,6 +149,59 @@ describe('讲解详情音频优先布局', () => {
expect(wrapper.get('.section-text').text()).toContain('detailed English narration')
})
it('仅展示 stop-info 声明支持的语言按钮', async () => {
mocks.enterExplainDetail.mockResolvedValue({
...exhibit,
supportedLanguages: ['zh-CN', 'en-US']
})
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
})
await mocks.onLoadHandler?.({ id: exhibit.id, lang: 'zh-CN', targetType: 'STOP', targetId: 'stop-1' })
await flushPromises()
const labels = wrapper.findAll('.language-option-text').map((node) => node.text())
expect(labels).toEqual(['中文', 'English'])
expect(labels).not.toContain('粤语')
})
it('无支持语言时不显示语言栏', async () => {
mocks.enterExplainDetail.mockResolvedValue({
...exhibit,
supportedLanguages: []
})
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
})
await mocks.onLoadHandler?.({ id: exhibit.id, lang: 'zh-CN', targetType: 'STOP', targetId: 'stop-1' })
await flushPromises()
expect(wrapper.find('.detail-language-bar').exists()).toBe(false)
})
it('深链语言不受支持时回退至中文并规范化地址', async () => {
mocks.enterExplainDetail.mockImplementation(async (request: { lang: string }) => ({
...exhibit,
audioLanguage: request.lang,
supportedLanguages: ['zh-CN']
}))
const replaceState = vi.spyOn(window.history, 'replaceState')
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
})
await mocks.onLoadHandler?.({ id: exhibit.id, lang: 'en-US', targetType: 'STOP', targetId: 'stop-1' })
await flushPromises()
expect(mocks.enterExplainDetail).toHaveBeenNthCalledWith(1, expect.objectContaining({ lang: 'en-US' }))
expect(mocks.enterExplainDetail).toHaveBeenNthCalledWith(2, expect.objectContaining({ lang: 'zh-CN' }))
expect(wrapper.get('.language-option').classes()).toContain('active')
expect(wrapper.get('.language-option-text').text()).toBe('中文')
expect(replaceState).toHaveBeenCalledWith(null, '', expect.stringContaining('lang=zh-CN'))
})
it('通过同一全局音频播放器开始播放,不创建页面播放器', async () => {
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }