diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-26 20:18:30 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-26 20:18:30 -0700 |
| commit | 3c06c95f396b6e911076bc3291d5855ed01b5caa (patch) | |
| tree | 17cd218339c52fbeee93d931303b04a3ff294f8b /tests/history.test.ts | |
| parent | f059d97ab7f6d74d61139ac698cb871be7cb632e (diff) | |
| download | graphiql-3c06c95f396b6e911076bc3291d5855ed01b5caa.tar.gz graphiql-3c06c95f396b6e911076bc3291d5855ed01b5caa.zip | |
cleanup and ready for launch
Diffstat (limited to 'tests/history.test.ts')
| -rw-r--r-- | tests/history.test.ts | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/history.test.ts b/tests/history.test.ts index a08c014..581c0ef 100644 --- a/tests/history.test.ts +++ b/tests/history.test.ts @@ -16,11 +16,7 @@ type Entry = { timestamp: number; }; -function entry(id: string, timestamp: number, favorite = false): Entry { - return { favorite, id, timestamp }; -} - -/*** TESTS -------------------------------------------- ***/ +/*** PROGRAM ------------------------------------------ ***/ test("evict keeps everything when under cap", () => { const entries = [entry("a", 3), entry("b", 2), entry("c", 1)]; @@ -35,7 +31,9 @@ test("evict drops the oldest non-favorites above cap", () => { entry("d", 2), entry("e", 1) ]; + const kept = evict(entries, 3); + expect(kept.map((e) => e.id)).toEqual(["a", "b", "c"]); }); @@ -47,6 +45,7 @@ test("evict never drops favorites", () => { entry("c", 8), entry("d", 7) ]; + const kept = evict(entries, 3); expect(kept.some((e) => e.id === "fav-old")).toEqual(true); @@ -60,6 +59,7 @@ test("evict can exceed cap when favorites alone do so", () => { entry("fav-3", 3, true), entry("regular", 2) ]; + const kept = evict(entries, 2); expect(kept.length).toEqual(3); @@ -73,6 +73,14 @@ test("evict sorts by timestamp descending", () => { entry("b", 2), entry("d", 0) ]; + const kept = evict(entries, 3); + expect(kept.map((e) => e.id)).toEqual(["a", "b", "c"]); }); + +/*** HELPER ------------------------------------------- ***/ + +function entry(id: string, timestamp: number, favorite = false): Entry { + return { favorite, id, timestamp }; +} |