mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-23 03:53:34 +08:00
Add interactive hook examples, shared Pinia runtime state, and configurable layouts. Generate typed namespaced icons during development, HMR, and builds. Refine the UI and establish project comment and design conventions. Validation: typecheck, ESLint, 181 tests, and production build passed.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { useAppNavigation } from '../../src/hooks/template/useAppNavigation'
|
|
|
|
const { push, replace, menus } = vi.hoisted(() => ({
|
|
push: vi.fn().mockResolvedValue(void 0),
|
|
replace: vi.fn().mockResolvedValue(void 0),
|
|
menus: [{ fullPath: '/parent', children: [{ fullPath: '/target' }] }],
|
|
}))
|
|
|
|
vi.mock('../../src/hooks', () => ({
|
|
useVueRouter: () => ({
|
|
router: { push, replace, getRoutes: () => [{ path: '/target' }] },
|
|
}),
|
|
}))
|
|
vi.mock('../../src/store', () => ({
|
|
useMenuGetters: () => ({ getMenuOptions: { value: menus } }),
|
|
}))
|
|
|
|
describe('useAppNavigation', () => {
|
|
beforeEach(() => vi.clearAllMocks())
|
|
|
|
it('returns the navigation promise and supports paths, menu objects and indices', async () => {
|
|
const { navigationTo } = useAppNavigation()
|
|
|
|
expect(navigationTo('/target')).toBeInstanceOf(Promise)
|
|
await navigationTo(0)
|
|
expect(push).toHaveBeenLastCalledWith({ path: '/target', query: void 0 })
|
|
await navigationTo('/target', { isPush: false, query: { from: 'demo' } })
|
|
expect(replace).toHaveBeenCalledWith({
|
|
path: '/target',
|
|
query: { from: 'demo' },
|
|
})
|
|
})
|
|
|
|
it.each([-1, NaN, Infinity, 0.5, 1])('ignores invalid index %s', (index) => {
|
|
const warning = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
|
|
expect(() => useAppNavigation().navigationTo(index)).not.toThrow()
|
|
expect(push).not.toHaveBeenCalled()
|
|
expect(warning).toHaveBeenCalled()
|
|
warning.mockRestore()
|
|
})
|
|
})
|