68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
import { defineComponent } from 'vue'
|
|
|
|
const testState = vi.hoisted(() => ({
|
|
restoreCount: 0,
|
|
onShowHandler: null as null | (() => Promise<void> | void)
|
|
}))
|
|
|
|
vi.mock('@dcloudio/uni-app', () => ({
|
|
onLoad: vi.fn(),
|
|
onShow: (handler: () => Promise<void> | void) => {
|
|
testState.onShowHandler = handler
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/utils/hostEnvironment', () => ({
|
|
isEmbeddedInWechatMiniProgram: () => false
|
|
}))
|
|
|
|
import SearchPage from '@/pages/search/index.vue'
|
|
|
|
const PoiSearchPanelStub = defineComponent({
|
|
name: 'PoiSearchPanel',
|
|
methods: {
|
|
restoreResultListScroll() {
|
|
testState.restoreCount += 1
|
|
}
|
|
},
|
|
template: '<div data-testid="poi-search-panel"></div>'
|
|
})
|
|
|
|
beforeEach(() => {
|
|
testState.restoreCount = 0
|
|
testState.onShowHandler = null
|
|
vi.stubGlobal('uni', {
|
|
reLaunch: vi.fn()
|
|
})
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
})
|
|
|
|
describe('独立搜索页取消闭环', () => {
|
|
it('主动返回地图时直接回到馆内首页', async () => {
|
|
const wrapper = mount(SearchPage, {
|
|
global: {
|
|
stubs: {
|
|
PoiSearchPanel: PoiSearchPanelStub
|
|
}
|
|
}
|
|
})
|
|
|
|
await testState.onShowHandler?.()
|
|
await flushPromises()
|
|
expect(testState.restoreCount).toBe(1)
|
|
|
|
await wrapper.get('.map-link').trigger('tap')
|
|
|
|
expect(uni.reLaunch).toHaveBeenCalledWith({
|
|
url: '/pages/index/index?tab=guide'
|
|
})
|
|
})
|
|
})
|