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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
import assert from "node:assert/strict";
const callbacks = [];
let killed = 0;
let removed = 0;
class Actor {
constructor(props = {}) {
Object.assign(this, props);
}
add_child() {}
set_text(text) {
this.text = text;
}
set_style_class_name(name) {
this.style = name;
}
destroy() {
this.destroyed = true;
}
}
class Button extends Actor {
menu = { addMenuItem() {}, addAction() {} };
}
class Item {
label = new Actor();
}
class Extension {
uuid = "test";
}
const St = { BoxLayout: Actor, Label: Actor };
const Clutter = { ActorAlign: { CENTER: 0 } };
const PanelMenu = { Button };
const PopupMenu = { PopupMenuItem: Item };
const Main = { panel: { addToStatusArea() {} }, notifyError() {} };
const GLib = {
PRIORITY_DEFAULT: 0,
SOURCE_CONTINUE: true,
timeout_add_seconds: () => 1,
Source: {
remove() {
removed++;
},
},
get_home_dir: () => "/home/test",
build_filenamev: (parts) => parts.join("/"),
};
const Gio = {
Cancellable: class {
cancelled = false;
cancel() {
this.cancelled = true;
}
is_cancelled() {
return this.cancelled;
}
},
SubprocessFlags: { NONE: 0, STDOUT_PIPE: 1, STDERR_PIPE: 2 },
Subprocess: {
new() {
return {
communicate_utf8_async(_input, _token, callback) {
callbacks.push(callback);
},
force_exit() {
killed++;
},
};
},
},
};
// EXTENSION
const panel = new CorporatePanel();
panel.enable();
panel._refresh();
assert.equal(callbacks.length, 1, "Do not overlap status processes");
panel._render({
displays: "EXT 1",
updates: "APT 3",
failed: "FAIL 1",
reboot: "",
errors: "",
});
assert.equal(panel._labels.failed.style, "corporate-critical");
assert.equal(panel._labels.updates.style, "corporate-warning");
assert.equal(panel._labels.reboot.visible, false);
const button = panel._button;
panel.disable();
assert.equal(killed, 1);
assert.equal(removed, 1);
assert.equal(button.destroyed, true);
panel.enable();
callbacks[0]({}, {});
assert.ok(panel._process, "Old callbacks cannot clear the new process");
const data = {
displays: "EXT 0",
updates: "APT 0",
failed: "FAIL 0",
reboot: "REBOOT",
errors: "",
};
callbacks[1](
{
communicate_utf8_finish: () => [true, JSON.stringify(data), ""],
get_successful: () => true,
},
{},
);
assert.equal(panel._labels.reboot.visible, true);
assert.equal(panel._process, null);
panel.disable();
|