62 lines
2.3 KiB
JavaScript
62 lines
2.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { describe, it } from "node:test";
|
|
import { buildPortraitViews } from "../src/portraitViews.mjs";
|
|
|
|
describe("portrait views", () => {
|
|
it("builds multiple switchable result types from the same profile", () => {
|
|
const views = buildPortraitViews({
|
|
result: {
|
|
score: 72,
|
|
band: "high",
|
|
signals: [
|
|
{ id: "timezone", score: 1 },
|
|
{ id: "language", score: 1 },
|
|
{ id: "fonts", score: 0.75 },
|
|
],
|
|
},
|
|
localFacts: [
|
|
{ id: "ua", category: "device", sensitivity: "high" },
|
|
{ id: "storage", category: "privacy", sensitivity: "medium" },
|
|
{ id: "webdriver", category: "automation", sensitivity: "high", value: "疑似自动化" },
|
|
],
|
|
requestFacts: [
|
|
{ id: "server-observed-ip", category: "request", sensitivity: "high" },
|
|
{ id: "request-forwarded-for", category: "request", sensitivity: "high" },
|
|
],
|
|
networkDiagnostics: {
|
|
status: "done",
|
|
server: { observedIp: "198.51.100.8", forwardedFor: "203.0.113.9" },
|
|
webrtc: { summary: { total: 3, public: 1, private: 1, mdns: 1 } },
|
|
connection: { supported: true, effectiveType: "4g", rtt: 40 },
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(
|
|
views.map((view) => view.id),
|
|
["regional", "identity", "persistence", "network", "automation"],
|
|
);
|
|
assert.equal(views.find((view) => view.id === "regional").band, "high");
|
|
assert.equal(views.find((view) => view.id === "network").band, "high");
|
|
assert.equal(views.find((view) => view.id === "automation").band, "high");
|
|
assert.equal(views.find((view) => view.id === "persistence").evidenceCount, 1);
|
|
});
|
|
|
|
it("keeps non-regional result cards available before backend evidence", () => {
|
|
const views = buildPortraitViews({
|
|
result: {
|
|
score: 0,
|
|
band: "low",
|
|
signals: [],
|
|
},
|
|
localFacts: [
|
|
{ id: "ua", category: "device", sensitivity: "high" },
|
|
{ id: "hardware", category: "device", sensitivity: "medium" },
|
|
],
|
|
networkDiagnostics: { status: "idle" },
|
|
});
|
|
|
|
assert.equal(views.find((view) => view.id === "identity").band, "medium");
|
|
assert.equal(views.find((view) => view.id === "network").band, "ready");
|
|
});
|
|
});
|