From 8a59f92d031963e23ecc84b75feecf43eb4dd146 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Fri, 24 Apr 2026 11:33:25 -0700 Subject: Initial commit: @eol/graphiql v0.3 Svelte 5 GraphiQL alternative for JSR. Covers: - HTTP fetcher with injectable fetch; SSE/WS stubs - Session store with tabs, auto-titling, persistence, rename - Operation detection via graphql parse(); Toolbar picker - CodeMirror 6 editor via cm6-graphql with theme prop - Light theme preset (hand-rolled EditorView.theme) - Doc explorer with breadcrumb nav and type guards - History panel with 100-entry cap, favorite pinning - Deno tests for operations, storage, and history eviction --- tests/history.test.ts | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/history.test.ts (limited to 'tests/history.test.ts') diff --git a/tests/history.test.ts b/tests/history.test.ts new file mode 100644 index 0000000..ecd7785 --- /dev/null +++ b/tests/history.test.ts @@ -0,0 +1,77 @@ + + + +/*** IMPORT ------------------------------------------- ***/ + +import { assertEquals } from "jsr:@std/assert@^1.0.0"; + +/*** UTILITY ------------------------------------------ ***/ + +import { evict } from "../source/library/state/history-logic.ts"; + +type Entry = { + favorite: boolean; + id: string; + timestamp: number; +}; + +function entry(id: string, timestamp: number, favorite = false): Entry { + return { favorite, id, timestamp }; +} + +/*** TESTS -------------------------------------------- ***/ + +Deno.test("evict keeps everything when under cap", () => { + const entries = [entry("a", 3), entry("b", 2), entry("c", 1)]; + assertEquals(evict(entries, 5), entries); +}); + +Deno.test("evict drops the oldest non-favorites above cap", () => { + const entries = [ + entry("a", 5), + entry("b", 4), + entry("c", 3), + entry("d", 2), + entry("e", 1) + ]; + const kept = evict(entries, 3); + assertEquals(kept.map((e) => e.id), ["a", "b", "c"]); +}); + +Deno.test("evict never drops favorites", () => { + const entries = [ + entry("a", 10), + entry("b", 9), + entry("fav-old", 1, true), + entry("c", 8), + entry("d", 7) + ]; + const kept = evict(entries, 3); + + assertEquals(kept.some((e) => e.id === "fav-old"), true); + assertEquals(kept.length, 3); +}); + +Deno.test("evict can exceed cap when favorites alone do so", () => { + const entries = [ + entry("fav-1", 5, true), + entry("fav-2", 4, true), + entry("fav-3", 3, true), + entry("regular", 2) + ]; + const kept = evict(entries, 2); + + assertEquals(kept.length, 3); + assertEquals(kept.every((e) => e.favorite), true); +}); + +Deno.test("evict sorts by timestamp descending", () => { + const entries = [ + entry("c", 1), + entry("a", 3), + entry("b", 2), + entry("d", 0) + ]; + const kept = evict(entries, 3); + assertEquals(kept.map((e) => e.id), ["a", "b", "c"]); +}); -- cgit v1.2.3