github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/clients-list-test.js (about) 1 import { currentURL } from 'ember-native-dom-helpers'; 2 import { test } from 'qunit'; 3 import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance'; 4 import ClientsList from 'nomad-ui/tests/pages/clients/list'; 5 6 function minimumSetup() { 7 server.createList('node', 1); 8 server.createList('agent', 1); 9 } 10 11 moduleForAcceptance('Acceptance | clients list'); 12 13 test('/clients should list one page of clients', function(assert) { 14 // Make sure to make more nodes than 1 page to assert that pagination is working 15 const nodesCount = 10; 16 const pageSize = 8; 17 18 server.createList('node', nodesCount); 19 server.createList('agent', 1); 20 21 ClientsList.visit(); 22 23 andThen(() => { 24 assert.equal(ClientsList.nodes.length, pageSize); 25 assert.ok(ClientsList.hasPagination, 'Pagination found on the page'); 26 27 const sortedNodes = server.db.nodes.sortBy('modifyIndex').reverse(); 28 29 ClientsList.nodes.forEach((node, index) => { 30 assert.equal(node.id, sortedNodes[index].id.split('-')[0], 'Clients are ordered'); 31 }); 32 }); 33 }); 34 35 test('each client record should show high-level info of the client', function(assert) { 36 minimumSetup(); 37 const node = server.db.nodes[0]; 38 39 ClientsList.visit(); 40 41 andThen(() => { 42 const nodeRow = ClientsList.nodes.objectAt(0); 43 const allocations = server.db.allocations.where({ nodeId: node.id }); 44 45 assert.equal(nodeRow.id, node.id.split('-')[0], 'ID'); 46 assert.equal(nodeRow.name, node.name, 'Name'); 47 assert.equal(nodeRow.status, node.status, 'Status'); 48 assert.equal(nodeRow.drain, node.drain + '', 'Draining'); 49 assert.equal(nodeRow.eligibility, node.schedulingEligibility, 'Eligibility'); 50 assert.equal(nodeRow.address, node.httpAddr); 51 assert.equal(nodeRow.datacenter, node.datacenter, 'Datacenter'); 52 assert.equal(nodeRow.allocations, allocations.length, '# Allocations'); 53 }); 54 }); 55 56 test('each client should link to the client detail page', function(assert) { 57 minimumSetup(); 58 const node = server.db.nodes[0]; 59 60 ClientsList.visit(); 61 62 andThen(() => { 63 ClientsList.nodes.objectAt(0).clickRow(); 64 }); 65 66 andThen(() => { 67 assert.equal(currentURL(), `/clients/${node.id}`); 68 }); 69 }); 70 71 test('when there are no clients, there is an empty message', function(assert) { 72 server.createList('agent', 1); 73 74 ClientsList.visit(); 75 76 andThen(() => { 77 assert.ok(ClientsList.isEmpty); 78 assert.equal(ClientsList.empty.headline, 'No Clients'); 79 }); 80 }); 81 82 test('when there are clients, but no matches for a search term, there is an empty message', function(assert) { 83 server.createList('agent', 1); 84 server.create('node', { name: 'node' }); 85 86 ClientsList.visit(); 87 88 andThen(() => { 89 ClientsList.search('client'); 90 }); 91 92 andThen(() => { 93 assert.ok(ClientsList.isEmpty); 94 assert.equal(ClientsList.empty.headline, 'No Matches'); 95 }); 96 }); 97 98 test('when accessing clients is forbidden, show a message with a link to the tokens page', function(assert) { 99 server.create('agent'); 100 server.create('node', { name: 'node' }); 101 server.pretender.get('/v1/nodes', () => [403, {}, null]); 102 103 ClientsList.visit(); 104 105 andThen(() => { 106 assert.equal(ClientsList.error.title, 'Not Authorized'); 107 }); 108 109 andThen(() => { 110 ClientsList.error.seekHelp(); 111 }); 112 113 andThen(() => { 114 assert.equal(currentURL(), '/settings/tokens'); 115 }); 116 });