-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathprune-deleted-monitors.test.ts
More file actions
108 lines (88 loc) · 3.53 KB
/
Copy pathprune-deleted-monitors.test.ts
File metadata and controls
108 lines (88 loc) · 3.53 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
/**
* Tests for pruning references to monitors ZoneMinder no longer has
* (refs #323, #324).
*/
import { describe, it, expect } from 'vitest';
import {
pruneProfileSettingsMonitorIds,
pruneWidgetMonitorIds,
} from '../prune-deleted-monitors';
import { DEFAULT_MONTAGE_GROUP_LAYOUT } from '../../../stores/settings';
import type { DashboardWidget } from '../../../stores/dashboard';
const KNOWN = new Set(['1', '2']);
function montageBucket(overrides: Partial<typeof DEFAULT_MONTAGE_GROUP_LAYOUT>) {
return { ...DEFAULT_MONTAGE_GROUP_LAYOUT, ...overrides };
}
function monitorWidget(settings: DashboardWidget['settings']): DashboardWidget {
return {
id: 'w1',
type: 'monitor',
settings,
layout: { i: 'w1', x: 0, y: 0, w: 4, h: 4 },
};
}
describe('pruneProfileSettingsMonitorIds', () => {
it('drops a hidden monitor that no longer exists so the hidden count matches reality', () => {
const patch = pruneProfileSettingsMonitorIds({ excludedMonitorIds: ['1', '99'] }, KNOWN);
expect(patch?.excludedMonitorIds).toEqual(['1']);
});
it('keeps every id when all of them still exist', () => {
expect(pruneProfileSettingsMonitorIds({ excludedMonitorIds: ['1', '2'] }, KNOWN)).toBeNull();
});
it('drops deleted monitors from a montage group without touching the survivors', () => {
const patch = pruneProfileSettingsMonitorIds(
{
montageByGroup: {
all: montageBucket({
hiddenMonitorIds: ['2', '99'],
workingLayout: [
{ i: '1', x: 0, y: 0, w: 6, h: 6 },
{ i: '99', x: 6, y: 0, w: 6, h: 6 },
],
}),
},
},
KNOWN
);
expect(patch?.montageByGroup?.all.hiddenMonitorIds).toEqual(['2']);
expect(patch?.montageByGroup?.all.workingLayout.map((l) => l.i)).toEqual(['1']);
});
it('leaves named saved layouts alone: they are user artifacts, not live state', () => {
const saved = [
{ name: 'Front', layout: [{ i: '99', x: 0, y: 0, w: 6, h: 6 }], displayCols: 2 },
];
const patch = pruneProfileSettingsMonitorIds(
{ montageByGroup: { all: montageBucket({ hiddenMonitorIds: ['99'], savedLayouts: saved }) } },
KNOWN
);
expect(patch?.montageByGroup?.all.savedLayouts).toEqual(saved);
});
it('reports no change when a montage group holds only live monitors', () => {
const patch = pruneProfileSettingsMonitorIds(
{ montageByGroup: { all: montageBucket({ hiddenMonitorIds: ['1'] }) } },
KNOWN
);
expect(patch).toBeNull();
});
});
describe('pruneWidgetMonitorIds', () => {
it('drops a deleted monitor from a widget display order', () => {
const updates = pruneWidgetMonitorIds([monitorWidget({ monitorIds: ['1', '99', '2'] })], KNOWN);
expect(updates).toEqual([{ id: 'w1', settings: { monitorIds: ['1', '2'] } }]);
});
it('clears a single-monitor widget whose monitor is gone', () => {
const updates = pruneWidgetMonitorIds([monitorWidget({ monitorId: '99' })], KNOWN);
expect(updates[0].settings.monitorId).toBeUndefined();
});
it('leaves widgets that reference only live monitors untouched', () => {
expect(pruneWidgetMonitorIds([monitorWidget({ monitorIds: ['1'], monitorId: '2' })], KNOWN))
.toEqual([]);
});
it('keeps the rest of a widget settings object intact', () => {
const updates = pruneWidgetMonitorIds(
[monitorWidget({ monitorIds: ['99'], feedFit: 'cover', eventCount: 5 })],
KNOWN
);
expect(updates[0].settings).toEqual({ monitorIds: [], feedFit: 'cover', eventCount: 5 });
});
});