mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-09 22:13:43 +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>
20 lines
800 B
JavaScript
20 lines
800 B
JavaScript
import assert from "node:assert/strict"
|
|
import { guardUnload } from "../web/js/unload-guard.js"
|
|
|
|
globalThis.window = new EventTarget()
|
|
let dirty = true
|
|
const stop = guardUnload(() => dirty)
|
|
const attempt = () => {
|
|
const event = new Event("beforeunload", { cancelable: true })
|
|
// Browsers expose a writable returnValue on BeforeUnloadEvent; Node's Event does not.
|
|
Object.defineProperty(event, "returnValue", { value: "", writable: true })
|
|
return window.dispatchEvent(event)
|
|
}
|
|
assert.equal(attempt(), false, "Live reload must defer while a draft is dirty")
|
|
dirty = false
|
|
assert.equal(attempt(), true, "Saving or discarding allows the pending reload")
|
|
dirty = true
|
|
stop()
|
|
assert.equal(attempt(), true, "An unmounted page must release its guard")
|
|
console.log("Unsaved draft unload guard passed")
|