import test from 'node:test' import assert from 'node:assert/strict' import { navigateBackOr, navigateToUnique } from '../utils/navigation.js' test('navigateBackOr returns through the stack and falls back when the stack is empty', () => { const calls = [] globalThis.uni = { navigateBack: (options) => calls.push(['back', options]), reLaunch: (options) => calls.push(['reLaunch', options]) } globalThis.getCurrentPages = () => [{ route: 'pages/home/home' }, { route: 'pages/profile/profile' }] navigateBackOr('/pages/home/home') assert.equal(calls[0][0], 'back') calls.length = 0 globalThis.getCurrentPages = () => [{ route: 'pages/profile/profile' }] navigateBackOr('/pages/home/home') assert.deepEqual(calls, [['reLaunch', { url: '/pages/home/home' }]]) calls.length = 0 globalThis.getCurrentPages = () => [{ route: 'pages/home/home' }, { route: 'pages/profile/profile' }] globalThis.uni.navigateBack = ({ fail }) => fail() navigateBackOr('/pages/home/home') assert.deepEqual(calls, [['reLaunch', { url: '/pages/home/home' }]]) }) test('navigateToUnique does not stack the current utility page twice', () => { const calls = [] globalThis.uni = { navigateTo: (options) => calls.push(options) } globalThis.getCurrentPages = () => [{ route: 'pages/profile/profile' }] navigateToUnique('/pages/profile/profile') assert.deepEqual(calls, []) navigateToUnique('/pages/history/history') assert.deepEqual(calls, [{ url: '/pages/history/history' }]) })