diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-24 11:33:25 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-24 11:33:25 -0700 |
| commit | 8a59f92d031963e23ecc84b75feecf43eb4dd146 (patch) | |
| tree | 75de5768885583897061a3b1795e4c987ce90039 /tests/storage.test.ts | |
| download | graphiql-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/storage.test.ts')
| -rw-r--r-- | tests/storage.test.ts | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/storage.test.ts b/tests/storage.test.ts new file mode 100644 index 0000000..7d6ba73 --- /dev/null +++ b/tests/storage.test.ts @@ -0,0 +1,83 @@ + + + +/*** IMPORT ------------------------------------------- ***/ + +import { assertEquals } from "jsr:@std/assert@^1.0.0"; + +/*** UTILITY ------------------------------------------ ***/ + +import { + createLocalStorage, + createMemoryStorage +} from "../source/library/state/storage.ts"; + +/*** TESTS -------------------------------------------- ***/ + +Deno.test("memory storage round-trips objects", () => { + const storage = createMemoryStorage(); + storage.set("k", { hello: "world" }); + assertEquals(storage.get<{ hello: string }>("k"), { hello: "world" }); +}); + +Deno.test("memory storage returns null for missing keys", () => { + const storage = createMemoryStorage(); + assertEquals(storage.get("missing"), null); +}); + +Deno.test("memory storage remove clears a key", () => { + const storage = createMemoryStorage(); + storage.set("k", 42); + storage.remove("k"); + assertEquals(storage.get("k"), null); +}); + +Deno.test("memory storage instances are isolated", () => { + const a = createMemoryStorage(); + const b = createMemoryStorage(); + a.set("shared", 1); + assertEquals(b.get("shared"), null); +}); + +Deno.test("local storage namespaces keys", () => { + globalThis.localStorage.clear(); + + const alpha = createLocalStorage("alpha"); + const beta = createLocalStorage("beta"); + + alpha.set("shared", { tag: "a" }); + beta.set("shared", { tag: "b" }); + + assertEquals(alpha.get<{ tag: string }>("shared"), { tag: "a" }); + assertEquals(beta.get<{ tag: string }>("shared"), { tag: "b" }); + assertEquals(globalThis.localStorage.getItem("alpha:shared"), JSON.stringify({ tag: "a" })); + assertEquals(globalThis.localStorage.getItem("beta:shared"), JSON.stringify({ tag: "b" })); + + globalThis.localStorage.clear(); +}); + +Deno.test("local storage remove respects the namespace", () => { + globalThis.localStorage.clear(); + + const alpha = createLocalStorage("alpha"); + const beta = createLocalStorage("beta"); + + alpha.set("k", 1); + beta.set("k", 2); + + alpha.remove("k"); + assertEquals(alpha.get("k"), null); + assertEquals(beta.get<number>("k"), 2); + + globalThis.localStorage.clear(); +}); + +Deno.test("local storage returns null on malformed JSON", () => { + globalThis.localStorage.clear(); + globalThis.localStorage.setItem("alpha:bad", "not-json"); + + const alpha = createLocalStorage("alpha"); + assertEquals(alpha.get("bad"), null); + + globalThis.localStorage.clear(); +}); |