Preserve S08 hash lifecycle while revealing linked SWOT tasks
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-10 18:17:13 +02:00
parent c790159250
commit 1c75a30a60
5 changed files with 104 additions and 10 deletions
+71
View File
@@ -270,3 +270,74 @@ test("page reveals the initial hash and server next-stage updates, listens for h
globalThis.window = previousWindow;
}
});
test('SWOT task anchor uses the shared hash listener inside the dossier and preserves S08', () => {
const f = targetFixture(),
effects = [],
listeners = new Map();
const previousWindow = globalThis.window;
const task = {
tagName: 'DETAILS',
open: false,
scrollIntoView: (options) => f.calls.push(['task-scroll', options]),
};
f.root.ownerDocument.getElementById = (id) =>
id === 'tarefas' ? task : id === 'S08' ? f.target : null;
f.root.contains = (node) => node === task || node === f.target;
globalThis.window = {
location: { hash: '#tarefas' },
addEventListener: (type, fn) => listeners.set(type, fn),
removeEventListener: (type) => listeners.delete(type),
};
try {
const h = harness(
{
investment_context: null,
facts: {},
fact_reasons: {},
phases: {},
fintech: null,
sector_contexts: [],
requests: [],
tasks: [],
results: [],
tools: {},
content_sources: [],
services: [],
steps: [{ code: 'S08', preparation_allowed: true }],
preparation_action: {
id: 'swot-qa',
title: 'Risco QA',
kind: 'risk',
opportunity: 'opportunity:42',
},
},
{
...React,
useRef: () => ({ current: f.root }),
useEffect: (effect) => effects.push(effect),
useState: (initial) => [
typeof initial === 'function' ? initial() : initial,
() => {},
],
},
);
h.renderPage();
assert.equal(effects.length, 1);
const cleanup = effects[0]();
assert.equal(task.open, true);
assert.equal(f.phase.open, false);
window.location.hash = '#S08';
listeners.get('hashchange')();
assert.equal(f.phase.open, true);
task.open = false;
window.location.hash = '#tarefas';
listeners.get('hashchange')();
assert.equal(task.open, true);
assert.equal(f.calls.filter((c) => c[0] === 'task-scroll').length, 2);
cleanup();
assert.equal(listeners.size, 0);
} finally {
globalThis.window = previousWindow;
}
});