import assert from 'node:assert/strict' import test from 'node:test' import { labelsVisibleFromSearch, searchWithLabels } from './labels-toggle.ts' import { renderAppPage } from './page.ts' import { clientScript } from './client-script.ts' test('labels show by default and hide only when ?labels=off (or similar)', () => { assert.equal(labelsVisibleFromSearch(''), true) assert.equal(labelsVisibleFromSearch('?mode=net'), true) assert.equal(labelsVisibleFromSearch('?labels=on'), true) assert.equal(labelsVisibleFromSearch('?labels=off'), false) assert.equal(labelsVisibleFromSearch('?labels=OFF&mode=net'), false) assert.equal(labelsVisibleFromSearch('?labels=false'), false) assert.equal(labelsVisibleFromSearch('?labels=0'), false) }) test('toggling writes or removes the labels param and keeps others', () => { assert.equal(searchWithLabels('', false), '?labels=off') assert.equal(searchWithLabels('?labels=off', true), '') assert.equal(searchWithLabels('?x=1&labels=off', true), '?x=1') assert.equal(searchWithLabels('?x=1', false), '?x=1&labels=off') }) test('page renders a Labels toggle that starts on, and the client honours it', () => { const html = renderAppPage({ appBasePath: '/packages/lineage', hostedUrl: 'https://example.kody.run/packages/lineage', repoLabel: 'o/r', }) assert.match(html, /]*data-labels-toggle[^>]*aria-pressed="true"[^>]*>Labels<\/button>/) assert.match(clientScript, /labelsVisibleFromSearch\(location\.search\)/) assert.match(clientScript, /if \(state\.labels\)/) })