okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
44d885874
main
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' , () => { 16const opened = router . settingsHref ( '#/chat/chat-a?preview=project-brief' ); 17assert . equal ( opened , '#/chat/chat-a?preview=project-brief&settings=1' ); 18assert . equal ( router . settingsHref ( opened ), opened ); 19assert . equal ( router . settingsHref ( '#/tuning' ), '#/tuning?settings=1' ); 20const location = router . parseLocation ( opened ); 21assert . equal ( location . route , 'chat' ); 22assert . equal ( location . param , 'chat-a' ); 23assert . equal ( location . query . get ( 'preview' ), 'project-brief' ); 24}); 25 26test ( 'a Settings bookmark opens over chat; closing restores only the background URL' , () => { 27const bookmark = router . parseLocation ( '#/settings' ); 28assert . equal ( bookmark . route , 'chat' ); 29assert . equal ( bookmark . query . get ( 'settings' ), '1' ); 30browserWindow . location . hash = '#/chat/chat-a?preview=project-brief&settings=1' ; 31router . closeSettings (); 32assert . equal ( browserWindow . location . hash , '#/chat/chat-a?preview=project-brief' ); 33browserWindow . location . hash = '#/monitor' ; 34router . navigate ( 'settings' ); 35assert . equal ( browserWindow . location . hash , '#/monitor?settings=1' ); 36router . closeSettings (); 37assert . equal ( browserWindow . location . hash , '#/monitor' ); 38}); 39 40 41test ( 'Settings opens and closes immediately without snapshotting the background page' , () => { 42browserWindow . location . hash = '#/chat/a' ; 43router . navigate ( 'settings' ); 44assert . equal ( browserWindow . location . hash , '#/chat/a?settings=1' ); 45router . closeSettings (); 46assert . equal ( browserWindow . location . hash , '#/chat/a' ); 47assert . equal ( transitions , 0 ); 48router . navigate ( 'models' ); 49assert . equal ( transitions , 1 , 'ordinary screen navigation still uses its view transition' ); 50});