This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user