Files
frontend-miniapp/tests/unit/OutdoorArrivalRoutePanel.spec.ts
lyf 540bb8627f
Some checks failed
CI / verify (push) Has been cancelled
同步移动端源码并修复小程序嵌入标题
2026-07-28 18:37:40 +08:00

119 lines
3.8 KiB
TypeScript

// @vitest-environment happy-dom
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import OutdoorArrivalRoutePanel from '@/components/navigation/OutdoorArrivalRoutePanel.vue'
const destination = {
title: '深圳自然博物馆[公交站]',
address: 'M574路',
latitude: 22.69258,
longitude: 114.36372
}
const start = {
name: '我的位置',
latitude: 22.688,
longitude: 114.359
}
const mountPanel = (overrides: Record<string, unknown> = {}) => mount(OutdoorArrivalRoutePanel, {
props: {
visible: true,
phase: 'permission-needed',
destination,
startPoint: null,
loading: false,
routeError: '',
routeDistance: 0,
routeDuration: 0,
manualSearchResults: [],
manualSearchLoading: false,
...overrides
}
})
describe('来馆路线起点确认', () => {
it('定位不可用时提示重新检测或手动选择,而不显示旧馆外导览界面', async () => {
const wrapper = mountPanel({
locationMessage: '请在微信小程序的设置中开启位置权限后重试'
})
expect(wrapper.text()).toContain('暂未获取实时位置')
expect(wrapper.text()).toContain('重新检测')
expect(wrapper.text()).toContain('手动选择起点')
expect(wrapper.text()).not.toContain('馆外导览')
await wrapper.get('.outdoor-route-action.secondary').trigger('tap')
await wrapper.get('.outdoor-route-action.primary').trigger('tap')
expect(wrapper.emitted('retryLocation')).toHaveLength(1)
expect(wrapper.emitted('manualStartRequest')).toHaveLength(1)
})
it('浏览器已拒绝位置权限时,重新检测区域会给出明确的设置指引', () => {
const wrapper = mountPanel({
locationHelpVisible: true,
locationMessage: '当前位置权限已关闭'
})
expect(wrapper.text()).toContain('请开启位置权限')
expect(wrapper.text()).toContain('微信小程序的设置')
expect(wrapper.text()).toContain('重新检测')
})
it('手动选择的起点保留确认操作,避免误用地图点位', async () => {
const wrapper = mountPanel({
phase: 'confirm-start',
startPoint: { ...start, name: '深圳北站' }
})
expect(wrapper.text()).toContain('深圳北站')
expect(wrapper.text()).toContain('从这里出发')
await wrapper.get('.outdoor-route-action.primary').trigger('tap')
await wrapper.get('.outdoor-route-text-action').trigger('tap')
expect(wrapper.emitted('confirmStart')).toHaveLength(1)
expect(wrapper.emitted('manualStartRequest')).toHaveLength(1)
})
it('手动起点支持输入地点与地图选点两条路径', async () => {
const wrapper = mountPanel({ phase: 'manual-search' })
await wrapper.get('.outdoor-route-switch + .outdoor-route-switch').trigger('tap')
expect(wrapper.emitted('manualMapRequest')).toHaveLength(1)
await wrapper.setProps({
manualSearchResults: [{
id: 'ping-shan-station',
title: '深圳坪山站',
address: '深圳市坪山区',
category: '火车站',
latitude: 22.699,
longitude: 114.347
}]
})
await wrapper.get('.outdoor-route-search-result').trigger('tap')
expect(wrapper.emitted('manualStartConfirm')).toEqual([[expect.objectContaining({
id: 'ping-shan-station',
title: '深圳坪山站'
})]])
})
it('路线已生成时仅展示路线结果,不重复显示出行方式选择', () => {
const wrapper = mountPanel({
phase: 'route',
startPoint: start,
routeDistance: 1850,
routeDuration: 14
})
expect(wrapper.text()).toContain('1.9 公里')
expect(wrapper.text()).toContain('约 14 分钟')
expect(wrapper.text()).toContain('路线已显示在地图上')
expect(wrapper.find('.outdoor-route-mode-list').exists()).toBe(false)
})
})