generated from coulomb/repo-seed
Bootstrap @citation-evidence/engine as a standalone TypeScript package with shared types and engine services copied from the umbrella MVP. All 89 tests pass with lint and typecheck clean.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
/**
|
|
* Unit tests for `openContextUrl()`. Locks the shape from
|
|
* `wiki/ArchitectureOverview.md` §14.3.
|
|
*/
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import type { AnnotationId, DocumentId } from "./ids";
|
|
import { openContextUrl } from "./open-context-url";
|
|
|
|
const DOC = "doc_abc-123" as DocumentId;
|
|
const ANN = "ann_def-456" as AnnotationId;
|
|
|
|
describe("openContextUrl()", () => {
|
|
it("produces the canonical /viewer?document=…&annotation=… shape", () => {
|
|
expect(openContextUrl({ documentId: DOC, annotationId: ANN })).toBe(
|
|
"/viewer?document=doc_abc-123&annotation=ann_def-456",
|
|
);
|
|
});
|
|
|
|
it("percent-encodes reserved characters in ids", () => {
|
|
const ugly = "doc with spaces&=#" as DocumentId;
|
|
const url = openContextUrl({ documentId: ugly, annotationId: ANN });
|
|
expect(url).toBe(
|
|
"/viewer?document=doc%20with%20spaces%26%3D%23&annotation=ann_def-456",
|
|
);
|
|
// round-trip
|
|
const params = new URL(url, "https://example.test").searchParams;
|
|
expect(params.get("document")).toBe("doc with spaces&=#");
|
|
expect(params.get("annotation")).toBe("ann_def-456");
|
|
});
|
|
});
|