import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import test from 'node:test'; import { en } from '../ui/locales/en.js'; import { normalizeServer, needsConfirmation } from '../ui/server.js'; const html = readFileSync(new URL('../ui/index.html', import.meta.url), 'utf8'); test('workspace selection is hidden before native configuration is available', () => { assert.match(html, /
/); assert.match(html, /id="startup-loading" role="status"/); }); test('every launcher text resolves to a nonempty English translation', () => { for (const [, key] of html.matchAll(/data-i18n="([^"]+)"/g)) { assert.equal(typeof en[key], 'string', key); assert.ok(en[key].trim(), key); } }); test('installation addresses support custom domains, ports and base paths', () => { assert.equal( normalizeServer(' HTTPS://Example.com:443/kanban '), 'https://example.com/kanban/', ); assert.equal(normalizeServer('https://[::1]:8443/'), 'https://[::1]:8443/'); for (const input of [ 'http://example.com', 'https:example.com', 'https://user:secret@example.com', 'https://user@example.com', 'https://example.com/?token=secret', 'https://example.com/#secret', 'https://exa\nmple.com', 'https://example.com\\other', 'file:///tmp/test', 'javascript:alert(1)', '', ]) { assert.throws(() => normalizeServer(input), undefined, input); } }); test('changing the installation requires confirmation, retrying does not', () => { assert.equal(needsConfirmation(null, 'https://example.com/'), false); assert.equal( needsConfirmation('https://example.com/', 'https://example.com/'), false, ); assert.equal( needsConfirmation('https://example.com/', 'https://example.com:8443/'), true, ); assert.equal( needsConfirmation('https://example.com/a/', 'https://example.com/b/'), true, ); });