diff options
Diffstat (limited to 'desktop/assistant/test_presets.js')
| -rw-r--r-- | desktop/assistant/test_presets.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/assistant/test_presets.js b/desktop/assistant/test_presets.js new file mode 100644 index 0000000..e4a18f4 --- /dev/null +++ b/desktop/assistant/test_presets.js @@ -0,0 +1,46 @@ +// Copyright (C) 2026 Danilo M. <danix@danix.xyz> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Run: node desktop/assistant/test_presets.js +// Presets.js is a QML library, so its .pragma line is stripped before node +// evaluates it. + +const fs = require("fs"); +const assert = require("assert"); + +const src = fs.readFileSync(__dirname + "/Presets.js", "utf8") + .replace(/^\.pragma library$/m, ""); +const P = new Function(src + "\nreturn { DEFAULTS, list, offered, prompt };")(); + +const files = (...kinds) => kinds.map((kind, i) => ({ path: `/f${i}`, name: `f${i}`, kind })); +const labels = staged => P.offered(P.DEFAULTS, staged).map(p => p.label); + +assert.deepStrictEqual(labels(files("pdf")), ["Summarize", "Key points", "Explain simply", "Extract text"]); +assert.deepStrictEqual(labels(files("image", "pdf")), ["Extract text", "Compare"]); +assert.deepStrictEqual(labels(files("code", "code")), ["Explain", "Review", "Compare"]); +assert.deepStrictEqual(labels(files("code")), ["Explain", "Review"]); +assert.deepStrictEqual(labels(files("text")), ["Summarize", "Explain simply"]); +assert.deepStrictEqual(labels(files("image")), ["Describe", "Extract text", "What is this?"]); +assert.deepStrictEqual(labels(files("video")), []); +assert.deepStrictEqual(labels([]), []); + +// Every prompt asks for the document's language. +for (const p of P.DEFAULTS) + assert.ok(P.prompt(p).endsWith(" Answer in the language of the document."), p.label); + +// A saved list is used when valid; anything else reads as the defaults. +const mine = [{ label: "Mine", prompt: "Do it.", kinds: ["pdf"] }]; +assert.strictEqual(P.list(mine), mine); +for (const bad of [null, undefined, {}, "x", [{ label: "No kinds", prompt: "p" }], + [{ label: 3, prompt: "p", kinds: [] }], [null]]) + assert.strictEqual(P.list(bad), P.DEFAULTS, JSON.stringify(bad)); + +console.log("ok"); |
