174 lines
6.2 KiB
HTML
174 lines
6.2 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Cookie Consent Integration Test Lab</title>
|
|
<style>
|
|
body {
|
|
font-family: system-ui, sans-serif;
|
|
max-width: 900px;
|
|
margin: 40px auto;
|
|
padding: 0 20px;
|
|
line-height: 1.5;
|
|
}
|
|
button {
|
|
padding: 10px 16px;
|
|
cursor: pointer;
|
|
}
|
|
#summary {
|
|
font-weight: 700;
|
|
margin: 20px 0;
|
|
}
|
|
.pass { color: #176b2c; }
|
|
.fail { color: #a11; }
|
|
pre {
|
|
background: #f5f5f5;
|
|
padding: 16px;
|
|
overflow: auto;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>Cookie Consent Integration Test Lab</h1>
|
|
<p>Browser regression suite for the Jurisdiction Engine + Consent Core boundary.</p>
|
|
|
|
<button id="run">Run tests</button>
|
|
<div id="summary">Not run.</div>
|
|
<pre id="output"></pre>
|
|
|
|
<script type="module">
|
|
import {
|
|
resolveConsentContext,
|
|
createIntegratedConsentEngine
|
|
} from "../../integration/index.js";
|
|
|
|
const output = document.getElementById("output");
|
|
const summary = document.getElementById("summary");
|
|
const runButton = document.getElementById("run");
|
|
|
|
function equal(actual, expected) {
|
|
if (actual !== expected) {
|
|
throw new Error(`Expected ${expected}, got ${actual}`);
|
|
}
|
|
}
|
|
|
|
function deepEqual(actual, expected) {
|
|
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
|
|
throw new Error("Values are not deeply equal.");
|
|
}
|
|
}
|
|
|
|
function throws(fn, pattern) {
|
|
try {
|
|
fn();
|
|
} catch (error) {
|
|
if (pattern.test(error.message)) return;
|
|
throw error;
|
|
}
|
|
throw new Error("Expected function to throw.");
|
|
}
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
output.textContent += `PASS: ${name}\n`;
|
|
return true;
|
|
} catch (error) {
|
|
output.textContent += `FAIL: ${name}\n${error.stack || error}\n`;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
runButton.addEventListener("click", () => {
|
|
output.textContent = "";
|
|
let passed = 0;
|
|
const total = 9;
|
|
|
|
if (test("fixed us-ma resolves into Core context", () => {
|
|
const context = resolveConsentContext({
|
|
mode: "fixed", jurisdiction: "us-ma"
|
|
});
|
|
equal(context.resolution.jurisdiction.id, "us-ma");
|
|
equal(context.resolution.policy.id, "us-state-privacy");
|
|
})) passed++;
|
|
|
|
if (test("fixed eu resolves into Core context", () => {
|
|
const context = resolveConsentContext({
|
|
mode: "fixed", jurisdiction: "eu"
|
|
});
|
|
equal(context.resolution.jurisdiction.id, "eu");
|
|
equal(context.resolution.policy.id, "eu-privacy");
|
|
})) passed++;
|
|
|
|
if (test("global resolves into global baseline", () => {
|
|
const context = resolveConsentContext({ mode: "global" });
|
|
equal(context.resolution.jurisdiction.id, "global");
|
|
equal(context.resolution.policy.id, "global-baseline");
|
|
})) passed++;
|
|
|
|
if (test("integration configures Core jurisdiction", () => {
|
|
const consent = createIntegratedConsentEngine({
|
|
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
|
});
|
|
const state = consent.initialize();
|
|
equal(state.jurisdiction, "us-ma");
|
|
equal(state.hasDecision, false);
|
|
})) passed++;
|
|
|
|
if (test("jurisdiction does not grant consent", () => {
|
|
const consent = createIntegratedConsentEngine({
|
|
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
|
});
|
|
const state = consent.initialize();
|
|
equal(state.categories.necessary, "granted");
|
|
equal(state.categories.preferences, "unknown");
|
|
equal(state.categories.analytics, "unknown");
|
|
equal(state.categories.marketing, "unknown");
|
|
equal(state.hasDecision, false);
|
|
})) passed++;
|
|
|
|
if (test("resolved context is exposed as frozen data", () => {
|
|
const consent = createIntegratedConsentEngine({
|
|
jurisdiction: { mode: "fixed", jurisdiction: "eu" }
|
|
});
|
|
const context = consent.getJurisdictionContext();
|
|
equal(context.resolution.jurisdiction.id, "eu");
|
|
equal(Object.isFrozen(context), true);
|
|
})) passed++;
|
|
|
|
if (test("Core persistence uses resolved jurisdiction", () => {
|
|
const consent = createIntegratedConsentEngine({
|
|
jurisdiction: { mode: "fixed", jurisdiction: "us-ma" }
|
|
});
|
|
consent.initialize();
|
|
consent.acceptAll();
|
|
equal(consent.getState().jurisdiction, "us-ma");
|
|
equal(consent.getState().hasDecision, true);
|
|
})) passed++;
|
|
|
|
if (test("integration is deterministic", () => {
|
|
const input = {
|
|
mode: "auto",
|
|
request: { jurisdiction: "us-ma", source: "server" },
|
|
visitor: { jurisdiction: "eu", source: "browser" }
|
|
};
|
|
deepEqual(
|
|
resolveConsentContext(input),
|
|
resolveConsentContext(input)
|
|
);
|
|
})) passed++;
|
|
|
|
if (test("invalid jurisdiction remains an Engine error", () => {
|
|
throws(() => resolveConsentContext({
|
|
mode: "fixed", jurisdiction: "not-a-jurisdiction"
|
|
}), /Unknown jurisdiction/);
|
|
})) passed++;
|
|
|
|
summary.textContent = `${passed}/${total} tests passed`;
|
|
summary.className = passed === total ? "pass" : "fail";
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|