mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-12 15:33:45 +08:00
00364fd645
Separate Galaxy authentication and local access policy from web presentation. Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
22 lines
1.5 KiB
JavaScript
22 lines
1.5 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import fs from "node:fs"
|
|
const text=fs.readFileSync(new URL("../web/js/route-leave.js", import.meta.url),"utf8")
|
|
const {createRouteLeave}=await import("data:text/javascript;base64,"+Buffer.from(text).toString("base64"))
|
|
let entries=[{path:"/",index:0}],at=0,shown="/",pending,queue=[]
|
|
const port={read:()=>entries[at],show:()=>{shown=entries[at].path},
|
|
push:(path,index)=>{entries=entries.slice(0,at+1);entries.push({path,index});at++},
|
|
replace:(path,index)=>{entries[at]={path,index}},
|
|
go:delta=>queue.push(()=>{at+=delta;nav.changed();queue.push(()=>nav.changed())})}
|
|
const nav=createRouteLeave(port)
|
|
const flush=()=>{while(queue.length)queue.shift()()}
|
|
nav.navigate("/tools");nav.navigate("/theme_maker");nav.setGuard(callback=>{pending=callback})
|
|
port.go(-1);flush();assert.equal(shown,"/theme_maker");assert.equal(port.read().path,"/theme_maker")
|
|
nav.navigate("/settings");pending();assert.equal(shown,"/settings")
|
|
nav.setGuard(callback=>{pending=callback})
|
|
port.push("/logs",port.read().index);nav.changed();queue.push(()=>nav.changed());flush()
|
|
assert.equal(port.read().path,"/settings");assert.equal(shown,"/settings")
|
|
pending();flush();assert.equal(shown,"/logs")
|
|
port.go(-1);flush();assert.equal(shown,"/logs");pending();flush();assert.equal(shown,"/settings")
|
|
port.go(1);flush();assert.equal(shown,"/settings");pending();flush();assert.equal(shown,"/logs")
|
|
console.log("async Back/Forward, retained-state hash and canceled-then-new navigation passed")
|