import { describe, expect, it } from 'vitest' import { currentItemIdFromLocation, currentPagePath, normalizeNavPath, pageIdFromPath, pluginNavItemToPageSelectorItem, } from '../../components/AppTopBar.navigation' describe('AppTopBar navigation helpers', () => { it('normalizes blank, relative, and trailing-slash paths', () => { expect(normalizeNavPath()).toBe('/') expect(normalizeNavPath('results')).toBe('/results') expect(normalizeNavPath('/results/')).toBe('/results') expect(normalizeNavPath(' /analysis/run/ ')).toBe('/analysis/run') }) it('derives stable page ids from paths', () => { expect(pageIdFromPath('/', 'fallback')).toBe('dashboard') expect(pageIdFromPath('/analysis/run', 'fallback')).toBe('analysis-run') expect(pageIdFromPath('', 'fallback')).toBe('dashboard') }) it('maps plugin nav items to page selector items with plugin fallbacks', () => { expect( pluginNavItemToPageSelectorItem( { label: 'Results', path: 'results' }, 1, { pluginIcon: 'flask' }, ), ).toEqual({ id: 'results', label: 'Results', to: '/results', icon: 'flask', }) }) it('prefers explicit nav item id and icon without exposing descriptions as hints', () => { expect( pluginNavItemToPageSelectorItem( { id: 'custom', label: 'Custom', path: '/custom', icon: 'sparkles', description: 'Custom page', }, 0, { pluginIcon: 'flask' }, ), ).toMatchObject({ id: 'custom', icon: 'sparkles', }) }) it('matches current route-relative page ids for integrated plugins', () => { const pages = [ { id: 'overview', to: '/' }, { id: 'results', to: '/results' }, ] expect(currentPagePath('/plugins/assay', '/plugins/assay')).toBe('/') expect(currentPagePath('/plugins/assay/results', '/plugins/assay')).toBe('/results') expect(currentItemIdFromLocation(pages, '/plugins/assay/results', '/plugins/assay')).toBe('results') }) })