修复讲解语音切换后播放器未刷新
- 暂停时切换语言或男女声同步刷新音轨、时长和进度 - 保持暂停状态,播放中继续自动切换新音轨 - 补充语音切换播放器刷新回归测试 Made-with: Proma
This commit is contained in:
@@ -12,6 +12,7 @@ const mocks = vi.hoisted(() => ({
|
||||
loadExplainDetailText: vi.fn(),
|
||||
selectAudioForExplainDetail: vi.fn(),
|
||||
play: vi.fn(),
|
||||
prepare: vi.fn(),
|
||||
pause: vi.fn(),
|
||||
resume: vi.fn(),
|
||||
close: vi.fn(),
|
||||
@@ -61,8 +62,15 @@ vi.mock('@/usecases/guideUseCase', () => ({
|
||||
vi.mock('@/composables/useGlobalAudioPlayer', () => ({
|
||||
useGlobalAudioPlayer: () => ({
|
||||
...audioState,
|
||||
isCurrentSource: () => false,
|
||||
isCurrentSource: (source: { stopId?: string, lang?: string, channelCode?: string }) => Boolean(
|
||||
audioState.currentAudio.value
|
||||
&& audioState.currentSource.value
|
||||
&& audioState.currentSource.value.stopId === source.stopId
|
||||
&& (!source.lang || audioState.currentSource.value.lang === source.lang)
|
||||
&& (!source.channelCode || audioState.currentSource.value.channelCode === source.channelCode)
|
||||
),
|
||||
play: mocks.play,
|
||||
prepare: mocks.prepare,
|
||||
pause: mocks.pause,
|
||||
resume: mocks.resume,
|
||||
switchLanguage: vi.fn(),
|
||||
@@ -346,6 +354,81 @@ describe('讲解详情音频优先布局', () => {
|
||||
}))
|
||||
})
|
||||
|
||||
it('暂停时切换语言立即刷新播放器但不自动播放', async () => {
|
||||
const bilingualExhibit = {
|
||||
...exhibit,
|
||||
audioLanguage: 'en-US',
|
||||
audioOptions: [
|
||||
{ channelCode: 'standard.zh-CN.female', version: 'standard', languageCode: 'zh-CN', gender: 'female', playUrl: '/assets/zh-female.mp3', duration: 50 },
|
||||
{ channelCode: 'standard.en-US.female', version: 'standard', languageCode: 'en-US', gender: 'female', playUrl: '/assets/en-female.mp3', duration: 80 }
|
||||
]
|
||||
}
|
||||
mocks.enterExplainDetail.mockResolvedValue(bilingualExhibit)
|
||||
mocks.selectAudioForExplainDetail.mockImplementation(async (data: { audioLanguage: string }) => {
|
||||
const option = bilingualExhibit.audioOptions.find((item) => item.languageCode === data.audioLanguage)!
|
||||
return {
|
||||
playable: true,
|
||||
exhibit: bilingualExhibit,
|
||||
media: { id: option.channelCode, url: option.playUrl, duration: option.duration, language: option.languageCode },
|
||||
playInfo: { title: exhibit.name }
|
||||
}
|
||||
})
|
||||
audioState.currentAudio.value = { id: 'standard.en-US.female', audioUrl: '/assets/en-female.mp3' }
|
||||
audioState.currentSource.value = { stopId: 'stop-1', lang: 'en-US', channelCode: 'standard.en-US.female' }
|
||||
audioState.playing.value = false
|
||||
const wrapper = mount(ExhibitDetail, {
|
||||
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
|
||||
})
|
||||
|
||||
await mocks.onLoadHandler?.({ id: exhibit.id, stopId: 'stop-1', lang: 'en-US' })
|
||||
await flushPromises()
|
||||
await wrapper.findAll('.language-option').find((button) => button.text() === '中文')!.trigger('tap')
|
||||
await flushPromises()
|
||||
|
||||
expect(mocks.prepare).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ audioUrl: '/assets/zh-female.mp3', language: 'zh-CN', duration: 50 }),
|
||||
expect.objectContaining({ source: expect.objectContaining({ lang: 'zh-CN', channelCode: 'standard.zh-CN.female' }) })
|
||||
)
|
||||
expect(mocks.play).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('暂停时切换男女声立即刷新播放器但不自动播放', async () => {
|
||||
const voiceExhibit = {
|
||||
...exhibit,
|
||||
audioOptions: [
|
||||
{ channelCode: 'standard.en-US.female', version: 'standard', languageCode: 'en-US', gender: 'female', playUrl: '/assets/en-female.mp3', duration: 80 },
|
||||
{ channelCode: 'standard.en-US.male', version: 'standard', languageCode: 'en-US', gender: 'male', playUrl: '/assets/en-male.mp3', duration: 75 }
|
||||
]
|
||||
}
|
||||
mocks.enterExplainDetail.mockResolvedValue(voiceExhibit)
|
||||
mocks.selectAudioForExplainDetail.mockImplementation(async (_data: unknown, options: { voiceGender?: string }) => {
|
||||
const option = voiceExhibit.audioOptions.find((item) => item.gender === options.voiceGender)!
|
||||
return {
|
||||
playable: true,
|
||||
exhibit: voiceExhibit,
|
||||
media: { id: option.channelCode, url: option.playUrl, duration: option.duration, language: option.languageCode },
|
||||
playInfo: { title: exhibit.name }
|
||||
}
|
||||
})
|
||||
audioState.currentAudio.value = { id: 'standard.en-US.female', audioUrl: '/assets/en-female.mp3' }
|
||||
audioState.currentSource.value = { stopId: 'stop-1', lang: 'en-US', channelCode: 'standard.en-US.female' }
|
||||
audioState.playing.value = false
|
||||
const wrapper = mount(ExhibitDetail, {
|
||||
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
|
||||
})
|
||||
|
||||
await mocks.onLoadHandler?.({ id: exhibit.id, stopId: 'stop-1', lang: 'en-US' })
|
||||
await flushPromises()
|
||||
await wrapper.get('.detail-audio-voice').trigger('tap')
|
||||
await flushPromises()
|
||||
|
||||
expect(mocks.prepare).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ audioUrl: '/assets/en-male.mp3', duration: 75 }),
|
||||
expect.objectContaining({ source: expect.objectContaining({ voiceGender: 'male', channelCode: 'standard.en-US.male' }) })
|
||||
)
|
||||
expect(mocks.play).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('播放器单行提供倍速循环和男女声切换', async () => {
|
||||
mocks.enterExplainDetail.mockResolvedValue({
|
||||
...exhibit,
|
||||
|
||||
Reference in New Issue
Block a user