Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { createAnnotationIdSource } from "./AnnotationIds.ts";
4
5describe("createAnnotationIdSource", () => {
6 it("gives annotations picked on separate page loads distinct ids", () => {
7 // The picker preload runs afresh on every page load, while the composer
8 // keeps earlier annotations keyed by id.
9 const firstLoad = createAnnotationIdSource();
10 firstLoad("element");
11 const firstAnnotation = firstLoad("annotation");
12
13 const secondLoad = createAnnotationIdSource();
14 secondLoad("element");
15 const secondAnnotation = secondLoad("annotation");
16
17 expect(secondAnnotation).not.toBe(firstAnnotation);
18 });
19
20 it("never repeats an id within one page load", () => {
21 const nextId = createAnnotationIdSource();
22 const ids = Array.from({ length: 1_000 }, () => nextId("annotation"));
23 expect(new Set(ids).size).toBe(ids.length);
24 });
25});