7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
87 lines
3.1 KiB
JavaScript
87 lines
3.1 KiB
JavaScript
/**
|
|
* Tests for followup.js — FollowUpResearch.getResearchIdFromPage.
|
|
*
|
|
* Extracts the parent research ID from one of four fallback sources:
|
|
* 1. URL path segment (/results/<id>)
|
|
* 2. URL query param (?research_id=<id>)
|
|
* 3. DOM data-research-id attribute
|
|
* 4. window.currentResearchId
|
|
*
|
|
* Each test isolates exactly one source so the precedence order doesn't
|
|
* have to be re-derived from the test setup.
|
|
*/
|
|
|
|
let FollowUpResearch;
|
|
|
|
beforeAll(async () => {
|
|
// followup.js auto-constructs an instance and binds a DOMContentLoaded
|
|
// listener that fetches /static/templates/followup_modal.html. The
|
|
// DOMContentLoaded event has already fired in happy-dom by the time
|
|
// import settles, so the listener never runs — but stub fetch
|
|
// defensively in case ordering changes.
|
|
globalThis.fetch = vi.fn(() =>
|
|
Promise.resolve({ ok: false, status: 404, text: () => Promise.resolve('') })
|
|
);
|
|
|
|
await import('@js/followup.js');
|
|
FollowUpResearch = window.FollowUpResearch;
|
|
});
|
|
|
|
function setLocation(pathname, search = '') {
|
|
Object.defineProperty(window, 'location', {
|
|
configurable: true,
|
|
writable: true,
|
|
value: { pathname, search, hash: '', host: 'localhost', protocol: 'http:' },
|
|
});
|
|
}
|
|
|
|
describe('FollowUpResearch.getResearchIdFromPage', () => {
|
|
afterEach(() => {
|
|
document.body.innerHTML = '';
|
|
delete window.currentResearchId;
|
|
});
|
|
|
|
it('extracts the id from /results/<id> in the URL path', () => {
|
|
setLocation('/results/abc-123-def');
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBe('abc-123-def');
|
|
});
|
|
|
|
it('falls through to the query string when the path does not match', () => {
|
|
setLocation('/somewhere-else', '?research_id=xyz-789');
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBe('xyz-789');
|
|
});
|
|
|
|
it('falls through to a [data-research-id] DOM attribute', () => {
|
|
setLocation('/somewhere-else', '');
|
|
const el = document.createElement('div');
|
|
el.dataset.researchId = 'data-id-456';
|
|
document.body.appendChild(el);
|
|
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBe('data-id-456');
|
|
});
|
|
|
|
it('falls through to window.currentResearchId as the last resort', () => {
|
|
setLocation('/somewhere-else', '');
|
|
window.currentResearchId = 'window-id-999';
|
|
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBe('window-id-999');
|
|
});
|
|
|
|
it('returns null when none of the four sources have a value', () => {
|
|
setLocation('/somewhere-else', '');
|
|
// No DOM element, no window.currentResearchId.
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBeNull();
|
|
});
|
|
|
|
it('prefers the URL path over the query string (precedence smoke test)', () => {
|
|
setLocation('/results/from-path', '?research_id=from-query');
|
|
const fr = new FollowUpResearch();
|
|
expect(fr.getResearchIdFromPage()).toBe('from-path');
|
|
});
|
|
});
|