This commit is contained in:
@@ -4,14 +4,18 @@ 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'
|
||||
import { openExternalNavigation } from '@/services/MapNavigationService'
|
||||
import { openWechatMiniProgramLocation } from '@/services/WechatMiniProgramBridgeService'
|
||||
|
||||
const selectedTarget = ARRIVAL_TARGETS[0]
|
||||
vi.mock('@/services/MapNavigationService', () => ({ openExternalNavigation: vi.fn() }))
|
||||
vi.mock('@/services/WechatMiniProgramBridgeService', () => ({ openWechatMiniProgramLocation: vi.fn() }))
|
||||
|
||||
const selectedTarget = ARRIVAL_TARGETS[1]
|
||||
const defaultUserAgent = window.navigator.userAgent
|
||||
|
||||
const mountArrivalPanel = () => mount(ArrivalPanel, {
|
||||
props: {
|
||||
visible: true,
|
||||
activeType: 'bus',
|
||||
activeType: selectedTarget.type,
|
||||
targets: [selectedTarget],
|
||||
selectedTargetId: selectedTarget.id,
|
||||
selectedTarget
|
||||
@@ -19,72 +23,62 @@ const mountArrivalPanel = () => mount(ArrivalPanel, {
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.mocked(openExternalNavigation).mockResolvedValue(true)
|
||||
vi.mocked(openWechatMiniProgramLocation).mockResolvedValue({ status: 'not-embedded' })
|
||||
vi.stubGlobal('uni', { showToast: vi.fn(), showActionSheet: vi.fn() })
|
||||
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(),
|
||||
showActionSheet: vi.fn()
|
||||
})
|
||||
delete (window as Window & { __wxjs_environment?: string }).__wxjs_environment
|
||||
Object.defineProperty(window.navigator, 'userAgent', { configurable: true, value: 'Mozilla/5.0 (Linux; Android 14)' })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(window.navigator, 'userAgent', {
|
||||
configurable: true,
|
||||
value: defaultUserAgent
|
||||
})
|
||||
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.clearAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('来馆面板 H5 实际渲染', () => {
|
||||
it('主按钮显示第三方导航,点击后弹出百度和高德选择框', async () => {
|
||||
describe('来馆面板 H5 导航分流', () => {
|
||||
it('嵌入小程序 web-view 时只向宿主页面导航,且完整传递当前选中目标', async () => {
|
||||
Object.assign(window, { __wxjs_environment: 'miniprogram' })
|
||||
Object.defineProperty(window.navigator, 'userAgent', { configurable: true, value: 'Mozilla/5.0 MicroMessenger/8.0.50' })
|
||||
vi.mocked(openWechatMiniProgramLocation).mockResolvedValue({ status: 'opened' })
|
||||
const wrapper = mountArrivalPanel()
|
||||
const showActionSheet = (uni as unknown as {
|
||||
showActionSheet: ReturnType<typeof vi.fn>
|
||||
}).showActionSheet
|
||||
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('打开地图导航')
|
||||
expect(wrapper.get('.arrival-primary-text').text()).toBe('打开地图导航')
|
||||
await wrapper.get('.arrival-primary').trigger('tap')
|
||||
|
||||
expect(showActionSheet).toHaveBeenCalledWith(expect.objectContaining({
|
||||
itemList: ['百度地图', '高德地图']
|
||||
}))
|
||||
expect(wrapper.find('.provider-sheet').exists()).toBe(false)
|
||||
expect(navigateTo).not.toHaveBeenCalled()
|
||||
expect(openWechatMiniProgramLocation).toHaveBeenCalledTimes(1)
|
||||
expect(openWechatMiniProgramLocation).toHaveBeenCalledWith({
|
||||
latitude: selectedTarget.latitude,
|
||||
longitude: selectedTarget.longitude,
|
||||
name: selectedTarget.title,
|
||||
address: selectedTarget.subtitle
|
||||
})
|
||||
expect(openExternalNavigation).not.toHaveBeenCalled()
|
||||
expect((uni as unknown as { showActionSheet: ReturnType<typeof vi.fn> }).showActionSheet).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('诊断信息默认隐藏,仅在 debug-build=1 时显示 H5 构建边界', () => {
|
||||
it('普通 H5 仅回退至第三方地图,并使用当前选中目标', async () => {
|
||||
const wrapper = mountArrivalPanel()
|
||||
expect(wrapper.get('.arrival-primary-text').text()).toBe('第三方导航')
|
||||
await wrapper.get('.arrival-primary').trigger('tap')
|
||||
|
||||
expect(openExternalNavigation).toHaveBeenCalledWith({
|
||||
latitude: selectedTarget.latitude,
|
||||
longitude: selectedTarget.longitude,
|
||||
name: selectedTarget.title,
|
||||
address: selectedTarget.subtitle
|
||||
})
|
||||
})
|
||||
|
||||
it('诊断信息默认隐藏,仅在 debug-build=1 时显示构建边界', () => {
|
||||
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:')
|
||||
expect(debugWrapper.get('[data-testid="arrival-build-diagnostics"]').text()).toContain('构建平台:h5')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user