1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// 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 shared/test_notify_config.js
// NotifyConfig.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 + "/NotifyConfig.js", "utf8")
.replace(/^\.pragma library$/m, "");
const C = new Function(src + "\nreturn { defaults, resolve, withheld, soundFor };")();
// Nothing, or garbage, is the defaults.
assert.deepStrictEqual(C.resolve(undefined), C.defaults());
assert.deepStrictEqual(C.resolve("x"), C.defaults());
// Partial merges; wrong types and bad values keep their defaults.
const r = C.resolve({ timeouts: { low: 3, normal: "x" }, liveCap: 500, historyCap: 0,
balloons: { corner: "middle", screen: "HDMI-A-1" },
dndPassCritical: false, muted: ["a", 3, "b"] });
assert.deepStrictEqual(r.timeouts, { low: 3, normal: 10, critical: 0 });
assert.strictEqual(r.liveCap, 100);
assert.strictEqual(r.historyCap, 1);
assert.deepStrictEqual(r.balloons, { screen: "HDMI-A-1", corner: "bottom-right" });
assert.strictEqual(r.dndPassCritical, false);
assert.deepStrictEqual(r.muted, ["a", "b"]);
// Timeouts above a day are out of range, as in the daemon: the default.
assert.strictEqual(C.resolve({ timeouts: { critical: 100000 } }).timeouts.critical, 0);
assert.strictEqual(C.resolve({ timeouts: { low: 86400 } }).timeouts.low, 86400);
// Suppression: muted always, DND per dndPassCritical.
const n = (app, urgency) => ({ app, urgency });
const cfg = C.resolve({ muted: ["spam"] });
assert.strictEqual(C.withheld(cfg, n("spam", "critical"), false), true);
assert.strictEqual(C.withheld(cfg, n("ok", "normal"), false), false);
assert.strictEqual(C.withheld(cfg, n("ok", "normal"), true), true);
assert.strictEqual(C.withheld(cfg, n("ok", "critical"), true), false);
assert.strictEqual(C.withheld(C.resolve({ dndPassCritical: false }), n("ok", "critical"), true), true);
// Sounds: strings only, empty theme falls back.
const s = C.resolve({ sounds: { low: "/a.oga", normal: 3 }, soundTheme: "" });
assert.deepStrictEqual(s.sounds, { low: "/a.oga", normal: "", critical: "" });
assert.strictEqual(s.soundTheme, "freedesktop");
assert.strictEqual(C.resolve({ soundTheme: "mine" }).soundTheme, "mine");
// soundFor: silent beats everything, the app's sound beats the urgency's.
const sc = C.resolve({ sounds: { low: "", normal: "/n.oga", critical: "/c.oga" } });
const sn = (urgency, sound, silent) => ({ app: "x", urgency, sound, silent });
assert.strictEqual(C.soundFor(sc, sn("normal", "", false)), "/n.oga");
assert.strictEqual(C.soundFor(sc, sn("low", "", false)), "");
assert.strictEqual(C.soundFor(sc, sn("low", "/app.oga", false)), "/app.oga");
assert.strictEqual(C.soundFor(sc, sn("critical", "/app.oga", true)), "");
// An old daemon publishes neither field.
assert.strictEqual(C.soundFor(sc, { app: "x", urgency: "critical" }), "/c.oga");
console.log("ok");
|