aboutsummaryrefslogtreecommitdiff
path: root/tests/history.test.ts
diff options
context:
space:
mode:
authornetop://ウィビ <paul@webb.page>2026-04-24 11:33:25 -0700
committernetop://ウィビ <paul@webb.page>2026-04-24 11:33:25 -0700
commit8a59f92d031963e23ecc84b75feecf43eb4dd146 (patch)
tree75de5768885583897061a3b1795e4c987ce90039 /tests/history.test.ts
downloadgraphiql-8a59f92d031963e23ecc84b75feecf43eb4dd146.tar.gz
graphiql-8a59f92d031963e23ecc84b75feecf43eb4dd146.zip
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
Diffstat (limited to 'tests/history.test.ts')
-rw-r--r--tests/history.test.ts77
1 files changed, 77 insertions, 0 deletions
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"]);
+});