50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
DEFAULT_APP_SCHEMES,
|
|
DEFAULT_RETURN_ROUTE,
|
|
formatDeepLinkRoute,
|
|
getAppDeepLinkUrls,
|
|
openMobileApp,
|
|
} from '../../../src/utils/navigation';
|
|
|
|
describe('navigation utils', () => {
|
|
const originalLocation = window.location;
|
|
|
|
beforeEach(() => {
|
|
vi.useFakeTimers();
|
|
Object.defineProperty(window, 'location', {
|
|
configurable: true,
|
|
value: { href: 'http://localhost:3000/store/' },
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
Object.defineProperty(window, 'location', {
|
|
configurable: true,
|
|
value: originalLocation,
|
|
});
|
|
});
|
|
|
|
it('formats deep link routes cleanly', () => {
|
|
expect(formatDeepLinkRoute()).toBe(DEFAULT_RETURN_ROUTE);
|
|
expect(formatDeepLinkRoute('///')).toBe(DEFAULT_RETURN_ROUTE);
|
|
expect(formatDeepLinkRoute('/subscriptions/')).toBe('subscriptions/');
|
|
});
|
|
|
|
it('generates deep link URLs for default and custom schemes', () => {
|
|
expect(getAppDeepLinkUrls()).toEqual(DEFAULT_APP_SCHEMES.map((s) => `${s}://${DEFAULT_RETURN_ROUTE}`));
|
|
expect(getAppDeepLinkUrls({ route: '/profile', schemes: ['customapp'] })).toEqual([
|
|
'customapp://profile',
|
|
]);
|
|
});
|
|
|
|
it('opens mobile app primary URL and schedules fallback URLs', () => {
|
|
openMobileApp({ route: '/modules', schemes: ['acupedia', 'myapp'], delayBetweenFallbacks: 300 });
|
|
expect(window.location.href).toBe('acupedia://modules');
|
|
|
|
vi.advanceTimersByTime(300);
|
|
expect(window.location.href).toBe('myapp://modules');
|
|
});
|
|
});
|