修复讲解详情页退出音频清理
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-17 23:08:45 +08:00
parent 72d1f30c89
commit b8ab414bac
2 changed files with 44 additions and 6 deletions

View File

@@ -6,6 +6,8 @@ import { flushPromises, mount } from '@vue/test-utils'
const mocks = vi.hoisted(() => ({
onLoadHandler: null as null | ((options?: Record<string, unknown>) => Promise<void>),
onHideHandler: null as null | (() => void),
onUnloadHandler: null as null | (() => void),
enterExplainDetail: vi.fn(),
loadExplainDetailText: vi.fn(),
selectAudioForExplainDetail: vi.fn(),
@@ -30,7 +32,12 @@ vi.mock('@dcloudio/uni-app', () => ({
onLoad: (handler: (options?: Record<string, unknown>) => Promise<void>) => {
mocks.onLoadHandler = handler
},
onUnload: () => undefined
onHide: (handler: () => void) => {
mocks.onHideHandler = handler
},
onUnload: (handler: () => void) => {
mocks.onUnloadHandler = handler
}
}))
vi.mock('@/usecases/explainUseCase', () => ({
@@ -93,6 +100,8 @@ const exhibit = {
describe('讲解详情音频优先布局', () => {
beforeEach(() => {
mocks.onLoadHandler = null
mocks.onHideHandler = null
mocks.onUnloadHandler = null
audioState.currentAudio.value = null
audioState.currentSource.value = null
audioState.playing.value = false
@@ -301,6 +310,24 @@ describe('讲解详情音频优先布局', () => {
expect(uni.redirectTo).not.toHaveBeenCalled()
})
it('离开详情页时立即关闭当前讲解播放器', async () => {
audioState.currentAudio.value = { id: 'audio-1', audioUrl: exhibit.audioUrl }
audioState.currentSource.value = { targetType: 'STOP', targetId: 'stop-1', lang: 'en-US' }
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }
})
await mocks.onLoadHandler?.({ id: exhibit.id, lang: 'en-US', targetType: 'STOP', targetId: 'stop-1' })
await flushPromises()
mocks.onHideHandler?.()
mocks.onUnloadHandler?.()
wrapper.getComponent(GuidePageFrameStub).vm.$emit('back')
await flushPromises()
expect(mocks.close).toHaveBeenCalledTimes(1)
})
it('深链详情按展厅上下文回退至讲解对象列表', async () => {
const wrapper = mount(ExhibitDetail, {
global: { stubs: { GuidePageFrame: GuidePageFrameStub } }