Repository navigation
Expand file tree
/
Copy pathTrayModel.test.js
More file actions
844 lines (750 loc) · 38 KB
/
Copy pathTrayModel.test.js
File metadata and controls
844 lines (750 loc) · 38 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
const test = require("node:test")
const assert = require("node:assert/strict")
const { spawnSync } = require("node:child_process")
const fs = require("node:fs")
const os = require("node:os")
const path = require("node:path")
const TrayModel = require("./TrayModel.js")
const restoreScript = path.join(__dirname, "restore-hosted.py")
function writeShell(layout) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tinytray-"))
const file = path.join(dir, "shell.json")
fs.writeFileSync(file, JSON.stringify({ bar: { layout } }))
return file
}
function dryRestore(shell, tray, ids, extraFlags) {
const flags = extraFlags || []
return spawnSync("python3", [restoreScript].concat(flags, ["--dry-run", shell, tray], ids), {
encoding: "utf8"
})
}
function clickable(target) {
return !!(
target
&& target.visible !== false
&& target.opacity !== 0
&& target.interactive !== false
&& target.pressable !== false
&& target.concealed !== true
&& typeof target.triggerPress === "function"
)
}
function applyConcealedOpacity(node) {
node.opacity = node.concealed ? 0 : 1
}
function panelPressable(target) {
return !!(target && target.triggerPress && target.visible !== false && target.opacity !== 0)
}
function pressTargetAt(targets) {
for (var i = targets.length - 1; i >= 0; i--) {
if (panelPressable(targets[i])) return targets[i]
}
return null
}
function button(overrides) {
return Object.assign({
triggerPress: function () {},
interactive: true,
pressable: true,
visible: true,
opacity: 1,
concealed: false,
children: []
}, overrides)
}
test("drawer rejects input when collapsed", () => {
assert.equal(TrayModel.drawerAcceptsInput(false, false), false)
})
test("drawer accepts input while expanded or a hosted panel is open", () => {
assert.equal(TrayModel.drawerAcceptsInput(true, false), true)
assert.equal(TrayModel.drawerAcceptsInput(false, true), true)
})
test("collapsed drawer buttons are skipped by bar click dispatch", () => {
const bluetooth = button()
const panel = { children: [bluetooth] }
assert.equal(clickable(bluetooth), true)
TrayModel.setDescendantClickable(panel, false)
assert.equal(bluetooth.interactive, false)
assert.equal(bluetooth.pressable, false)
assert.equal(bluetooth.concealed, true)
assert.equal(clickable(bluetooth), false)
})
test("open panel click on battery does not fire overlapping wifi", () => {
const network = button()
const power = button()
TrayModel.setDescendantClickable({ children: [network] }, false)
applyConcealedOpacity(network)
applyConcealedOpacity(power)
assert.equal(panelPressable(network), false)
assert.equal(pressTargetAt([power, network]), power)
})
test("collapsed drawer buttons leave the panel click list immediately", () => {
const targets = []
const bar = {
clickTargets: targets,
registerClickTarget: function (t) { if (targets.indexOf(t) === -1) targets.push(t) },
unregisterClickTarget: function (t) {
var i = targets.indexOf(t)
if (i !== -1) targets.splice(i, 1)
}
}
const power = button({ bar: bar })
const network = button({ bar: bar })
bar.registerClickTarget(power)
bar.registerClickTarget(network)
TrayModel.setDescendantClickable({ children: [network] }, false)
assert.equal(targets.indexOf(network), -1)
assert.equal(pressTargetAt(targets), power)
TrayModel.setDescendantClickable({ children: [network] }, true)
assert.notEqual(targets.indexOf(network), -1)
})
test("pinned or revealed drawer buttons stay dispatchable", () => {
const bluetooth = button({ interactive: false, pressable: false, concealed: true, opacity: 0 })
TrayModel.setDescendantClickable({ children: [bluetooth] }, true)
applyConcealedOpacity(bluetooth)
assert.equal(bluetooth.concealed, false)
assert.equal(clickable(bluetooth), true)
assert.equal(panelPressable(bluetooth), true)
})
test("walker returns 0 until a pressable child exists", () => {
const panel = { children: [] }
assert.equal(TrayModel.setDescendantClickable(panel, false), 0)
panel.children = [button()]
assert.equal(TrayModel.setDescendantClickable(panel, false), 1)
})
test("non-button descendants are left alone", () => {
const label = { interactive: true, children: [] }
TrayModel.setDescendantClickable({ children: [label] }, false)
assert.equal(label.interactive, true)
})
test("hosted omarchy panels resolve to first-party Panel.qml urls", () => {
assert.equal(
TrayModel.hostedWidgetUrl("/usr/share/omarchy", "omarchy.bluetooth"),
"file:///usr/share/omarchy/shell/plugins/panels/bluetooth/Panel.qml"
)
assert.equal(
TrayModel.hostedWidgetUrl("/usr/share/omarchy/", "omarchy.network"),
"file:///usr/share/omarchy/shell/plugins/panels/network/Panel.qml"
)
})
test("hosted widget urls ignore unknown or non-omarchy ids", () => {
assert.equal(TrayModel.hostedWidgetUrl("/usr/share/omarchy", "vincentritter.tinytray"), "")
assert.equal(TrayModel.hostedWidgetUrl("/usr/share/omarchy", ""), "")
assert.equal(TrayModel.hostedWidgetUrl("/usr/share/omarchy", "omarchy"), "")
})
test("hosted panel open ignores a foreign popout on the plugin bar facade", () => {
const foreign = { foreign: true }
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: null, foreignPopoutMarker: foreign }), false)
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: foreign, foreignPopoutMarker: foreign }), false)
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: { opened: true }, foreignPopoutMarker: foreign }), true)
})
test("missing extraWidgets keeps the default list, an empty array means none", () => {
const fallback = ["omarchy.bluetooth"]
assert.deepEqual(TrayModel.extraWidgetIdsFromSettings({}, fallback), ["omarchy.bluetooth"])
assert.deepEqual(TrayModel.extraWidgetIdsFromSettings({ extraWidgets: [] }, fallback), [])
assert.deepEqual(
TrayModel.extraWidgetIdsFromSettings({ extraWidgets: ["omarchy.audio"] }, fallback),
["omarchy.audio"]
)
const like = { 0: "omarchy.audio", 1: "omarchy.power", length: 2 }
assert.deepEqual(TrayModel.extraWidgetIdsFromSettings({ extraWidgets: like }, fallback), ["omarchy.audio", "omarchy.power"])
})
test("default hosted widgets are bluetooth, network, and display", () => {
assert.deepEqual(TrayModel.defaultExtraWidgetIds(), ["omarchy.bluetooth", "omarchy.network", "omarchy.monitor"])
assert.deepEqual(TrayModel.extraWidgetIdsFromSettings({}), ["omarchy.bluetooth", "omarchy.network", "omarchy.monitor"])
})
test("toggleId adds a missing widget and removes one that is already listed", () => {
assert.deepEqual(TrayModel.toggleId(["omarchy.bluetooth"], "omarchy.audio"), ["omarchy.bluetooth", "omarchy.audio"])
assert.deepEqual(TrayModel.toggleId(["omarchy.bluetooth", "omarchy.audio"], "omarchy.bluetooth"), ["omarchy.audio"])
assert.deepEqual(TrayModel.toggleId(["omarchy.bluetooth"], ""), ["omarchy.bluetooth"])
})
test("adding a bar widget takes it off the bar so the tray can host it", () => {
const add = TrayModel.extraWidgetTogglePlan(["omarchy.bluetooth"], "omarchy.audio", true)
assert.deepEqual(add.extras, ["omarchy.bluetooth", "omarchy.audio"])
assert.equal(add.adding, true)
assert.equal(add.setBarEnabled, false)
assert.equal(add.placeAfter, "")
const remove = TrayModel.extraWidgetTogglePlan(["omarchy.bluetooth", "omarchy.audio"], "omarchy.audio", false, "vincentritter.tinytray")
assert.deepEqual(remove.extras, ["omarchy.bluetooth"])
assert.equal(remove.adding, false)
assert.equal(remove.setBarEnabled, true)
assert.equal(remove.placeAfter, "vincentritter.tinytray")
})
test("returning a widget to the bar enables it after Tinytray, not a bare enable", () => {
assert.deepEqual(
TrayModel.barWidgetCommand("omarchy.audio", true, "vincentritter.tinytray"),
["omarchy", "plugin", "enable", "omarchy.audio", "--after", "vincentritter.tinytray"]
)
})
test("returning a widget without Tinytray as an anchor falls back to the right section", () => {
assert.deepEqual(
TrayModel.barWidgetCommand("omarchy.network", true, ""),
["omarchy", "plugin", "enable", "omarchy.network", "--section", "right"]
)
})
test("hosting a bar widget still disables it without placement", () => {
assert.deepEqual(
TrayModel.barWidgetCommand("omarchy.audio", false, "vincentritter.tinytray"),
["omarchy", "plugin", "disable", "omarchy.audio"]
)
})
test("adding an off-bar widget does not disable it on the bar", () => {
const add = TrayModel.extraWidgetTogglePlan(["omarchy.bluetooth"], "jankeesvw.herdr", false)
assert.deepEqual(add.extras, ["omarchy.bluetooth", "jankeesvw.herdr"])
assert.equal(add.adding, true)
assert.equal(add.setBarEnabled, null)
})
test("hostedIds skips widgets that are still on the bar", () => {
assert.deepEqual(
TrayModel.hostedIds(["omarchy.audio", "omarchy.bluetooth"], { right: [{ id: "omarchy.audio" }] }),
["omarchy.bluetooth"]
)
})
test("layoutWithoutWidget drops one id and leaves the others", () => {
const layout = { right: [{ id: "omarchy.audio" }, { id: "vincentritter.tinytray" }] }
const next = TrayModel.layoutWithoutWidget(layout, "omarchy.audio")
assert.equal(TrayModel.layoutHasWidget(next, "omarchy.audio"), false)
assert.equal(TrayModel.layoutHasWidget(next, "vincentritter.tinytray"), true)
})
test("catalog entries require a bar-widget manifest and a qml file url", () => {
const panel = TrayModel.catalogEntryFromManifest("/usr/share/omarchy/shell/plugins/panels/bluetooth", {
id: "omarchy.bluetooth",
name: "Bluetooth",
kinds: ["bar-widget"],
entryPoints: { barWidget: "Panel.qml" },
barWidget: { displayName: "Bluetooth" }
})
assert.equal(panel.id, "omarchy.bluetooth")
assert.equal(panel.title, "Bluetooth")
assert.equal(panel.url, "file:///usr/share/omarchy/shell/plugins/panels/bluetooth/Panel.qml")
assert.equal(TrayModel.catalogEntryFromManifest("/tmp/speedtest", {
id: "omarchy.speedtest",
kinds: ["panel"],
entryPoints: { panel: "Panel.qml" }
}), null)
})
test("catalog rows skip the tray itself and sort by title", () => {
const rows = TrayModel.catalogRows([
{ id: "vincentritter.tinytray", title: "Tinytray", url: "file:///tmp/Tray.qml" },
{ id: "vincent.tray", title: "My System tray", url: "file:///tmp/old.qml" },
{ id: "omarchy.tray", title: "System tray", url: "file:///tmp/stock.qml" },
{ id: "omarchy.audio", title: "Audio", url: "file:///tmp/audio.qml" },
{ id: "omarchy.bluetooth", title: "Bluetooth", url: "file:///tmp/bt.qml" }
], ["omarchy.bluetooth"], {
right: [
{ id: "omarchy.audio" },
{ id: "vincentritter.tinytray" },
{ id: "vincent.tray" },
{ id: "omarchy.tray" }
]
}, "vincentritter.tinytray")
assert.equal(rows.length, 2)
assert.equal(rows[0].id, "omarchy.audio")
assert.equal(rows[0].onBar, true)
assert.equal(rows[0].inTray, false)
assert.equal(rows[1].id, "omarchy.bluetooth")
assert.equal(rows[1].inTray, true)
assert.equal(rows[1].onBar, false)
})
test("catalog rows omit widgets that sit on another side of the bar", () => {
const rows = TrayModel.catalogRows([
{ id: "omarchy.clock", title: "Clock", url: "file:///tmp/clock.qml" },
{ id: "jankeesvw.herdr", title: "Herdr", url: "file:///tmp/herdr.qml" },
{ id: "omarchy.audio", title: "Audio", url: "file:///tmp/audio.qml" },
{ id: "omarchy.bluetooth", title: "Bluetooth", url: "file:///tmp/bt.qml" }
], ["omarchy.bluetooth"], {
left: [{ id: "jankeesvw.herdr" }],
center: [{ id: "omarchy.clock" }],
right: [{ id: "vincentritter.tinytray" }, { id: "omarchy.audio" }]
}, "vincentritter.tinytray")
assert.deepEqual(rows.map(function (row) { return row.id }), ["omarchy.audio", "omarchy.bluetooth"])
})
test("catalog rows include off-bar dropbox and tailscale so they can be added", () => {
const rows = TrayModel.catalogRows([
{ id: "omarchy.dropbox", title: "Dropbox", url: "file:///tmp/dropbox.qml" },
{ id: "omarchy.tailscale", title: "Tailscale", url: "file:///tmp/ts.qml" },
{ id: "omarchy.clock", title: "Clock", url: "file:///tmp/clock.qml" }
], [], {
center: [{ id: "omarchy.clock" }],
right: [{ id: "vincentritter.tinytray" }]
}, "vincentritter.tinytray")
assert.deepEqual(rows.map(function (row) { return row.id }), ["omarchy.dropbox", "omarchy.tailscale"])
assert.equal(rows[0].onBar, false)
assert.equal(rows[0].inTray, false)
})
test("catalog rows keep extraWidgets that the scan missed so they can be removed", () => {
const rows = TrayModel.catalogRows([], ["omarchy.dropbox"], {})
assert.equal(rows.length, 1)
assert.equal(rows[0].id, "omarchy.dropbox")
assert.equal(rows[0].inTray, true)
})
test("hosted widget url prefers a catalog entry over the omarchy panel convention", () => {
const catalog = [{ id: "omarchy.clock", url: "file:///tmp/BarWidget.qml" }]
assert.equal(
TrayModel.hostedWidgetUrl("/usr/share/omarchy", "omarchy.clock", catalog),
"file:///tmp/BarWidget.qml"
)
assert.equal(
TrayModel.hostedWidgetUrl("/usr/share/omarchy", "omarchy.bluetooth", catalog),
"file:///usr/share/omarchy/shell/plugins/panels/bluetooth/Panel.qml"
)
})
test("restore script no-ops while the tray is still in shell.json", () => {
const shell = writeShell({
right: [{ id: "vincentritter.tinytray" }, { id: "omarchy.audio" }]
})
const result = dryRestore(shell, "vincentritter.tinytray", ["omarchy.bluetooth"])
assert.equal(result.status, 0)
assert.equal(result.stdout, "")
})
test("restore script re-enables hosted widgets after the tray, in listed order", () => {
const shell = writeShell({
right: [{ id: "omarchy.tray" }, { id: "omarchy.audio" }]
})
const result = dryRestore(shell, "vincentritter.tinytray", ["omarchy.bluetooth", "omarchy.network"])
assert.equal(result.status, 0)
assert.equal(
result.stdout,
"omarchy plugin enable omarchy.bluetooth --after omarchy.tray\n" +
"omarchy plugin enable omarchy.network --after omarchy.bluetooth\n"
)
})
test("restore script skips widgets already on the bar and places the rest after the last kept id", () => {
const shell = writeShell({
right: [{ id: "omarchy.tray" }, { id: "omarchy.bluetooth" }]
})
const result = dryRestore(shell, "vincentritter.tinytray", ["omarchy.bluetooth", "omarchy.dropbox"])
assert.equal(result.status, 0)
assert.equal(result.stdout, "omarchy plugin enable omarchy.dropbox --after omarchy.bluetooth\n")
})
test("restore --force re-enables hosted widgets after Tinytray when it is still in the layout", () => {
const shell = writeShell({
right: [{ id: "vincentritter.tinytray" }, { id: "omarchy.audio" }]
})
const skipped = dryRestore(shell, "vincentritter.tinytray", ["omarchy.bluetooth"])
assert.equal(skipped.status, 0)
assert.equal(skipped.stdout, "")
const forced = dryRestore(shell, "vincentritter.tinytray", ["omarchy.bluetooth"], ["--force"])
assert.equal(forced.status, 0)
assert.equal(forced.stdout, "omarchy plugin enable omarchy.bluetooth --after vincentritter.tinytray\n")
})
test("restore without ids uses leaked extraWidgets on omarchy.tray", () => {
const shell = writeShell({
right: [{
id: "omarchy.tray",
extraWidgets: ["omarchy.bluetooth", "omarchy.network"],
chevron: "dot"
}]
})
const result = dryRestore(shell, "vincentritter.tinytray", [])
assert.equal(result.status, 0)
assert.equal(
result.stdout,
"omarchy plugin enable omarchy.bluetooth --after omarchy.tray\n" +
"omarchy plugin enable omarchy.network --after omarchy.bluetooth\n" +
"strip omarchy.tray\n"
)
})
test("restore without ids does not treat a stock omarchy.tray as the default hosted list", () => {
const shell = writeShell({
right: [{ id: "omarchy.tray" }]
})
const result = dryRestore(shell, "vincentritter.tinytray", [])
assert.equal(result.status, 0)
assert.equal(result.stdout, "")
})
test("restore without ids treats an empty leaked extraWidgets list as none", () => {
const shell = writeShell({
right: [{ id: "omarchy.tray", extraWidgets: [] }]
})
const result = dryRestore(shell, "vincentritter.tinytray", [])
assert.equal(result.status, 0)
assert.equal(result.stdout, "strip omarchy.tray\n")
})
test("restore strips Tinytray keys off omarchy.tray", () => {
const shell = writeShell({
right: [{
id: "omarchy.tray",
extraWidgets: ["omarchy.bluetooth"],
chevron: "dot",
expandOnHover: false,
monochromeIcons: true,
dropdownDrawer: true,
showAttention: false,
hidden: [],
pinned: [],
showPercentage: false
}, { id: "omarchy.bluetooth" }]
})
const result = spawnSync("python3", [restoreScript, shell, "vincentritter.tinytray", "omarchy.bluetooth"], {
encoding: "utf8"
})
assert.equal(result.status, 0)
const cfg = JSON.parse(fs.readFileSync(shell, "utf8"))
assert.equal(cfg.version, 1)
const right = cfg.bar.layout.right
assert.deepEqual(right[0], { id: "omarchy.tray", showPercentage: false })
assert.equal(right[1].id, "omarchy.bluetooth")
})
test("restore --install-helper copies a runnable command into config", () => {
const home = fs.mkdtempSync(path.join(os.tmpdir(), "tinytray-home-"))
const result = spawnSync("python3", [restoreScript, "--install-helper"], {
encoding: "utf8",
env: { ...process.env, HOME: home }
})
assert.equal(result.status, 0)
const helper = path.join(home, ".config/omarchy/tinytray-restore")
assert.equal(fs.existsSync(helper), true)
assert.equal(fs.statSync(helper).mode & 0o111, 0o111)
})
test("print-hosted uses defaults when extraWidgets is missing and none when it is empty", () => {
const missing = writeShell({
right: [{ id: "vincentritter.tinytray" }]
})
const missingOut = spawnSync("python3", [restoreScript, "--print-hosted", missing, "vincentritter.tinytray"], {
encoding: "utf8"
})
assert.equal(missingOut.status, 0)
assert.equal(missingOut.stdout, "omarchy.bluetooth\nomarchy.network\nomarchy.monitor\n")
const empty = writeShell({
right: [{ id: "vincentritter.tinytray", extraWidgets: [] }]
})
const emptyOut = spawnSync("python3", [restoreScript, "--print-hosted", empty, "vincentritter.tinytray"], {
encoding: "utf8"
})
assert.equal(emptyOut.status, 0)
assert.equal(emptyOut.stdout, "")
const listed = writeShell({
right: [{ id: "vincentritter.tinytray", extraWidgets: ["omarchy.dropbox"] }]
})
const listedOut = spawnSync("python3", [restoreScript, "--print-hosted", listed, "vincentritter.tinytray"], {
encoding: "utf8"
})
assert.equal(listedOut.status, 0)
assert.equal(listedOut.stdout, "omarchy.dropbox\n")
const absent = writeShell({ right: [{ id: "omarchy.tray" }] })
const absentOut = spawnSync("python3", [restoreScript, "--print-hosted", absent, "vincentritter.tinytray"], {
encoding: "utf8"
})
assert.equal(absentOut.status, 1)
})
test("widget status names tray vs bar", () => {
assert.equal(TrayModel.widgetStatusText(true, false), "In the tray")
assert.equal(TrayModel.widgetStatusText(true, true), "In the tray")
assert.equal(TrayModel.widgetStatusText(false, true), "On the bar")
assert.equal(TrayModel.widgetStatusText(false, false), "Not on the bar")
})
test("app status prefers hidden over pinned", () => {
assert.equal(TrayModel.appStatusText(false, true), "Hidden")
assert.equal(TrayModel.appStatusText(true, true), "Hidden")
assert.equal(TrayModel.appStatusText(true, false), "Pinned")
assert.equal(TrayModel.appStatusText(false, false), "In the drawer")
})
test("hero meta summarizes pinned and drawer counts", () => {
assert.equal(TrayModel.heroMeta(0, 0), "Empty drawer")
assert.equal(TrayModel.heroMeta(1, 0), "1 in the drawer")
assert.equal(TrayModel.heroMeta(3, 0), "3 in the drawer")
assert.equal(TrayModel.heroMeta(0, 1), "1 pinned")
assert.equal(TrayModel.heroMeta(2, 1), "1 pinned · 2 in the drawer")
assert.equal(TrayModel.heroMeta(1, 2), "2 pinned · 1 in the drawer")
})
test("LocalSend tray items are treated as owned by Omarchy", () => {
assert.equal(TrayModel.ownedByOmarchy({ id: "fresh-id-every-launch", title: "LocalSend" }, {}, []), true)
assert.equal(TrayModel.ownedByOmarchy({ id: "another-fresh-id", tooltipTitle: "LocalSend" }, {}, []), true)
})
test("Dropbox native tray icon is owned when the Omarchy widget is on the bar or hosted", () => {
const item = { id: "dropbox-client", title: "Dropbox" }
assert.equal(TrayModel.ownedByOmarchy(item, {}, ["omarchy.dropbox"]), true)
assert.equal(TrayModel.ownedByOmarchy(item, { right: [{ id: "omarchy.dropbox" }] }, []), true)
})
test("Dropbox native tray icon is left alone when the Omarchy widget is not hosted", () => {
const item = { id: "dropbox-client", title: "Dropbox" }
assert.equal(TrayModel.ownedByOmarchy(item, {}, TrayModel.defaultExtraWidgetIds()), false)
})
test("ordinary app icons are not owned by Omarchy", () => {
const item = { id: "1password", title: "1Password" }
assert.equal(TrayModel.ownedByOmarchy(item, {}, ["omarchy.dropbox"]), false)
})
test("item display name prefers title, then tooltip, then the last path segment", () => {
assert.equal(TrayModel.itemDisplayName({ title: "1Password" }), "1Password")
assert.equal(TrayModel.itemDisplayName({ title: " ", tooltipTitle: "Dropbox" }), "Dropbox")
assert.equal(TrayModel.itemDisplayName({ id: "org.kde.StatusNotifierItem/123" }), "123")
assert.equal(TrayModel.itemDisplayName({}), "Unknown")
})
test("chevron id falls back to chevron for missing or unknown values", () => {
assert.equal(TrayModel.chevronIdFromSettings({}), "chevron")
assert.equal(TrayModel.chevronIdFromSettings({ chevron: "caret" }), "caret")
assert.equal(TrayModel.chevronIdFromSettings({ chevron: "dot" }), "dot")
assert.equal(TrayModel.chevronIdFromSettings({ chevron: "nope" }), "chevron")
assert.equal(TrayModel.chevronIdFromSettings(null), "chevron")
})
test("chevron glyph maps known ids and defaults to the chevron mark", () => {
assert.equal(TrayModel.chevronGlyph("chevron"), "\uf053")
assert.equal(TrayModel.chevronGlyph("caret"), "\uf0d9")
assert.equal(TrayModel.chevronGlyph("angle"), "\uf104")
assert.equal(TrayModel.chevronGlyph("arrow"), "\uf060")
assert.equal(TrayModel.chevronGlyph("double"), "\uf100")
assert.equal(TrayModel.chevronGlyph("dot"), "\ueb8a")
assert.equal(TrayModel.chevronGlyph("nope"), "\uf053")
assert.equal(TrayModel.chevronGlyph(""), "\uf053")
})
test("chevron picker keeps its six choices in order", () => {
assert.deepEqual(
TrayModel.chevronOptions().map((option) => option.value),
["chevron", "caret", "angle", "arrow", "double", "dot"]
)
})
test("dot and caret draw as shapes while the other chevrons stay font glyphs", () => {
assert.equal(TrayModel.chevronShape("dot"), "dot")
assert.equal(TrayModel.chevronShape("caret"), "caret")
for (const id of ["chevron", "angle", "arrow", "double"]) {
assert.equal(TrayModel.chevronShape(id), "", id)
}
assert.equal(TrayModel.chevronShape("nope"), "")
assert.equal(TrayModel.chevronShape(TrayModel.chevronIdFromSettings({ chevron: "dot" })), "dot")
})
test("hover expand is on unless settings turn it off", () => {
assert.equal(TrayModel.expandOnHoverFromSettings({}), true)
assert.equal(TrayModel.expandOnHoverFromSettings(null), true)
assert.equal(TrayModel.expandOnHoverFromSettings({ expandOnHover: true }), true)
assert.equal(TrayModel.expandOnHoverFromSettings({ expandOnHover: false }), false)
assert.equal(TrayModel.expandOnHoverFromSettings({ expandOnHover: "false" }), true)
})
test("hovering opens the drawer only when hover expand is on", () => {
assert.equal(TrayModel.expandedAfterHover(true, true, false), true)
assert.equal(TrayModel.expandedAfterHover(true, false, false), false)
assert.equal(TrayModel.expandedAfterHover(true, false, true), true)
})
test("leaving the tray closes the drawer either way", () => {
assert.equal(TrayModel.expandedAfterHover(false, true, true), false)
assert.equal(TrayModel.expandedAfterHover(false, false, true), false)
})
test("chevron clicks open Manage with hover expand and toggle the drawer without it", () => {
const left = 1
const right = 2
const middle = 4
assert.equal(TrayModel.chevronClickAction(left, true), "manage")
assert.equal(TrayModel.chevronClickAction(right, true), "manage")
assert.equal(TrayModel.chevronClickAction(left, false), "drawer")
assert.equal(TrayModel.chevronClickAction(right, false), "manage")
assert.equal(TrayModel.chevronClickAction(middle, true), "")
assert.equal(TrayModel.chevronClickAction(middle, false), "")
})
test("hover opens the drawer after a short wait and closes it after a grace period", () => {
assert.deepEqual(TrayModel.hoverTransition(true, true, false), { expanded: true, delay: TrayModel.HOVER_OPEN_DELAY })
assert.deepEqual(TrayModel.hoverTransition(false, true, true), { expanded: false, delay: TrayModel.HOVER_CLOSE_DELAY })
assert.ok(TrayModel.HOVER_OPEN_DELAY > 0)
assert.ok(TrayModel.HOVER_CLOSE_DELAY > 0)
})
test("hover with nothing to change cancels a pending open or close", () => {
assert.equal(TrayModel.hoverTransition(true, true, true), null)
assert.equal(TrayModel.hoverTransition(false, true, false), null)
assert.equal(TrayModel.hoverTransition(true, false, false), null)
assert.equal(TrayModel.hoverTransition(true, false, true), null)
})
test("leaving a click-opened drawer still closes it after the grace period", () => {
assert.deepEqual(TrayModel.hoverTransition(false, false, true), { expanded: false, delay: TrayModel.HOVER_CLOSE_DELAY })
})
test("only drawer apps that need attention mark the chevron", () => {
const attention = 2
const items = [
{ id: "slack", title: "Slack", status: attention },
{ id: "nm", title: "Network", status: 1 },
{ id: "1password", tooltipTitle: "1Password", status: attention }
]
assert.deepEqual(TrayModel.attentionNames(items, attention), ["Slack", "1Password"])
assert.deepEqual(TrayModel.attentionNames([{ id: "nm", status: 1 }], attention), [])
assert.deepEqual(TrayModel.attentionNames(null, attention), [])
})
test("chevron tooltip names the apps that need attention", () => {
assert.equal(TrayModel.chevronTooltip("Manage Tinytray", []), "Manage Tinytray")
assert.equal(TrayModel.chevronTooltip("Manage Tinytray", ["Slack"]), "Slack needs attention")
assert.equal(TrayModel.chevronTooltip("Manage Tinytray", ["Slack", "1Password"]), "Slack and 1Password need attention")
assert.equal(TrayModel.chevronTooltip("Manage Tinytray", ["Slack", "1Password", "Zoom"]), "Slack, 1Password, and Zoom need attention")
})
test("mergeSettings keeps existing keys and applies updates", () => {
const merged = TrayModel.mergeSettings(
{ pinned: ["a"], extraWidgets: ["omarchy.bluetooth"], chevron: "caret" },
"vincentritter.tinytray",
{ pinned: ["b"], hidden: [] }
)
assert.equal(merged.id, "vincentritter.tinytray")
assert.deepEqual(merged.pinned, ["b"])
assert.deepEqual(merged.hidden, [])
assert.equal(merged.chevron, "caret")
assert.deepEqual(merged.extraWidgets, ["omarchy.bluetooth"])
})
test("mergeSettings deletes keys set to undefined", () => {
const merged = TrayModel.mergeSettings(
{ chevron: "arrow", pinned: ["a"] },
"vincentritter.tinytray",
{ chevron: undefined }
)
assert.equal("chevron" in merged, false)
assert.deepEqual(merged.pinned, ["a"])
})
test("hosted panel open ignores Tinytray manage popup while keeping tray menus open", () => {
const foreign = { foreign: true }
const owner = { id: "tinytray" }
const hosted = { id: "bluetooth" }
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: owner, foreignPopoutMarker: foreign }, owner, false), false)
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: owner, foreignPopoutMarker: foreign }, owner, true), true)
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: hosted, foreignPopoutMarker: foreign }, owner, false), true)
assert.equal(TrayModel.hostedPanelIsOpen({ activePopout: foreign, foreignPopoutMarker: foreign }, owner, true), false)
})
test("firstDescendantClickable finds the first nested pressable widget button", () => {
const nested = button()
const tree = { children: [{ children: [] }, { children: [nested] }] }
assert.equal(TrayModel.firstDescendantClickable(tree), nested)
assert.equal(TrayModel.firstDescendantClickable({ children: [{ children: [] }] }), null)
assert.equal(TrayModel.firstDescendantClickable(null), null)
})
test("hostedWidgetExtent collapses hidden loaded widgets and respects real dimensions", () => {
assert.equal(TrayModel.hostedWidgetExtent({ visible: true, implicitWidth: 54 }, true, 27, "width"), 54)
assert.equal(TrayModel.hostedWidgetExtent({ visible: false, implicitWidth: 54 }, true, 27, "width"), 0)
assert.equal(TrayModel.hostedWidgetExtent({ visible: true, implicitHeight: 36 }, true, 27, "height"), 36)
assert.equal(TrayModel.hostedWidgetExtent(null, true, 27, "width"), 27)
assert.equal(TrayModel.hostedWidgetExtent(null, false, 27, "width"), 0)
})
test("drawerExtentFromContent collapses in dropdown mode and uses measured content otherwise", () => {
assert.equal(TrayModel.drawerExtentFromContent(true, 108, 4, 27, 0), 0)
assert.equal(TrayModel.drawerExtentFromContent(false, 108.2, 4, 27, 0), 109)
assert.equal(TrayModel.drawerExtentFromContent(false, 0, 2, 27, 0), 0)
assert.equal(TrayModel.drawerExtentFromContent(false, null, 3, 27, 2), 85)
})
test("monochrome icons and dropdown drawer default off unless explicitly enabled", () => {
assert.equal(TrayModel.monochromeIconsFromSettings({}), false)
assert.equal(TrayModel.monochromeIconsFromSettings(null), false)
assert.equal(TrayModel.monochromeIconsFromSettings({ monochromeIcons: "true" }), false)
assert.equal(TrayModel.monochromeIconsFromSettings({ monochromeIcons: true }), true)
assert.equal(TrayModel.dropdownDrawerFromSettings({}), false)
assert.equal(TrayModel.dropdownDrawerFromSettings(null), false)
assert.equal(TrayModel.dropdownDrawerFromSettings({ dropdownDrawer: "true" }), false)
assert.equal(TrayModel.dropdownDrawerFromSettings({ dropdownDrawer: true }), true)
})
test("showAttention defaults on unless settings turn it off", () => {
assert.equal(TrayModel.showAttentionFromSettings({}), true)
assert.equal(TrayModel.showAttentionFromSettings(null), true)
assert.equal(TrayModel.showAttentionFromSettings({ expandOnHover: false }), true)
assert.equal(TrayModel.showAttentionFromSettings({ showAttention: true }), true)
assert.equal(TrayModel.showAttentionFromSettings({ showAttention: false }), false)
assert.equal(TrayModel.showAttentionFromSettings({ showAttention: "false" }), true)
})
test("iconEffectMode tints symbolic icons, desaturates monochrome color icons, and leaves color icons alone", () => {
assert.equal(TrayModel.iconEffectMode(true, false), "tint")
assert.equal(TrayModel.iconEffectMode(true, true), "tint")
assert.equal(TrayModel.iconEffectMode(false, true), "desaturate")
assert.equal(TrayModel.iconEffectMode(false, false), "none")
})
test("directional chevrons flip for bar drawer and point toward dropdown on every bar edge", () => {
assert.equal(TrayModel.chevronOpenRotationDelta("dot", false, "top", false), 0)
assert.equal(TrayModel.chevronOpenRotationDelta("dot", false, "top", true), 0)
assert.equal(TrayModel.chevronOpenRotationDelta("chevron", false, "top", false), 180)
assert.equal(TrayModel.chevronOpenRotationDelta("caret", true, "left", false), 180)
assert.equal(TrayModel.chevronOpenRotationDelta("chevron", false, "top", true), -90)
assert.equal(TrayModel.chevronOpenRotationDelta("chevron", false, "bottom", true), 90)
assert.equal(TrayModel.chevronOpenRotationDelta("chevron", true, "left", true), 90)
assert.equal(TrayModel.chevronOpenRotationDelta("chevron", true, "right", true), -90)
})
test("dropdown mode routes left-click to dropdown, right-click to manage, and ignores bar hover", () => {
const left = 1
const right = 2
const middle = 4
assert.equal(TrayModel.chevronClickAction(left, true, true), "dropdown")
assert.equal(TrayModel.chevronClickAction(left, false, true), "dropdown")
assert.equal(TrayModel.chevronClickAction(right, true, true), "manage")
assert.equal(TrayModel.chevronClickAction(middle, true, true), "")
assert.equal(TrayModel.hoverTransition(true, true, false, true), null)
assert.equal(TrayModel.hoverTransition(false, true, true, true), null)
assert.equal(TrayModel.chevronBaseTooltip(true, true), "Open Tinytray. Right-click to manage.")
assert.equal(TrayModel.chevronBaseTooltip(true, false), "Manage Tinytray")
assert.equal(TrayModel.chevronBaseTooltip(false, false), "Open Tinytray. Right-click to manage.")
})
test("dropdown app row clicks activate normal apps, open menu for menu-only or right-click, and secondary-activate on middle", () => {
const left = 1
const right = 2
const middle = 4
assert.equal(TrayModel.dropdownAppClickAction(left, false), "activate")
assert.equal(TrayModel.dropdownAppClickAction(left, true), "menu")
assert.equal(TrayModel.dropdownAppClickAction(right, false), "menu")
assert.equal(TrayModel.dropdownAppClickAction(middle, false), "secondary")
assert.equal(TrayModel.dropdownAppClickAction(8, false), "")
})
test("drawer animation closes faster than it opens", () => {
assert.equal(TrayModel.drawerAnimationDuration(true), TrayModel.DRAWER_OPEN_DURATION)
assert.equal(TrayModel.drawerAnimationDuration(false), TrayModel.DRAWER_CLOSE_DURATION)
assert.ok(TrayModel.DRAWER_OPEN_DURATION > TrayModel.DRAWER_CLOSE_DURATION)
assert.ok(TrayModel.DRAWER_CLOSE_DURATION > 0)
})
test("hostedWidgetAttentionCount prefers badgeCount, then unreadCount, then notificationCount across service and item", () => {
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, service: { badgeCount: 5, unreadCount: 2, notificationCount: 1 } }, null), 5)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, service: { badgeCount: 0, unreadCount: 3, notificationCount: 1 } }, null), 3)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, service: { badgeCount: 0, unreadCount: 0, notificationCount: 4 } }, null), 4)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, badgeCount: 2 }, null), 2)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, unreadCount: 6 }, null), 6)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, notificationCount: 1 }, null), 1)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, service: { unreadCount: -2 }, unreadCount: NaN }, null), 0)
assert.equal(TrayModel.hostedWidgetAttentionCount({ visible: true, service: { badgeCount: "3" } }, null), 0)
assert.equal(TrayModel.hostedWidgetAttentionCount(null, null), 0)
})
test("hostedWidgetAttentionCount and hostedWidgetNeedsAttention ignore hidden widgets", () => {
const withCount = { visible: false, service: { unreadCount: 4 }, authError: true }
const visibleItem = { visible: true, service: { unreadCount: 4 }, needsAttention: true }
const hiddenBtn = { visible: false, active: true, useActiveColor: true }
assert.equal(TrayModel.hostedWidgetAttentionCount(withCount, null), 0)
assert.equal(TrayModel.hostedWidgetNeedsAttention(withCount, null), false)
assert.equal(TrayModel.hostedWidgetAttentionCount(visibleItem, hiddenBtn), 0)
assert.equal(TrayModel.hostedWidgetNeedsAttention(visibleItem, hiddenBtn), false)
})
test("hostedWidgetNeedsAttention detects counts, active buttons with active color, needsAttention, and authError", () => {
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true, service: { unreadCount: 1 } }, null), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true }, { visible: true, active: true, useActiveColor: true }), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true }, { visible: true, active: true }), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true }, { visible: true, active: true, useActiveColor: false }), false)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true }, { visible: true, active: false, useActiveColor: true }), false)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true, needsAttention: true }, null), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true, authError: true }, null), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true, service: { authError: true } }, null), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true, service: { needsAttention: true } }, null), true)
assert.equal(TrayModel.hostedWidgetNeedsAttention({ visible: true }, { visible: true }), false)
assert.equal(TrayModel.hostedWidgetNeedsAttention(null, { visible: true, active: true }), false)
})
test("hostedAttentionLabel and attentionBadgeText format counts and cap badges at 99+", () => {
assert.equal(TrayModel.hostedAttentionLabel("HEY", 3), "HEY (3)")
assert.equal(TrayModel.hostedAttentionLabel("Network", 0), "Network")
assert.equal(TrayModel.hostedAttentionLabel("", 3), "")
assert.equal(TrayModel.attentionBadgeText(0), "")
assert.equal(TrayModel.attentionBadgeText(-1), "")
assert.equal(TrayModel.attentionBadgeText(1), "1")
assert.equal(TrayModel.attentionBadgeText(99), "99")
assert.equal(TrayModel.attentionBadgeText(100), "99+")
assert.equal(TrayModel.attentionBadgeText(250), "99+")
})
test("hostedAttentionNames and combinedAttentionNames feed chevronTooltip for apps and hosted widgets", () => {
const titles = {
"37signals.hey": "HEY",
"vincentritter.photon": "Photon",
"omarchy.network": "Network"
}
const hosts = [
{ widgetId: "37signals.hey", needsAttention: true, attentionCount: 3 },
{ widgetId: "vincentritter.photon", needsAttention: false, attentionCount: 0 },
{ widgetId: "omarchy.network", needsAttention: true, attentionCount: 0 }
]
const hosted = TrayModel.hostedAttentionNames(hosts, (id) => titles[id] || id)
assert.deepEqual(hosted, ["HEY (3)", "Network"])
const combined = TrayModel.combinedAttentionNames(["Slack"], hosted)
assert.deepEqual(combined, ["Slack", "HEY (3)", "Network"])
assert.equal(
TrayModel.chevronTooltip("Manage Tinytray", combined),
"Slack, HEY (3), and Network need attention"
)
assert.equal(
TrayModel.chevronTooltip("Manage Tinytray", TrayModel.combinedAttentionNames([], ["HEY (3)"])),
"HEY (3) needs attention"
)
assert.equal(
TrayModel.chevronTooltip("Manage Tinytray", TrayModel.combinedAttentionNames([], [])),
"Manage Tinytray"
)
})