-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpluginSpec.js
493 lines (412 loc) · 15 KB
/
pluginSpec.js
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
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2024, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
import {
createMouseEvent,
createOpenMct,
renderWhenVisible,
resetApplicationState,
spyOnBuiltins
} from 'utils/testing';
import { nextTick } from 'vue';
import { MODE } from './constants.js';
import TablePlugin from './plugin.js';
class MockDataTransfer {
constructor() {
this.data = {};
}
get types() {
return Object.keys(this.data);
}
setData(format, data) {
this.data[format] = data;
}
getData(format) {
return this.data[format];
}
}
describe('the plugin', () => {
let openmct;
let tablePlugin;
let element;
let child;
let historicalTelemetryProvider;
let originalRouterPath;
let unlistenConfigMutation;
beforeEach((done) => {
openmct = createOpenMct();
// Table Plugin is actually installed by default, but because installing it
// again is harmless it is left here as an example for non-default plugins.
tablePlugin = new TablePlugin();
openmct.install(tablePlugin);
historicalTelemetryProvider = {
request: () => {
return Promise.resolve([]);
}
};
spyOn(openmct.telemetry, 'findRequestProvider').and.returnValue(historicalTelemetryProvider);
element = document.createElement('div');
child = document.createElement('div');
element.appendChild(child);
openmct.time.timeSystem('utc', {
start: 0,
end: 4
});
openmct.types.addType('test-object', {
creatable: true
});
spyOnBuiltins(['requestAnimationFrame']);
window.requestAnimationFrame.and.callFake((callBack) => {
callBack();
});
originalRouterPath = openmct.router.path;
openmct.on('start', done);
openmct.startHeadless();
});
afterEach(() => {
openmct.time.timeSystem('utc', {
start: 0,
end: 1
});
if (unlistenConfigMutation) {
unlistenConfigMutation();
}
return resetApplicationState(openmct);
});
describe('defines a table object', function () {
it('that is creatable', () => {
let tableType = openmct.types.get('table');
expect(tableType.definition.creatable).toBe(true);
});
});
it('provides a table view for objects with telemetry', () => {
const testTelemetryObject = {
id: 'test-object',
type: 'test-object',
telemetry: {
values: [
{
key: 'some-key'
}
]
}
};
const applicableViews = openmct.objectViews.get(testTelemetryObject, []);
let tableView = applicableViews.find((viewProvider) => viewProvider.key === 'table');
expect(tableView).toBeDefined();
});
describe('The table view', () => {
let testTelemetryObject;
let applicableViews;
let tableViewProvider;
let tableView;
let tableInstance;
let mockClock;
let telemetryCallback;
beforeEach(async () => {
openmct.time.timeSystem('utc', {
start: 0,
end: 10
});
mockClock = jasmine.createSpyObj('clock', ['on', 'off', 'currentValue']);
mockClock.key = 'mockClock';
mockClock.currentValue.and.returnValue(1);
openmct.time.addClock(mockClock);
openmct.time.clock('mockClock', {
start: 0,
end: 10
});
testTelemetryObject = {
identifier: {
namespace: '',
key: 'test-object'
},
type: 'test-object',
name: 'Test Object',
telemetry: {
values: [
{
key: 'utc',
format: 'utc',
name: 'Time',
hints: {
domain: 1
}
},
{
key: 'some-key',
name: 'Some attribute',
hints: {
range: 1
}
},
{
key: 'some-other-key',
name: 'Another attribute',
hints: {
range: 2
}
}
]
},
configuration: {
hiddenColumns: {
name: false,
utc: false,
'some-key': false,
'some-other-key': false
},
persistModeChange: true,
rowLimit: 50,
telemetryMode: MODE.PERFORMANCE
}
};
const testTelemetry = [
{
utc: 1,
'some-key': 'some-value 1',
'some-other-key': 'some-other-value 1'
},
{
utc: 2,
'some-key': 'some-value 2',
'some-other-key': 'some-other-value 2'
},
{
utc: 3,
'some-key': 'some-value 3',
'some-other-key': 'some-other-value 3'
}
];
historicalTelemetryProvider.request = () => {
return Promise.resolve(testTelemetry);
};
const realtimeTelemetryProvider = {
supportsSubscribe: () => true,
subscribe: (domainObject, passedCallback) => {
telemetryCallback = passedCallback;
return Promise.resolve(() => {});
}
};
spyOn(openmct.telemetry, 'findSubscriptionProvider').and.returnValue(
realtimeTelemetryProvider
);
openmct.router.path = [testTelemetryObject];
applicableViews = openmct.objectViews.get(testTelemetryObject, []);
tableViewProvider = applicableViews.find((viewProvider) => viewProvider.key === 'table');
tableView = tableViewProvider.view(testTelemetryObject, [testTelemetryObject]);
tableView.show(child, true, { renderWhenVisible });
tableInstance = tableView.getTable();
await nextTick();
});
afterEach(() => {
openmct.router.path = originalRouterPath;
openmct.time.setClock('local');
});
it('Shows no progress bar initially', () => {
let progressBar = element.querySelector('.c-progress-bar');
expect(tableInstance.outstandingRequests).toBe(0);
expect(progressBar).toBeNull();
});
it('Shows a progress bar while making requests', async () => {
tableInstance.incrementOutstandingRequests();
await nextTick();
let progressBar = element.querySelector('.c-progress-bar');
expect(tableInstance.outstandingRequests).toBe(1);
expect(progressBar).not.toBeNull();
});
it('Renders a row for every telemetry datum returned', async () => {
let rows = element.querySelectorAll('table.c-telemetry-table__body tr');
await nextTick();
expect(rows.length).toBe(3);
});
it('Adds a row in place when updating with existing telemetry', async () => {
let rows = element.querySelectorAll('table.c-telemetry-table__body tr');
await nextTick();
expect(rows.length).toBe(3);
// fire some telemetry
const newTelemetry = {
utc: 2,
'some-key': 'some-value 2',
'some-other-key': 'spacecraft'
};
spyOn(tableInstance.tableRows, 'getInPlaceUpdateIndex').and.returnValue(1);
spyOn(tableInstance.tableRows, 'updateRowInPlace').and.callThrough();
telemetryCallback(newTelemetry);
expect(tableInstance.tableRows.updateRowInPlace.calls.count()).toBeGreaterThan(0);
});
it('Renders a column for every item in telemetry metadata', () => {
let headers = element.querySelectorAll('span.c-telemetry-table__headers__label');
expect(headers.length).toBe(4);
expect(headers[0].innerText).toBe('Name');
expect(headers[1].innerText).toBe('Time');
expect(headers[2].innerText).toBe('Some attribute');
expect(headers[3].innerText).toBe('Another attribute');
});
it('Supports column reordering via drag and drop', async () => {
let columns = element.querySelectorAll('tr.c-telemetry-table__headers__labels th');
let fromColumn = columns[0];
let toColumn = columns[1];
let fromColumnText = fromColumn.querySelector(
'span.c-telemetry-table__headers__label'
).innerText;
let toColumnText = toColumn.querySelector('span.c-telemetry-table__headers__label').innerText;
let dragStartEvent = createMouseEvent('dragstart');
let dragOverEvent = createMouseEvent('dragover');
let dropEvent = createMouseEvent('drop');
dragStartEvent.dataTransfer =
dragOverEvent.dataTransfer =
dropEvent.dataTransfer =
new MockDataTransfer();
fromColumn.dispatchEvent(dragStartEvent);
toColumn.dispatchEvent(dragOverEvent);
toColumn.dispatchEvent(dropEvent);
await nextTick();
columns = element.querySelectorAll('tr.c-telemetry-table__headers__labels th');
let firstColumn = columns[0];
let secondColumn = columns[1];
let firstColumnText = firstColumn.querySelector(
'span.c-telemetry-table__headers__label'
).innerText;
let secondColumnText = secondColumn.querySelector(
'span.c-telemetry-table__headers__label'
).innerText;
expect(fromColumnText).not.toEqual(firstColumnText);
expect(fromColumnText).toEqual(secondColumnText);
expect(toColumnText).not.toEqual(secondColumnText);
expect(toColumnText).toEqual(firstColumnText);
});
it('displays the correct number of column headers when the configuration is mutated', async () => {
const tableInstanceConfiguration = tableInstance.domainObject.configuration;
tableInstanceConfiguration.hiddenColumns['some-key'] = true;
unlistenConfigMutation = tableInstance.openmct.objects.mutate(
tableInstance.domainObject,
'configuration',
tableInstanceConfiguration
);
await nextTick();
let tableHeaderElements = element.querySelectorAll('.c-telemetry-table__headers__label');
expect(tableHeaderElements.length).toEqual(3);
tableInstanceConfiguration.hiddenColumns['some-key'] = false;
unlistenConfigMutation = tableInstance.openmct.objects.mutate(
tableInstance.domainObject,
'configuration',
tableInstanceConfiguration
);
await nextTick();
tableHeaderElements = element.querySelectorAll('.c-telemetry-table__headers__label');
expect(tableHeaderElements.length).toEqual(4);
});
it('displays the correct number of table cells in a row when the configuration is mutated', async () => {
const tableInstanceConfiguration = tableInstance.domainObject.configuration;
tableInstanceConfiguration.hiddenColumns['some-key'] = true;
unlistenConfigMutation = tableInstance.openmct.objects.mutate(
tableInstance.domainObject,
'configuration',
tableInstanceConfiguration
);
await nextTick();
let tableRowCells = element.querySelectorAll(
'table.c-telemetry-table__body > tbody > tr:first-child td'
);
expect(tableRowCells.length).toEqual(3);
tableInstanceConfiguration.hiddenColumns['some-key'] = false;
unlistenConfigMutation = tableInstance.openmct.objects.mutate(
tableInstance.domainObject,
'configuration',
tableInstanceConfiguration
);
await nextTick();
tableRowCells = element.querySelectorAll(
'table.c-telemetry-table__body > tbody > tr:first-child td'
);
expect(tableRowCells.length).toEqual(4);
});
it('Pauses the table when a row is marked', async () => {
let firstRow = element.querySelector('table.c-telemetry-table__body > tbody > tr');
let clickEvent = createMouseEvent('click');
// Mark a row
firstRow.dispatchEvent(clickEvent);
await nextTick();
// Verify table is paused
expect(element.querySelector('div.c-table.is-paused')).not.toBeNull();
});
it('Unpauses the table on user bounds change', async () => {
let firstRow = element.querySelector('table.c-telemetry-table__body > tbody > tr');
let clickEvent = createMouseEvent('click');
// Mark a row
firstRow.dispatchEvent(clickEvent);
await nextTick();
// Verify table is paused
expect(element.querySelector('div.c-table.is-paused')).not.toBeNull();
const currentBounds = openmct.time.bounds();
await nextTick();
const newBounds = {
start: currentBounds.start,
end: currentBounds.end - 3
};
// Manually change the time bounds
openmct.time.bounds(newBounds);
await nextTick();
// Verify table is no longer paused
expect(element.querySelector('div.c-table.is-paused')).toBeNull();
});
it('Unpauses the table on user bounds change if paused by button', async () => {
const viewContext = tableView.getViewContext();
// Pause by button
viewContext.togglePauseByButton();
await nextTick();
// Verify table is paused
expect(element.querySelector('div.c-table.is-paused')).not.toBeNull();
const currentBounds = openmct.time.bounds();
await nextTick();
const newBounds = {
start: currentBounds.start,
end: currentBounds.end - 1
};
// Manually change the time bounds
openmct.time.bounds(newBounds);
await nextTick();
// Verify table is no longer paused
expect(element.querySelector('div.c-table.is-paused')).toBeNull();
});
it('Does not unpause the table on tick', async () => {
const viewContext = tableView.getViewContext();
// Pause by button
viewContext.togglePauseByButton();
await nextTick();
// Verify table displays the correct number of rows
let tableRows = element.querySelectorAll('table.c-telemetry-table__body > tbody > tr');
expect(tableRows.length).toEqual(3);
// Verify table is paused
expect(element.querySelector('div.c-table.is-paused')).not.toBeNull();
// Tick the clock
openmct.time.tick(1);
await nextTick();
// Verify table is still paused
expect(element.querySelector('div.c-table.is-paused')).not.toBeNull();
await nextTick();
// Verify table displays the correct number of rows
tableRows = element.querySelectorAll('table.c-telemetry-table__body > tbody > tr');
expect(tableRows.length).toEqual(3);
});
});
});