-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathclients-list-test.js
More file actions
554 lines (471 loc) · 16.4 KB
/
clients-list-test.js
File metadata and controls
554 lines (471 loc) · 16.4 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
/**
* Copyright IBM Corp. 2015, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint-disable qunit/require-expect */
import { currentURL, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import pageSizeSelect from './behaviors/page-size-select';
import ClientsList from 'nomad-ui/tests/pages/clients/list';
import faker from 'nomad-ui/mirage/faker';
module('Acceptance | clients list', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(function () {
window.localStorage.clear();
server.createList('node-pool', 3);
});
test('it passes an accessibility audit', async function (assert) {
const nodesCount = ClientsList.pageSize + 1;
server.createList('node', nodesCount);
server.createList('agent', 1);
await ClientsList.visit();
await a11yAudit(assert);
});
test('/clients should list one page of clients', async function (assert) {
faker.seed(1);
// Make sure to make more nodes than 1 page to assert that pagination is working
const nodesCount = ClientsList.pageSize + 1;
server.createList('node', nodesCount);
server.createList('agent', 1);
await ClientsList.visit();
assert.equal(ClientsList.nodes.length, ClientsList.pageSize);
assert.ok(ClientsList.hasPagination, 'Pagination found on the page');
const sortedNodes = server.db.nodes.sortBy('modifyIndex').reverse();
ClientsList.nodes.forEach((node, index) => {
assert.equal(
node.id,
sortedNodes[index].id.split('-')[0],
'Clients are ordered'
);
});
assert.ok(document.title.includes('Clients'));
});
test('each client record should show high-level info of the client', async function (assert) {
const node = server.create('node', 'draining', {
status: 'ready',
});
server.createList('agent', 1);
await ClientsList.visit();
const nodeRow = ClientsList.nodes.objectAt(0);
const allocations = server.db.allocations.where({ nodeId: node.id });
assert.equal(nodeRow.id, node.id.split('-')[0], 'ID');
assert.equal(nodeRow.name, node.name, 'Name');
assert.equal(nodeRow.nodePool, node.nodePool, 'Node Pool');
assert.equal(
nodeRow.compositeStatus.text,
'Ready Ineligible Draining',
'Combined status, draining, and eligbility'
);
assert.equal(nodeRow.address, node.httpAddr);
assert.equal(nodeRow.datacenter, node.datacenter, 'Datacenter');
assert.equal(nodeRow.version, node.version, 'Version');
assert.equal(nodeRow.allocations, allocations.length, '# Allocations');
});
test('each client record should show running allocations', async function (assert) {
server.createList('agent', 1);
const node = server.create('node', {
modifyIndex: 4,
status: 'ready',
schedulingEligibility: 'eligible',
drain: false,
});
server.create('job', { createAllocations: false });
const running = server.createList('allocation', 2, {
clientStatus: 'running',
});
server.createList('allocation', 3, { clientStatus: 'pending' });
server.createList('allocation', 10, { clientStatus: 'complete' });
await ClientsList.visit();
const nodeRow = ClientsList.nodes.objectAt(0);
assert.equal(nodeRow.id, node.id.split('-')[0], 'ID');
assert.equal(
nodeRow.compositeStatus.text,
'Ready Eligible Not Draining',
'Combined status, draining, and eligbility'
);
assert.equal(nodeRow.allocations, running.length, '# Allocations');
});
test('client status, draining, and eligibility are combined into one column that stays sorted on status', async function (assert) {
server.createList('agent', 1);
server.create('node', {
modifyIndex: 5,
status: 'ready',
schedulingEligibility: 'eligible',
drain: false,
});
server.create('node', {
modifyIndex: 4,
status: 'initializing',
schedulingEligibility: 'eligible',
drain: false,
});
server.create('node', {
modifyIndex: 3,
status: 'down',
schedulingEligibility: 'eligible',
drain: false,
});
server.create('node', {
modifyIndex: 2,
status: 'down',
schedulingEligibility: 'ineligible',
drain: false,
});
server.create('node', {
modifyIndex: 1,
status: 'ready',
schedulingEligibility: 'ineligible',
drain: false,
});
server.create('node', 'draining', {
schedulingEligibility: 'eligible',
modifyIndex: 0,
status: 'ready',
});
await ClientsList.visit();
assert.equal(
ClientsList.nodes[0].compositeStatus.text,
'Ready Eligible Not Draining'
);
assert.equal(
ClientsList.nodes[1].compositeStatus.text,
'Initializing Eligible Not Draining'
);
assert.equal(
ClientsList.nodes[2].compositeStatus.text,
'Down Eligible Not Draining'
);
assert.equal(
ClientsList.nodes[3].compositeStatus.text,
'Down Ineligible Not Draining'
);
assert.equal(
ClientsList.nodes[4].compositeStatus.text,
'Ready Ineligible Not Draining'
);
assert.equal(
ClientsList.nodes[5].compositeStatus.text,
'Ready Eligible Draining'
);
await ClientsList.sortBy('status');
assert.deepEqual(
ClientsList.nodes.map((n) => n.compositeStatus.text),
[
'Ready Eligible Draining',
'Ready Ineligible Not Draining',
'Ready Eligible Not Draining',
'Initializing Eligible Not Draining',
'Down Ineligible Not Draining',
'Down Eligible Not Draining',
],
'Nodes are sorted only by status, and otherwise default to modifyIndex'
);
// Simulate a client state change arriving through polling
let discoClient = this.owner
.lookup('service:store')
.peekAll('node')
.findBy('modifyIndex', 5);
discoClient.set('status', 'disconnected');
await settled();
assert.deepEqual(
ClientsList.nodes.map((n) => n.compositeStatus.text),
[
'Ready Eligible Draining',
'Ready Ineligible Not Draining',
'Disconnected Eligible Not Draining',
'Initializing Eligible Not Draining',
'Down Ineligible Not Draining',
'Down Eligible Not Draining',
]
);
});
test('each client should link to the client detail page', async function (assert) {
server.createList('node', 1);
server.createList('agent', 1);
const node = server.db.nodes[0];
await ClientsList.visit();
await ClientsList.nodes.objectAt(0).clickRow();
assert.equal(currentURL(), `/clients/${node.id}`);
});
test('when there are no clients, there is an empty message', async function (assert) {
faker.seed(1);
server.createList('agent', 1);
await ClientsList.visit();
assert.ok(ClientsList.isEmpty);
assert.equal(ClientsList.empty.headline, 'No Clients');
});
test('when there are clients, but no matches for a search term, there is an empty message', async function (assert) {
server.createList('agent', 1);
server.create('node', { name: 'node' });
await ClientsList.visit();
await ClientsList.search('client');
assert.ok(ClientsList.isEmpty);
assert.equal(ClientsList.empty.headline, 'No Matches');
});
test('when accessing clients is forbidden, show a message with a link to the tokens page', async function (assert) {
server.create('agent');
server.create('node', { name: 'node' });
server.pretender.get('/v1/nodes', () => [403, {}, null]);
await ClientsList.visit();
assert.equal(ClientsList.error.title, 'Not Authorized');
await ClientsList.error.seekHelp();
assert.equal(currentURL(), '/settings/tokens');
});
pageSizeSelect({
resourceName: 'client',
pageObject: ClientsList,
pageObjectList: ClientsList.nodes,
async setup() {
server.createList('node', ClientsList.pageSize);
server.createList('agent', 1);
await ClientsList.visit();
},
});
testFacet('Class', {
facet: ClientsList.facets.class,
paramName: 'class',
expectedOptions(nodes) {
return Array.from(new Set(nodes.mapBy('nodeClass'))).sort();
},
async beforeEach() {
server.create('agent');
server.createList('node', 2, { nodeClass: 'nc-one' });
server.createList('node', 2, { nodeClass: 'nc-two' });
server.createList('node', 2, { nodeClass: 'nc-three' });
await ClientsList.visit();
},
filter: (node, selection) => selection.includes(node.nodeClass),
});
testFacet('State', {
facet: ClientsList.facets.state,
paramName: 'state',
expectedOptions: [
'initializing',
'ready',
'down',
'disconnected',
'eligible',
'ineligible',
'draining',
'not draining',
],
async beforeEach() {
server.create('agent');
server.createList('node', 2, { status: 'initializing' });
server.createList('node', 2, { status: 'ready' });
server.createList('node', 2, { status: 'down' });
server.createList('node', 2, {
schedulingEligibility: 'eligible',
drain: false,
});
server.createList('node', 2, {
schedulingEligibility: 'ineligible',
drain: false,
});
server.createList('node', 2, {
schedulingEligibility: 'ineligible',
drain: true,
});
await ClientsList.visit();
},
filter: (node, selection) => {
if (selection.includes('draining') && !node.drain) return false;
if (
selection.includes('ineligible') &&
node.schedulingEligibility === 'eligible'
)
return false;
return !selection.includes(node.status);
},
});
testFacet('Node Pools', {
facet: ClientsList.facets.nodePools,
paramName: 'nodePool',
expectedOptions() {
return server.db.nodePools
.filter((p) => p.name !== 'all') // The node pool 'all' should not be a filter.
.map((p) => p.name);
},
async beforeEach() {
server.create('agent');
server.create('node-pool', { name: 'all' });
server.create('node-pool', { name: 'default' });
server.createList('node-pool', 10);
// Make sure each node pool has at least one node.
server.db.nodePools.forEach((p) => {
server.createList('node', 2, { nodePool: p.name });
});
await ClientsList.visit();
},
filter: (node, selection) => selection.includes(node.nodePool),
});
testFacet('Datacenters', {
facet: ClientsList.facets.datacenter,
paramName: 'dc',
expectedOptions(nodes) {
return Array.from(new Set(nodes.mapBy('datacenter'))).sort();
},
async beforeEach() {
server.create('agent');
server.createList('node', 2, { datacenter: 'pdx-1' });
server.createList('node', 2, { datacenter: 'nyc-1' });
server.createList('node', 2, { datacenter: 'ams-1' });
await ClientsList.visit();
},
filter: (node, selection) => selection.includes(node.datacenter),
});
testFacet('Versions', {
facet: ClientsList.facets.version,
paramName: 'version',
expectedOptions(nodes) {
return Array.from(new Set(nodes.mapBy('version'))).sort();
},
async beforeEach() {
server.create('agent');
server.createList('node', 2, { version: '0.12.0' });
server.createList('node', 2, { version: '1.1.0-beta1' });
server.createList('node', 2, { version: '1.2.0+ent' });
await ClientsList.visit();
},
filter: (node, selection) => selection.includes(node.version),
});
testFacet('Volumes', {
facet: ClientsList.facets.volume,
paramName: 'volume',
expectedOptions(nodes) {
const flatten = (acc, val) => acc.concat(Object.keys(val));
return Array.from(
new Set(nodes.mapBy('hostVolumes').reduce(flatten, []))
);
},
async beforeEach() {
server.create('agent');
server.createList('node', 2, { hostVolumes: { One: { Name: 'One' } } });
server.createList('node', 2, {
hostVolumes: { One: { Name: 'One' }, Two: { Name: 'Two' } },
});
server.createList('node', 2, { hostVolumes: { Two: { Name: 'Two' } } });
await ClientsList.visit();
},
filter: (node, selection) =>
Object.keys(node.hostVolumes).find((volume) =>
selection.includes(volume)
),
});
test('when the facet selections result in no matches, the empty state states why', async function (assert) {
server.create('agent');
server.createList('node', 2, { status: 'ready' });
await ClientsList.visit();
await ClientsList.facets.state.toggle();
await ClientsList.facets.state.options.objectAt(1).toggle();
assert.ok(ClientsList.isEmpty, 'There is an empty message');
assert.equal(
ClientsList.empty.headline,
'No Matches',
'The message is appropriate'
);
});
test('the clients list is immediately filtered based on query params', async function (assert) {
server.create('agent');
server.create('node', { nodeClass: 'omg-large' });
server.create('node', { nodeClass: 'wtf-tiny' });
await ClientsList.visit({ class: JSON.stringify(['wtf-tiny']) });
assert.equal(
ClientsList.nodes.length,
1,
'Only one client shown due to query param'
);
});
function testFacet(
label,
{ facet, paramName, beforeEach, filter, expectedOptions }
) {
test(`the ${label} facet has the correct options`, async function (assert) {
await beforeEach();
await facet.toggle();
let expectation;
if (typeof expectedOptions === 'function') {
expectation = expectedOptions(server.db.nodes);
} else {
expectation = expectedOptions;
}
assert.deepEqual(
facet.options.map((option) => {
return option.key.trim();
}),
expectation,
'Options for facet are as expected'
);
});
test(`the ${label} facet filters the nodes list by ${label}`, async function (assert) {
let option;
await beforeEach();
await facet.toggle();
option = facet.options.objectAt(0);
await option.toggle();
const selection = [option.key];
const expectedNodes = server.db.nodes
.filter((node) => filter(node, selection))
.sortBy('modifyIndex')
.reverse();
ClientsList.nodes.forEach((node, index) => {
assert.equal(
node.id,
expectedNodes[index].id.split('-')[0],
`Node at ${index} is ${expectedNodes[index].id}`
);
});
});
test(`selecting multiple options in the ${label} facet results in a broader search`, async function (assert) {
const selection = [];
await beforeEach();
await facet.toggle();
const option1 = facet.options.objectAt(0);
const option2 = facet.options.objectAt(1);
await option1.toggle();
selection.push(option1.key);
await option2.toggle();
selection.push(option2.key);
const expectedNodes = server.db.nodes
.filter((node) => filter(node, selection))
.sortBy('modifyIndex')
.reverse();
ClientsList.nodes.forEach((node, index) => {
assert.equal(
node.id,
expectedNodes[index].id.split('-')[0],
`Node at ${index} is ${expectedNodes[index].id}`
);
});
});
test(`selecting options in the ${label} facet updates the ${paramName} query param`, async function (assert) {
const selection = [];
await beforeEach();
await facet.toggle();
const option1 = facet.options.objectAt(0);
const option2 = facet.options.objectAt(1);
await option1.toggle();
selection.push(option1.key);
await option2.toggle();
selection.push(option2.key);
// State is different from the other facets, in that it is an "exclusive" filter, whete others are "inclusive".
// Because of this, it doesn't pass "state" as a stringified-array query param; rather, exclusion is indicated
// for each option with a "${optionName}=false" query param.
const stateString = `/clients?${selection
.map((option) => `state_${option}=false`)
.join('&')}`;
const nonStateString = `/clients?${paramName}=${encodeURIComponent(
JSON.stringify(selection)
)}`;
assert.equal(
currentURL(),
paramName === 'state' ? stateString : nonStateString,
'URL has the correct query param key and value'
);
});
}
});