This commit is contained in:
87
tests/unit/ArrivalPanel.spec.ts
Normal file
87
tests/unit/ArrivalPanel.spec.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import ArrivalPanel from '@/components/navigation/ArrivalPanel.vue'
|
||||
import { ARRIVAL_TARGETS } from '@/data/arrivalSearchTargets'
|
||||
|
||||
const selectedTarget = ARRIVAL_TARGETS[0]
|
||||
const defaultUserAgent = window.navigator.userAgent
|
||||
|
||||
const mountArrivalPanel = () => mount(ArrivalPanel, {
|
||||
props: {
|
||||
visible: true,
|
||||
activeType: 'bus',
|
||||
targets: [selectedTarget],
|
||||
selectedTargetId: selectedTarget.id,
|
||||
selectedTarget
|
||||
}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
window.history.replaceState({}, '', '/#/pages/index/index?tab=guide')
|
||||
Object.defineProperty(window.navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: 'Mozilla/5.0 MicroMessenger/8.0.50 miniProgram'
|
||||
})
|
||||
Object.assign(window, {
|
||||
__wxjs_environment: 'miniprogram',
|
||||
wx: {
|
||||
miniProgram: {
|
||||
navigateTo: vi.fn()
|
||||
}
|
||||
}
|
||||
})
|
||||
vi.stubGlobal('uni', {
|
||||
showToast: vi.fn()
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(window.navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: defaultUserAgent
|
||||
})
|
||||
delete (window as Window & { __wxjs_environment?: string }).__wxjs_environment
|
||||
delete (window as Window & { wx?: unknown }).wx
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('来馆面板 H5 实际渲染', () => {
|
||||
it('主按钮显示第三方导航,点击后展示三家地图选择层', async () => {
|
||||
const wrapper = mountArrivalPanel()
|
||||
const navigateTo = (
|
||||
window as Window & {
|
||||
wx?: { miniProgram?: { navigateTo?: ReturnType<typeof vi.fn> } }
|
||||
}
|
||||
).wx?.miniProgram?.navigateTo
|
||||
|
||||
expect(wrapper.get('.arrival-primary-text').text()).toBe('第三方导航')
|
||||
expect(wrapper.text()).not.toContain('打开地图导航')
|
||||
await wrapper.get('.arrival-primary').trigger('tap')
|
||||
|
||||
expect(wrapper.find('.provider-sheet').exists()).toBe(true)
|
||||
expect(wrapper.findAll('.provider-row')).toHaveLength(3)
|
||||
expect(wrapper.text()).toContain('高德地图')
|
||||
expect(wrapper.text()).toContain('百度地图')
|
||||
expect(wrapper.text()).toContain('腾讯地图')
|
||||
expect(navigateTo).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('诊断信息默认隐藏,仅在 debug-build=1 时显示 H5 构建边界', () => {
|
||||
const normalWrapper = mountArrivalPanel()
|
||||
expect(normalWrapper.find('[data-testid="arrival-build-diagnostics"]').exists()).toBe(false)
|
||||
normalWrapper.unmount()
|
||||
|
||||
window.location.hash = '#/pages/index/index?tab=guide&debug-build=1'
|
||||
const debugWrapper = mountArrivalPanel()
|
||||
const diagnostics = debugWrapper.get('[data-testid="arrival-build-diagnostics"]')
|
||||
|
||||
expect(diagnostics.text()).toContain('构建 ID:test-build')
|
||||
expect(diagnostics.text()).toContain('Git commit:test-commit')
|
||||
expect(diagnostics.text()).toContain('构建平台:h5')
|
||||
expect(diagnostics.text()).toContain('navigationMode:third-party-providers')
|
||||
expect(diagnostics.text()).toContain('location.href:')
|
||||
expect(diagnostics.text()).toContain('UA:')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user