@@ -42,6 +42,7 @@ import {
|
|||||||
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
|
import { isEmbeddedInWechatMiniProgram } from '@/utils/hostEnvironment'
|
||||||
import { explainGuideStopListUrl } from '@/utils/explainNavigation'
|
import { explainGuideStopListUrl } from '@/utils/explainNavigation'
|
||||||
import { returnToWechatMiniProgram } from '@/services/WechatMiniProgramBridgeService'
|
import { returnToWechatMiniProgram } from '@/services/WechatMiniProgramBridgeService'
|
||||||
|
import { syncHostNavigationTitle } from '@/utils/hostNavigationTitle'
|
||||||
|
|
||||||
const explainHallItems = ref<ExplainHallSelectItem[]>([])
|
const explainHallItems = ref<ExplainHallSelectItem[]>([])
|
||||||
const explainLoading = ref(false)
|
const explainLoading = ref(false)
|
||||||
@@ -236,6 +237,7 @@ const loadExplainHalls = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
|
if (shouldUseHostNavigation.value) syncHostNavigationTitle('免费讲解')
|
||||||
pushExplainListHistory()
|
pushExplainListHistory()
|
||||||
void loadExplainHalls()
|
void loadExplainHalls()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1032,6 +1032,11 @@ const syncTopTabToUrl = (tabId: GuideTopTab) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const syncEmbeddedHostNavigationTitle = (tabId: GuideTopTab) => {
|
||||||
|
if (!isEmbeddedInWechatMiniProgram()) return
|
||||||
|
syncHostNavigationTitle(tabId === 'explain' ? '免费讲解' : '地图导览')
|
||||||
|
}
|
||||||
|
|
||||||
const isPoiSearchOverlayHistoryState = (state: unknown): state is PoiSearchOverlayHistoryState => (
|
const isPoiSearchOverlayHistoryState = (state: unknown): state is PoiSearchOverlayHistoryState => (
|
||||||
Boolean(
|
Boolean(
|
||||||
state
|
state
|
||||||
@@ -1133,6 +1138,7 @@ const handleTabChange = (tabId: GuideTopTab) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentTab.value = tabId
|
currentTab.value = tabId
|
||||||
|
syncEmbeddedHostNavigationTitle(tabId)
|
||||||
syncTopTabToUrl(tabId)
|
syncTopTabToUrl(tabId)
|
||||||
loadTopTabData(tabId)
|
loadTopTabData(tabId)
|
||||||
|
|
||||||
@@ -1160,11 +1166,13 @@ const syncTopTabFromHash = () => {
|
|||||||
closeArrivalPanel()
|
closeArrivalPanel()
|
||||||
}
|
}
|
||||||
syncTopTabToUrl(tab)
|
syncTopTabToUrl(tab)
|
||||||
|
syncEmbeddedHostNavigationTitle(tab)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
syncTopTabToUrl(currentTab.value)
|
syncTopTabToUrl(currentTab.value)
|
||||||
loadTopTabData(currentTab.value)
|
loadTopTabData(currentTab.value)
|
||||||
|
syncEmbeddedHostNavigationTitle(currentTab.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -1173,10 +1181,6 @@ onMounted(() => {
|
|||||||
|
|
||||||
if (typeof window === 'undefined') return
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
if (isEmbeddedInWechatMiniProgram()) {
|
|
||||||
syncHostNavigationTitle('地图导览')
|
|
||||||
}
|
|
||||||
|
|
||||||
stopOutdoorMapAvailabilitySubscription = subscribeOutdoorMapAvailability(handleOutdoorMapUnavailable)
|
stopOutdoorMapAvailabilitySubscription = subscribeOutdoorMapAvailability(handleOutdoorMapUnavailable)
|
||||||
void refreshOutdoorMapAvailability()
|
void refreshOutdoorMapAvailability()
|
||||||
syncTopTabFromHash()
|
syncTopTabFromHash()
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ const miniProgramBridgeMocks = vi.hoisted(() => ({
|
|||||||
returnToWechatMiniProgram: vi.fn()
|
returnToWechatMiniProgram: vi.fn()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const hostNavigationTitleMocks = vi.hoisted(() => ({
|
||||||
|
syncHostNavigationTitle: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
const testState = vi.hoisted(() => ({
|
const testState = vi.hoisted(() => ({
|
||||||
onLoadHandler: null as null | (() => void),
|
onLoadHandler: null as null | (() => void),
|
||||||
onBackPressHandler: null as null | (() => boolean)
|
onBackPressHandler: null as null | (() => boolean)
|
||||||
@@ -35,6 +39,10 @@ vi.mock('@/services/WechatMiniProgramBridgeService', () => ({
|
|||||||
returnToWechatMiniProgram: miniProgramBridgeMocks.returnToWechatMiniProgram
|
returnToWechatMiniProgram: miniProgramBridgeMocks.returnToWechatMiniProgram
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/utils/hostNavigationTitle', () => ({
|
||||||
|
syncHostNavigationTitle: hostNavigationTitleMocks.syncHostNavigationTitle
|
||||||
|
}))
|
||||||
|
|
||||||
vi.mock('@/usecases/explainUseCase', () => ({
|
vi.mock('@/usecases/explainUseCase', () => ({
|
||||||
explainUseCase: {
|
explainUseCase: {
|
||||||
loadExplainHalls: async () => [],
|
loadExplainHalls: async () => [],
|
||||||
@@ -69,6 +77,7 @@ const mountExplainList = () => mount(ExplainListPage, {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
hostEnvironmentMocks.embeddedInWechatMiniProgram = false
|
hostEnvironmentMocks.embeddedInWechatMiniProgram = false
|
||||||
miniProgramBridgeMocks.returnToWechatMiniProgram.mockResolvedValue({ status: 'not-embedded' })
|
miniProgramBridgeMocks.returnToWechatMiniProgram.mockResolvedValue({ status: 'not-embedded' })
|
||||||
|
hostNavigationTitleMocks.syncHostNavigationTitle.mockReset()
|
||||||
testState.onLoadHandler = null
|
testState.onLoadHandler = null
|
||||||
testState.onBackPressHandler = null
|
testState.onBackPressHandler = null
|
||||||
window.location.hash = '#/pages/explain/list'
|
window.location.hash = '#/pages/explain/list'
|
||||||
@@ -123,7 +132,11 @@ describe('讲解展厅列表返回', () => {
|
|||||||
window.history.replaceState({}, '', window.location.href)
|
window.history.replaceState({}, '', window.location.href)
|
||||||
const wrapper = mountExplainList()
|
const wrapper = mountExplainList()
|
||||||
|
|
||||||
|
testState.onLoadHandler?.()
|
||||||
|
await flushPromises()
|
||||||
|
|
||||||
expect(wrapper.getComponent(ExplainHallSelectStub).props('forceInternalHeader')).toBe(false)
|
expect(wrapper.getComponent(ExplainHallSelectStub).props('forceInternalHeader')).toBe(false)
|
||||||
|
expect(hostNavigationTitleMocks.syncHostNavigationTitle).toHaveBeenCalledWith('免费讲解')
|
||||||
await wrapper.get('[data-testid="explain-list-back"]').trigger('click')
|
await wrapper.get('[data-testid="explain-list-back"]').trigger('click')
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ const testState = vi.hoisted(() => ({
|
|||||||
onShowHandler: null as null | (() => Promise<void> | void)
|
onShowHandler: null as null | (() => Promise<void> | void)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
const hostEnvironmentMocks = vi.hoisted(() => ({
|
||||||
|
embeddedInWechatMiniProgram: false
|
||||||
|
}))
|
||||||
|
|
||||||
|
const hostNavigationTitleMocks = vi.hoisted(() => ({
|
||||||
|
syncHostNavigationTitle: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
vi.mock('@dcloudio/uni-app', () => ({
|
vi.mock('@dcloudio/uni-app', () => ({
|
||||||
onLoad: vi.fn(),
|
onLoad: vi.fn(),
|
||||||
onShow: (handler: () => Promise<void> | void) => {
|
onShow: (handler: () => Promise<void> | void) => {
|
||||||
@@ -19,7 +27,11 @@ vi.mock('@dcloudio/uni-app', () => ({
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
vi.mock('@/utils/hostEnvironment', () => ({
|
vi.mock('@/utils/hostEnvironment', () => ({
|
||||||
isEmbeddedInWechatMiniProgram: () => false
|
isEmbeddedInWechatMiniProgram: () => hostEnvironmentMocks.embeddedInWechatMiniProgram
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/utils/hostNavigationTitle', () => ({
|
||||||
|
syncHostNavigationTitle: hostNavigationTitleMocks.syncHostNavigationTitle
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const modelSource = {
|
const modelSource = {
|
||||||
@@ -107,7 +119,9 @@ beforeEach(() => {
|
|||||||
testState.threeMapMountCount = 0
|
testState.threeMapMountCount = 0
|
||||||
testState.threeMapUnmountCount = 0
|
testState.threeMapUnmountCount = 0
|
||||||
testState.onShowHandler = null
|
testState.onShowHandler = null
|
||||||
window.history.replaceState({}, '', '/#/pages/index/index?tab=guide')
|
hostEnvironmentMocks.embeddedInWechatMiniProgram = false
|
||||||
|
hostNavigationTitleMocks.syncHostNavigationTitle.mockReset()
|
||||||
|
window.location.hash = '#/pages/index/index?tab=guide'
|
||||||
vi.stubGlobal('uni', {
|
vi.stubGlobal('uni', {
|
||||||
navigateTo: vi.fn(),
|
navigateTo: vi.fn(),
|
||||||
navigateBack: vi.fn(),
|
navigateBack: vi.fn(),
|
||||||
@@ -124,6 +138,16 @@ afterEach(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('首页启动遮罩与馆内模型生命周期', () => {
|
describe('首页启动遮罩与馆内模型生命周期', () => {
|
||||||
|
it('嵌入小程序打开讲解首页时同步免费讲解标题', async () => {
|
||||||
|
hostEnvironmentMocks.embeddedInWechatMiniProgram = true
|
||||||
|
window.location.hash = '#/pages/index/index?tab=explain&embedded=wechat-mini-program'
|
||||||
|
|
||||||
|
const wrapper = await mountIndex()
|
||||||
|
|
||||||
|
expect(hostNavigationTitleMocks.syncHostNavigationTitle).toHaveBeenCalledWith('免费讲解')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
it('12 秒超时后仍保持 indoor,且不会挂载 TencentMap', async () => {
|
it('12 秒超时后仍保持 indoor,且不会挂载 TencentMap', async () => {
|
||||||
const wrapper = await mountIndex()
|
const wrapper = await mountIndex()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user