fix(licensing): keep hash target revealed after next-stage updates
This commit is contained in:
@@ -462,7 +462,7 @@ export default function InvestmentPath(path: Path) {
|
|||||||
reveal();
|
reveal();
|
||||||
window.addEventListener('hashchange', reveal);
|
window.addEventListener('hashchange', reveal);
|
||||||
return () => window.removeEventListener('hashchange', reveal);
|
return () => window.removeEventListener('hashchange', reveal);
|
||||||
}, [path.case.id, path.context_opportunity, stageCodes]);
|
}, [path.case.id, path.context_opportunity, stageCodes, path.next?.code]);
|
||||||
const { auth, flash } = usePage<{
|
const { auth, flash } = usePage<{
|
||||||
auth: { user: { id: number } };
|
auth: { user: { id: number } };
|
||||||
flash: { success?: string };
|
flash: { success?: string };
|
||||||
|
|||||||
@@ -200,11 +200,12 @@ test("unknown, absent or out-of-scope hash targets have no effect", () => {
|
|||||||
assert.equal(f.phase.open, false);
|
assert.equal(f.phase.open, false);
|
||||||
assert.deepEqual(f.calls, []);
|
assert.deepEqual(f.calls, []);
|
||||||
});
|
});
|
||||||
test("page reveals the initial hash, listens for later hash changes and cleans up the listener", () => {
|
test("page reveals the initial hash and server next-stage updates, listens for hash changes and cleans up", () => {
|
||||||
const f = targetFixture(),
|
const f = targetFixture(),
|
||||||
effects = [],
|
effects = [],
|
||||||
listeners = new Map();
|
listeners = new Map();
|
||||||
const previousWindow = globalThis.window;
|
const previousWindow = globalThis.window;
|
||||||
|
let previousDependencies;
|
||||||
globalThis.window = {
|
globalThis.window = {
|
||||||
location: { hash: "#S08" },
|
location: { hash: "#S08" },
|
||||||
addEventListener: (type, fn) => listeners.set(type, fn),
|
addEventListener: (type, fn) => listeners.set(type, fn),
|
||||||
@@ -233,7 +234,12 @@ test("page reveals the initial hash, listens for later hash changes and cleans u
|
|||||||
{
|
{
|
||||||
...React,
|
...React,
|
||||||
useRef: () => ({ current: f.root }),
|
useRef: () => ({ current: f.root }),
|
||||||
useEffect: (effect) => effects.push(effect),
|
useEffect: (effect, dependencies) => {
|
||||||
|
if (!previousDependencies || dependencies.some((value, i) => value !== previousDependencies[i])) {
|
||||||
|
effects.push(effect);
|
||||||
|
}
|
||||||
|
previousDependencies = dependencies;
|
||||||
|
},
|
||||||
useState: (initial) => [
|
useState: (initial) => [
|
||||||
typeof initial === "function" ? initial() : initial,
|
typeof initial === "function" ? initial() : initial,
|
||||||
() => {},
|
() => {},
|
||||||
@@ -249,6 +255,17 @@ test("page reveals the initial hash, listens for later hash changes and cleans u
|
|||||||
assert.equal(f.phase.open, true);
|
assert.equal(f.phase.open, true);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.equal(listeners.size, 0);
|
assert.equal(listeners.size, 0);
|
||||||
|
h.renderPage();
|
||||||
|
assert.equal(effects.length, 1);
|
||||||
|
// A saved transition changes the controlled phase's `open` prop.
|
||||||
|
h.path.next = { code: "S09" };
|
||||||
|
f.phase.open = false;
|
||||||
|
h.renderPage();
|
||||||
|
assert.equal(effects.length, 2);
|
||||||
|
const updatedCleanup = effects[1]();
|
||||||
|
assert.equal(f.phase.open, true);
|
||||||
|
updatedCleanup();
|
||||||
|
assert.equal(listeners.size, 0);
|
||||||
} finally {
|
} finally {
|
||||||
globalThis.window = previousWindow;
|
globalThis.window = previousWindow;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user