import assert from 'node:assert/strict'; import { describe, it } from 'node:test'; import { grouped, localPages } from '../src/web/public/core/palette.js'; /** * Command palette, the parts that hold no DOM (M19). * * Both are small and both are the kind of thing that degrades quietly: a * heading above every line, or a page offered to someone who cannot open it. */ const result = (kind, title) => ({ kind, title }); describe('grouping the results', () => { /** The forge returns issues and pull requests interleaved. */ it('gathers each kind, however they arrive', () => { const order = grouped([ result('issue', 'i1'), result('pull', 'p1'), result('issue', 'i2'), result('pull', 'p2'), ]).map((entry) => entry.kind); assert.deepEqual(order, ['issue', 'issue', 'pull', 'pull']); }); it('keeps the order the server chose inside a group', () => { const titles = grouped([ result('card', 'première'), result('page', 'une page'), result('card', 'seconde'), ]) .filter((entry) => entry.kind === 'card') .map((entry) => entry.title); assert.deepEqual(titles, ['première', 'seconde']); }); it('puts the pages first and the members last', () => { const order = grouped([ result('member', 'quelqu’un'), result('repository', 'FWS/x'), result('page', 'Dépôts'), ]).map((entry) => entry.kind); assert.deepEqual(order, ['page', 'repository', 'member']); }); it('sends an unknown kind to the end rather than dropping it', () => { const order = grouped([result('inconnu', '?'), result('page', 'Dépôts')]).map((entry) => entry.kind); assert.deepEqual(order, ['page', 'inconnu']); }); it('survives an empty answer', () => { assert.deepEqual(grouped([]), []); }); }); describe('matching the pages locally', () => { const pages = [ { path: '', label: 'Vue d’ensemble', group: 'Pilotage' }, { path: 'tasks', label: 'Mes tâches', group: 'Pilotage' }, { path: 'repos', label: 'Dépôts', group: 'Code' }, { path: 'settings', label: 'Paramètres', group: 'Système' }, ]; it('lists everything when nothing is typed', () => { assert.equal(localPages(pages, '').length, pages.length); }); it('matches on the label', () => { assert.deepEqual( localPages(pages, 'tâche').map((entry) => entry.title), ['Mes tâches'], ); }); /** Typing the section is how people who know the panel navigate it. */ it('matches on the group', () => { assert.deepEqual( localPages(pages, 'pilotage').map((entry) => entry.title), ['Vue d’ensemble', 'Mes tâches'], ); }); it('points at the hash route of each page', () => { const [overview] = localPages(pages, 'ensemble'); assert.equal(overview.href, '#/'); assert.equal(localPages(pages, 'dépôt')[0].href, '#/repos'); }); /** * The caller passes only the pages the visitor can see, so a page missing * from that list must never surface — the palette does no filtering of its own. */ it('offers nothing beyond the list it was given', () => { const visible = pages.filter((page) => page.path !== 'settings'); assert.deepEqual(localPages(visible, 'paramètres'), []); }); });