From 9060142f5d3a0742167c557bd10cab91c8a12e7a Mon Sep 17 00:00:00 2001 From: saphid <4596216+saphid@users.noreply.github.com> Date: Tue, 20 Oct 2026 23:34:00 +1100 Subject: [PATCH] Test: a Home shortcut keeps its destination's scroll and loads its tool once, even when hashchange beats the next frame Co-Authored-By: Claude Opus 5.5 --- tests/ui_workspace.cjs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/ui_workspace.cjs b/tests/ui_workspace.cjs index 93754cd..0472035 100644 --- a/tests/ui_workspace.cjs +++ b/tests/ui_workspace.cjs @@ -298,3 +298,23 @@ test('Home shortcuts show their tool before focusing it, so typing works on the f.run(html.slice(start,end).replace(/showPage\(\)/g,'globalThis.showPage()'));buttons[0].onclick(); assert.equal(focusedVisible,true);assert.equal(shows,1);assert.equal(f.context.location.hash,'#pad'); }); +test('a Home shortcut keeps the destination scroll and loads its tool once, with frames deferred',()=>{ + const f=workspaceFixture(),frames=[],events=[],buttons=[{dataset:{go:'pad'}},{dataset:{go:'macview'}}]; + // A hash assignment queues hashchange, which a browser may deliver before the next frame. + let hash=f.context.location.hash; + Object.defineProperty(f.context.location,'hash',{get:()=>hash,set(v){const next='#'+String(v).replace(/^#/,'');if(next!==hash){hash=next;events.push(()=>f.run('showPage({type:"hashchange"})'));}}}); + const flush=()=>{while(events.length||frames.length)(events.length?events:frames).shift()();}; + f.context.requestAnimationFrame=fn=>frames.push(fn); + f.context.document.querySelectorAll=(q=>s=>s==='[data-go]'?buttons:q(s))(f.context.document.querySelectorAll); + Object.assign(f.context,{pad:{state:'on'},padStart(){},history:{pushState(_,__,url){hash=url;}}}); + f.el('padType').focus=()=>{}; + f.navigate('#pad');flush();f.scroll(320); + f.navigate('#home');flush();f.scroll(150); + const start=html.indexOf('document.querySelectorAll("[data-go]")'),end=html.indexOf('$("nowSend").onclick',start); + f.run(html.slice(start,end)); + buttons[0].onclick();flush(); + assert.equal(f.context.window.scrollY,320); + f.navigate('#home');flush();f.calls.length=0; + buttons[1].onclick();flush(); + assert.equal(f.calls.filter(c=>c[0]==='macview').length,1); +});