Files
FWS-DiscordBot/tests/web-palette.test.js
nocodeandClaude Opus 5 9acb523510 feat(web): search the whole panel from one place
Finding anything meant knowing which tab it lived in — fine once you
have learned the panel, hopeless before. ⌘K now covers cards,
repositories, issues, wiki pages and members at once.

Pages are matched in the browser, so the palette answers before it has
asked the server and stays useful while the forge is down. Each remote
source is queried independently and a source that fails is simply absent
from the results, rather than taking the others with it. Issues come
from one organization-wide request: per repository, the palette could
not afford them on every keystroke.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-24 18:46:04 +02:00

101 lines
3.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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'), []);
});
});