From 607934e74ffabc1dcce72b29fc28e92a669e54ce Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 16:41:51 +0200 Subject: feat(assistant): the Do row of file operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- desktop/assistant/test_ops.js | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 desktop/assistant/test_ops.js (limited to 'desktop/assistant/test_ops.js') 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. +// +// 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"); -- cgit v1.2.3