aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/island/test_logic.js
blob: 5932991e1b2d876d0fc2fcb4f8b1b60bae14fbeb (plain)
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
// Run: node desktop/island/test_logic.js
// Logic.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 + "/Logic.js", "utf8")
    .replace(/^\.pragma library$/m, "");
const L = new Function(src +
    "\nreturn { volumeIcon, vmRole, flagFor, privacyRoles, parseOpenWindow };")();

// Volume: muted or zero is muted, then thirds.
assert.strictEqual(L.volumeIcon(0.5, true), "audio-volume-muted");
assert.strictEqual(L.volumeIcon(0, false), "audio-volume-muted");
assert.strictEqual(L.volumeIcon(0.2, false), "audio-volume-low");
assert.strictEqual(L.volumeIcon(undefined, false), "audio-volume-muted");
assert.strictEqual(L.volumeIcon(NaN, false), "audio-volume-muted");
assert.strictEqual(L.volumeIcon(0.33, false), "audio-volume-medium");
assert.strictEqual(L.volumeIcon(0.5, false), "audio-volume-medium");
assert.strictEqual(L.volumeIcon(0.66, false), "audio-volume-high");
assert.strictEqual(L.volumeIcon(1.2, false), "audio-volume-high");

// VM dots: Theme property names, "" for no dot.
assert.strictEqual(L.vmRole({ state: "running" }), "green");
assert.strictEqual(L.vmRole({ state: "paused" }), "yellow");
assert.strictEqual(L.vmRole({ state: "blocked" }), "yellow");
assert.strictEqual(L.vmRole({ state: "shutting down" }), "yellow");
assert.strictEqual(L.vmRole({ state: "suspended" }), "accent");
assert.strictEqual(L.vmRole({ state: "crashed" }), "red");
assert.strictEqual(L.vmRole({ state: "shut off", saved: true }), "blue");
assert.strictEqual(L.vmRole({ state: "shut off", saved: false }), "");
assert.strictEqual(L.vmRole({ state: "unknown" }), "");
assert.strictEqual(L.vmRole({}), "");

// Flags: wb-lang's mapping, an unknown layout is the English one, an empty
// read is Italian (the default keymap here).
assert.strictEqual(L.flagFor("Italian"), "flag-it.svg");
assert.strictEqual(L.flagFor("English (US)"), "burger.svg");
assert.strictEqual(L.flagFor("German"), "burger.svg");
assert.strictEqual(L.flagFor(""), "flag-it.svg");

// Privacy: fixed order mic, cam, loc, scr.
assert.deepStrictEqual(L.privacyRoles(false, false, false, false), []);
assert.deepStrictEqual(L.privacyRoles(true, false, false, true), ["green", "red"]);
assert.deepStrictEqual(L.privacyRoles(true, true, true, true),
    ["green", "yellow", "blue", "red"]);

// openwindow: "address,workspace,class,title"; the title may hold commas.
assert.deepStrictEqual(L.parseOpenWindow("55d1a0,3,kitty,a, b, c"),
    { address: "55d1a0", workspace: "3", appClass: "kitty" });
assert.deepStrictEqual(L.parseOpenWindow(""),
    { address: "", workspace: "", appClass: "" });

console.log("ok");