aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/user/test_user.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 09:57:22 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 09:57:22 +0200
commit5fabbeb09aea782b7df05e8827b552e5ec44cf83 (patch)
tree693f3c61dc60a8f4ca3e6b18e55117de4d85cf07 /desktop/modules/user/test_user.js
parentd5eaa4855a90057c268bf4d717f366ccf3197dba (diff)
downloadquickshell-5fabbeb09aea782b7df05e8827b552e5ec44cf83.tar.gz
quickshell-5fabbeb09aea782b7df05e8827b552e5ec44cf83.zip
feat(user): helpers for the user page
Parsing userctl's output and locale -a, and the git name preview, kept out of QML so node can test them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/user/test_user.js')
-rw-r--r--desktop/modules/user/test_user.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/desktop/modules/user/test_user.js b/desktop/modules/user/test_user.js
new file mode 100644
index 0000000..3ab22a1
--- /dev/null
+++ b/desktop/modules/user/test_user.js
@@ -0,0 +1,47 @@
+// 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/modules/user/test_user.js
+// User.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 + "/User.js", "utf8")
+ .replace(/^\.pragma library$/m, "");
+const U = new Function(src + "\nreturn { parse, keys, locales, gitName };")();
+
+// parse: key=value lines; a value may itself hold "=".
+assert.deepStrictEqual(U.parse("name=Jane Doèr\nlocation=a=b\n\n"),
+ { name: "Jane Doèr", location: "a=b" });
+assert.deepStrictEqual(U.parse(""), {});
+// userctl get prints a lone error= line when AccountsService cannot be read.
+assert.deepStrictEqual(U.parse("error=boom\n"), { error: "boom" });
+
+// keys: userctl keys lines into {fpr, uid}.
+assert.deepStrictEqual(U.keys("AAAA\tJane <j@example.org>\nBBBB\tWork\n"),
+ [{ fpr: "AAAA", uid: "Jane <j@example.org>" }, { fpr: "BBBB", uid: "Work" }]);
+
+// locales: UTF-8 entries of locale -a, spelled as AccountsService stores
+// them; C and POSIX left out; sorted.
+assert.deepStrictEqual(U.locales("C\nC.utf8\nPOSIX\nit_IT.utf8\nen_US.UTF-8\nde_DE\nfr_FR.utf8\n"),
+ ["en_US.UTF-8", "fr_FR.UTF-8", "it_IT.UTF-8"]);
+
+// gitName: the same rule as userctl's gitname.
+assert.strictEqual(U.gitName("Jane Doèr"), "Jane D.");
+assert.strictEqual(U.gitName("Anna Maria Rossi"), "Anna Maria R.");
+assert.strictEqual(U.gitName("Cher"), "Cher");
+assert.strictEqual(U.gitName("Ève Àlba"), "Ève À.");
+assert.strictEqual(U.gitName(" Jane Doèr "), "Jane D.");
+assert.strictEqual(U.gitName(""), "");
+
+console.log("test_user: ok");