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/operations.test.ts | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/operations.test.ts (limited to 'tests/operations.test.ts') diff --git a/tests/operations.test.ts b/tests/operations.test.ts new file mode 100644 index 0000000..99357ea --- /dev/null +++ b/tests/operations.test.ts @@ -0,0 +1,64 @@ + + + +/*** IMPORT ------------------------------------------- ***/ + +import { assertEquals } from "jsr:@std/assert@^1.0.0"; + +/*** UTILITY ------------------------------------------ ***/ + +import { deriveTitle, parseOperations } from "../source/library/graphql/operations.ts"; + +/*** TESTS -------------------------------------------- ***/ + +Deno.test("parseOperations returns empty for blank query", () => { + assertEquals(parseOperations(""), []); + assertEquals(parseOperations(" "), []); +}); + +Deno.test("parseOperations returns empty on syntax error", () => { + assertEquals(parseOperations("query { ..."), []); +}); + +Deno.test("parseOperations captures a single named query", () => { + const ops = parseOperations("query Foo { viewer { id } }"); + assertEquals(ops, [{ name: "Foo", type: "query" }]); +}); + +Deno.test("parseOperations returns null name for anonymous ops", () => { + const ops = parseOperations("{ viewer { id } }"); + assertEquals(ops, [{ name: null, type: "query" }]); +}); + +Deno.test("parseOperations captures multiple operations", () => { + const ops = parseOperations(` + query Foo { a } + mutation Bar { b } + subscription Baz { c } + `); + assertEquals(ops, [ + { name: "Foo", type: "query" }, + { name: "Bar", type: "mutation" }, + { name: "Baz", type: "subscription" } + ]); +}); + +Deno.test("deriveTitle prefers the first operation name", () => { + const ops = parseOperations("query Foo { a }"); + assertEquals(deriveTitle("query Foo { a }", ops), "Foo"); +}); + +Deno.test("deriveTitle falls back to operation type", () => { + const ops = parseOperations("mutation { a }"); + assertEquals(deriveTitle("mutation { a }", ops), "mutation"); +}); + +Deno.test("deriveTitle falls back to the first 20 chars when unparsable", () => { + const query = "this is not valid graphql at all"; + assertEquals(deriveTitle(query, parseOperations(query)), "this is not valid gr"); +}); + +Deno.test("deriveTitle returns 'untitled' for empty input", () => { + assertEquals(deriveTitle("", []), "untitled"); + assertEquals(deriveTitle(" ", []), "untitled"); +}); -- cgit v1.2.3