okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221host tests: fileURLToPath replaces the regex that stripped the slash before a drive letter (replaces 439339ab1; the pathname form also left %20 in paths with spaces)44d885874

main
2.6 KiB50 linesraw
1import { fileURLToPath } from 'node:url';
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { build } from 'esbuild';
5import { createRequire } from 'node:module';
6
7const { outputFiles } = await build({ entryPoints: [fileURLToPath(new URL('../src/lib/router.ts',import.meta.url))], bundle: true, write: false, platform: 'node', format: 'cjs' });
8const browserWindow = { location: { hash: '#/chat/a' }, matchMedia: () => ({ matches: false }) };
9let transitions = 0;
10const documentStub = { documentElement: { dataset: {} }, startViewTransition: () => { transitions++; return { ready: Promise.resolve(), updateCallbackDone: Promise.resolve(), finished: Promise.resolve() }; } };
11const module = { exports: {} };
12new Function('require', 'module', 'exports', 'window', 'document', outputFiles[0].text)(createRequire(import.meta.url), module, module.exports, browserWindow, documentStub);
13const router = module.exports;
14
15test('Settings retains the page, chat id and existing query, and reopening is idempotent', () => {
16  const opened = router.settingsHref('#/chat/chat-a?preview=project-brief');
17  assert.equal(opened, '#/chat/chat-a?preview=project-brief&settings=1');
18  assert.equal(router.settingsHref(opened), opened);
19  assert.equal(router.settingsHref('#/tuning'), '#/tuning?settings=1');
20  const location = router.parseLocation(opened);
21  assert.equal(location.route, 'chat');
22  assert.equal(location.param, 'chat-a');
23  assert.equal(location.query.get('preview'), 'project-brief');
24});
25
26test('a Settings bookmark opens over chat; closing restores only the background URL', () => {
27  const bookmark = router.parseLocation('#/settings');
28  assert.equal(bookmark.route, 'chat');
29  assert.equal(bookmark.query.get('settings'), '1');
30  browserWindow.location.hash = '#/chat/chat-a?preview=project-brief&settings=1';
31  router.closeSettings();
32  assert.equal(browserWindow.location.hash, '#/chat/chat-a?preview=project-brief');
33  browserWindow.location.hash = '#/monitor';
34  router.navigate('settings');
35  assert.equal(browserWindow.location.hash, '#/monitor?settings=1');
36  router.closeSettings();
37  assert.equal(browserWindow.location.hash, '#/monitor');
38});
39
40
41test('Settings opens and closes immediately without snapshotting the background page', () => {
42  browserWindow.location.hash = '#/chat/a';
43  router.navigate('settings');
44  assert.equal(browserWindow.location.hash, '#/chat/a?settings=1');
45  router.closeSettings();
46  assert.equal(browserWindow.location.hash, '#/chat/a');
47  assert.equal(transitions, 0);
48  router.navigate('models');
49  assert.equal(transitions, 1, 'ordinary screen navigation still uses its view transition');
50});