aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/assistant/test_ops.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 16:41:51 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 16:41:51 +0200
commit607934e74ffabc1dcce72b29fc28e92a669e54ce (patch)
tree47ca9f67742c1892ff9197b5d4d31f6dd6534d36 /desktop/assistant/test_ops.js
parent9a2a0c93cc30af979a26d957fef603e2378676be (diff)
downloadquickshell-607934e74ffabc1dcce72b29fc28e92a669e54ce.tar.gz
quickshell-607934e74ffabc1dcce72b29fc28e92a669e54ce.zip
feat(assistant): the Do row of file operations
Conversions, extraction, merge and compression on the staged files from the file state, one at a time, with Stop; Compress… opens its formats. To .md goes through the daemon's write, the rest through fileops. The card keeps the result line, Saved name with Open and Folder, or the error, so another operation can follow on the same files. Results land in Documents/Assistant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/assistant/test_ops.js')
-rw-r--r--desktop/assistant/test_ops.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/desktop/assistant/test_ops.js b/desktop/assistant/test_ops.js
new file mode 100644
index 0000000..6d53376
--- /dev/null
+++ b/desktop/assistant/test_ops.js
@@ -0,0 +1,45 @@
+// 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_ops.js
+// Ops.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 + "/Ops.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const O = new Function(src + "\nreturn { offered, COMPRESS };")();
+
+const f = (name, kind) => ({ path: "/x/" + name, name, kind });
+const labels = files => O.offered(files).map(o => o.label);
+
+assert.deepStrictEqual(labels([f("a.pdf", "pdf")]), ["To .md", "To images", "Compress…"]);
+assert.deepStrictEqual(labels([f("a.pdf", "pdf"), f("b.pdf", "pdf")]),
+ ["To .md", "To images", "Merge", "Compress…"]);
+assert.deepStrictEqual(labels([f("a.pdf", "pdf"), f("p.png", "image")]), ["Compress…"]);
+// An image's own format is not offered.
+assert.deepStrictEqual(labels([f("p.png", "image")]), ["To JPEG", "To WebP", "Resize 50%", "Compress…"]);
+assert.deepStrictEqual(labels([f("p.JPG", "image")]), ["To PNG", "To WebP", "Resize 50%", "Compress…"]);
+// Mixed formats: offered while any file would change.
+assert.deepStrictEqual(labels([f("p.png", "image"), f("q.jpg", "image")]),
+ ["To PNG", "To JPEG", "To WebP", "Resize 50%", "Compress…"]);
+assert.deepStrictEqual(labels([f("c.mp4", "video")]),
+ ["Extract audio", "To WebM", "To GIF", "Trackcrop", "Compress…"]);
+assert.deepStrictEqual(labels([f("c.mkv", "video")]),
+ ["Extract audio", "To MP4", "To WebM", "To GIF", "Trackcrop", "Compress…"]);
+assert.deepStrictEqual(labels([f("b.tar.gz", "archive")]), ["Extract", "Compress…"]);
+assert.deepStrictEqual(labels([f("n.txt", "text")]), ["Compress…"]);
+assert.deepStrictEqual(labels([]), []);
+assert.deepStrictEqual(O.COMPRESS.map(c => c.op), ["zip", "tgz", "txz", "tbz2"]);
+
+console.log("ok");