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/operations.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/operations.test.ts')
| -rw-r--r-- | tests/operations.test.ts | 64 |
1 files changed, 64 insertions, 0 deletions
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"); +}); |