@@ -112,7 +112,7 @@ describe('讲解展厅列表返回', () => {
|
||||
window.history.replaceState({}, '', window.location.href)
|
||||
const wrapper = mountExplainList()
|
||||
|
||||
expect(wrapper.getComponent(ExplainHallSelectStub).props('forceInternalHeader')).toBe(true)
|
||||
expect(wrapper.getComponent(ExplainHallSelectStub).props('forceInternalHeader')).toBe(false)
|
||||
await wrapper.get('[data-testid="explain-list-back"]').trigger('click')
|
||||
|
||||
expect(uni.navigateBack).not.toHaveBeenCalled()
|
||||
|
||||
61
tests/unit/hostNavigationTitle.spec.ts
Normal file
61
tests/unit/hostNavigationTitle.spec.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
MINI_PROGRAM_NAVIGATION_TITLE_MESSAGE,
|
||||
syncHostNavigationTitle
|
||||
} from '@/utils/hostNavigationTitle'
|
||||
|
||||
const hostEnvironmentMocks = vi.hoisted(() => ({
|
||||
embeddedInWechatMiniProgram: false
|
||||
}))
|
||||
|
||||
vi.mock('@/utils/hostEnvironment', () => ({
|
||||
isEmbeddedInWechatMiniProgram: () => hostEnvironmentMocks.embeddedInWechatMiniProgram
|
||||
}))
|
||||
|
||||
afterEach(() => {
|
||||
hostEnvironmentMocks.embeddedInWechatMiniProgram = false
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('小程序宿主标题同步', () => {
|
||||
it('嵌入态同步免费讲解标题并通知小程序宿主', () => {
|
||||
const postMessage = vi.fn()
|
||||
const setNavigationBarTitle = vi.fn()
|
||||
hostEnvironmentMocks.embeddedInWechatMiniProgram = true
|
||||
vi.stubGlobal('uni', { setNavigationBarTitle })
|
||||
vi.stubGlobal('window', {
|
||||
...window,
|
||||
wx: {
|
||||
miniProgram: { postMessage }
|
||||
}
|
||||
})
|
||||
|
||||
syncHostNavigationTitle('免费讲解')
|
||||
|
||||
expect(document.title).toBe('免费讲解')
|
||||
expect(setNavigationBarTitle).toHaveBeenCalledWith({ title: '免费讲解' })
|
||||
expect(postMessage).toHaveBeenCalledWith({
|
||||
data: {
|
||||
type: MINI_PROGRAM_NAVIGATION_TITLE_MESSAGE,
|
||||
title: '免费讲解'
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('非嵌入态不向小程序桥接发送标题', () => {
|
||||
const postMessage = vi.fn()
|
||||
vi.stubGlobal('window', {
|
||||
...window,
|
||||
wx: {
|
||||
miniProgram: { postMessage }
|
||||
}
|
||||
})
|
||||
|
||||
syncHostNavigationTitle('免费讲解')
|
||||
|
||||
expect(document.title).toBe('免费讲解')
|
||||
expect(postMessage).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user