soulsync/webui/src/platform/shell/route-manifest.test.ts
Antti Kettunen 9da8251e43
feat(webui): clarify import source metadata
- thread primary_source through album and track search payloads while keeping per-result source on the returned rows
- reuse the shared Notice primitive for fallback and error messaging in the import pages
- update the import route tests and shell route smoke coverage for the new behavior
2026-05-24 21:17:22 +03:00

75 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
getShellRouteByPageId,
legacyShellRoutes,
normalizeShellPath,
reactShellRoutes,
resolveLegacyShellPageFromPath,
resolveShellNavPage,
resolveShellPageFromPath,
shellRouteManifest,
} from './route-manifest';
describe('shellRouteManifest', () => {
it('resolves page ids from explicit paths', () => {
expect(resolveShellPageFromPath('/issues')).toBe('issues');
expect(resolveShellPageFromPath('/discover')).toBe('discover');
expect(resolveShellPageFromPath('/watchlist')).toBe('watchlist');
expect(resolveShellPageFromPath('/active-downloads')).toBe('active-downloads');
expect(resolveShellPageFromPath('/artist-detail')).toBeNull();
expect(resolveShellPageFromPath('/artist-detail/spotify/2YZyLoL8N0Wb9xBt1NhZWg')).toBe(
'artist-detail',
);
expect(resolveShellPageFromPath('/artists')).toBeNull();
});
it('treats the root path as unresolved so the shell can redirect to the profile home', () => {
expect(resolveShellPageFromPath('/')).toBeNull();
});
it('normalizes trailing slashes before resolving', () => {
expect(normalizeShellPath('/issues/')).toBe('/issues');
expect(resolveShellPageFromPath('/issues/')).toBe('issues');
});
it('resolves nested React route paths to their shell page', () => {
expect(resolveShellPageFromPath('/import/album')).toBe('import');
expect(resolveShellPageFromPath('/import/auto')).toBe('import');
expect(resolveShellPageFromPath('/import/singles')).toBe('import');
expect(resolveLegacyShellPageFromPath('/import/album')).toBeNull();
});
it('keeps a route entry for every manifest page id', () => {
expect(shellRouteManifest).not.toHaveLength(0);
expect(getShellRouteByPageId('dashboard')?.path).toBe('/dashboard');
expect(getShellRouteByPageId('hydrabase')?.path).toBe('/hydrabase');
expect(getShellRouteByPageId('watchlist')?.path).toBe('/watchlist');
expect(getShellRouteByPageId('tools')?.path).toBe('/tools');
expect(getShellRouteByPageId('artist-detail')?.path).toBe('/artist-detail');
});
it('tracks whether a route is rendered by React or the legacy shell', () => {
expect(getShellRouteByPageId('issues')?.kind).toBe('react');
expect(getShellRouteByPageId('stats')?.kind).toBe('react');
expect(getShellRouteByPageId('import')?.kind).toBe('react');
expect(getShellRouteByPageId('discover')?.kind).toBe('legacy');
expect(reactShellRoutes.map((route) => route.pageId)).toEqual(['import', 'stats', 'issues']);
expect(legacyShellRoutes.some((route) => route.pageId === 'dashboard')).toBe(true);
});
it('only resolves legacy page ids for legacy-owned paths', () => {
expect(resolveLegacyShellPageFromPath('/search')).toBe('search');
expect(resolveLegacyShellPageFromPath('/active-downloads')).toBe('active-downloads');
expect(resolveLegacyShellPageFromPath('/tools')).toBe('tools');
expect(resolveLegacyShellPageFromPath('/artist-detail')).toBeNull();
expect(resolveLegacyShellPageFromPath('/artist-detail/deezer/12345')).toBe('artist-detail');
expect(resolveLegacyShellPageFromPath('/issues')).toBeNull();
expect(resolveLegacyShellPageFromPath('/does-not-exist')).toBeNull();
});
it('maps contextual pages to the nav chrome they belong under', () => {
expect(resolveShellNavPage('artist-detail')).toBe('library');
expect(resolveShellNavPage('stats')).toBe('stats');
});
});