2017-09-30 01:33:57 +00:00
|
|
|
import { click, find, findAll, currentURL, visit } from 'ember-native-dom-helpers';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
|
|
|
import { findLeader } from '../../mirage/config';
|
|
|
|
import ipParts from 'nomad-ui/utils/ip-parts';
|
|
|
|
|
|
|
|
function minimumSetup() {
|
|
|
|
server.createList('node', 1);
|
|
|
|
server.createList('agent', 1);
|
|
|
|
}
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
moduleForAcceptance('Acceptance | clients list');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients should list one page of clients', function(assert) {
|
2017-09-19 14:47:10 +00:00
|
|
|
// Make sure to make more nodes than 1 page to assert that pagination is working
|
|
|
|
const nodesCount = 10;
|
|
|
|
const pageSize = 8;
|
|
|
|
|
|
|
|
server.createList('node', nodesCount);
|
|
|
|
server.createList('agent', 1);
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(findAll('[data-test-client-node-row]').length, pageSize);
|
|
|
|
assert.ok(find('[data-test-pagination]'), 'Pagination found on the page');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const sortedNodes = server.db.nodes.sortBy('modifyIndex').reverse();
|
|
|
|
|
|
|
|
for (var nodeNumber = 0; nodeNumber < pageSize; nodeNumber++) {
|
2018-01-05 20:59:36 +00:00
|
|
|
const nodeRow = findAll('[data-test-client-node-row]')[nodeNumber];
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
nodeRow.querySelector('[data-test-client-id]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sortedNodes[nodeNumber].id.split('-')[0],
|
2017-10-28 01:23:41 +00:00
|
|
|
'Clients are ordered'
|
2017-09-19 14:47:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each client record should show high-level info of the client', function(assert) {
|
|
|
|
minimumSetup();
|
|
|
|
const node = server.db.nodes[0];
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
const nodeRow = find('[data-test-client-node-row]');
|
2017-09-19 14:47:10 +00:00
|
|
|
const allocations = server.db.allocations.where({ nodeId: node.id });
|
|
|
|
const { address, port } = ipParts(node.httpAddr);
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-id]').textContent.trim(),
|
|
|
|
node.id.split('-')[0],
|
|
|
|
'ID'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-name]').textContent.trim(),
|
|
|
|
node.name,
|
|
|
|
'Name'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-status]').textContent.trim(),
|
|
|
|
node.status,
|
|
|
|
'Status'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-address]').textContent.trim(),
|
|
|
|
address,
|
|
|
|
'Address'
|
|
|
|
);
|
|
|
|
assert.equal(nodeRow.querySelector('[data-test-client-port]').textContent.trim(), port, 'Port');
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-datacenter]').textContent.trim(),
|
|
|
|
node.datacenter,
|
|
|
|
'Datacenter'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
nodeRow.querySelector('[data-test-client-allocations]').textContent.trim(),
|
|
|
|
allocations.length,
|
|
|
|
'# Allocations'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each client should link to the client detail page', function(assert) {
|
|
|
|
minimumSetup();
|
|
|
|
const node = server.db.nodes[0];
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-09-26 07:47:16 +00:00
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-client-node-row]');
|
2017-09-26 07:47:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-28 01:23:41 +00:00
|
|
|
assert.equal(currentURL(), `/clients/${node.id}`);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-30 01:33:57 +00:00
|
|
|
test('when there are no clients, there is an empty message', function(assert) {
|
|
|
|
server.createList('agent', 1);
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-09-30 01:33:57 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-empty-clients-list]'));
|
|
|
|
assert.equal(find('[data-test-empty-clients-list-headline]').textContent, 'No Clients');
|
2017-09-30 01:33:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when there are clients, but no matches for a search term, there is an empty message', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
server.createList('agent', 1);
|
|
|
|
server.create('node', { name: 'node' });
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-09-30 01:33:57 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
fillIn('.search-box input', 'client');
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-empty-clients-list]'));
|
|
|
|
assert.equal(find('[data-test-empty-clients-list-headline]').textContent, 'No Matches');
|
2017-09-30 01:33:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-24 23:08:01 +00:00
|
|
|
test('when accessing clients is forbidden, show a message with a link to the tokens page', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
server.create('agent');
|
|
|
|
server.create('node', { name: 'node' });
|
|
|
|
server.pretender.get('/v1/nodes', () => [403, {}, null]);
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-10-24 23:08:01 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(find('[data-test-error-title]').textContent, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-error-message] a');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
test('/servers should list all servers', function(assert) {
|
|
|
|
const agentsCount = 10;
|
|
|
|
const pageSize = 8;
|
|
|
|
|
|
|
|
server.createList('node', 1);
|
|
|
|
server.createList('agent', agentsCount);
|
|
|
|
|
|
|
|
const leader = findLeader(server.schema);
|
|
|
|
|
|
|
|
visit('/servers');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(findAll('[data-test-server-agent-row]').length, pageSize);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const sortedAgents = server.db.agents
|
|
|
|
.sort((a, b) => {
|
|
|
|
if (`${a.address}:${a.tags.port}` === leader) {
|
|
|
|
return 1;
|
|
|
|
} else if (`${b.address}:${b.tags.port}` === leader) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
})
|
|
|
|
.reverse();
|
|
|
|
|
|
|
|
for (var agentNumber = 0; agentNumber < 8; agentNumber++) {
|
2018-01-05 20:59:36 +00:00
|
|
|
const serverRow = findAll('[data-test-server-agent-row]')[agentNumber];
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
serverRow.querySelector('[data-test-server-name]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sortedAgents[agentNumber].name,
|
2018-01-05 20:59:36 +00:00
|
|
|
'Servers are ordered'
|
2017-09-19 14:47:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each server should show high-level info of the server', function(assert) {
|
|
|
|
minimumSetup();
|
|
|
|
const agent = server.db.agents[0];
|
|
|
|
|
|
|
|
visit('/servers');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
const agentRow = find('[data-test-server-agent-row]');
|
|
|
|
|
|
|
|
assert.equal(agentRow.querySelector('[data-test-server-name]').textContent, agent.name, 'Name');
|
|
|
|
assert.equal(
|
|
|
|
agentRow.querySelector('[data-test-server-status]').textContent,
|
|
|
|
agent.status,
|
|
|
|
'Status'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
agentRow.querySelector('[data-test-server-is-leader]').textContent,
|
|
|
|
'True',
|
|
|
|
'Leader?'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
agentRow.querySelector('[data-test-server-address]').textContent,
|
|
|
|
agent.address,
|
|
|
|
'Address'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
agentRow.querySelector('[data-test-server-port]').textContent,
|
|
|
|
agent.serf_port,
|
|
|
|
'Serf Port'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
agentRow.querySelector('[data-test-server-datacenter]').textContent,
|
|
|
|
agent.tags.dc,
|
|
|
|
'Datacenter'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each server should link to the server detail page', function(assert) {
|
|
|
|
minimumSetup();
|
|
|
|
const agent = server.db.agents[0];
|
|
|
|
|
|
|
|
visit('/servers');
|
2017-09-26 07:47:16 +00:00
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-server-agent-row]');
|
2017-09-26 07:47:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), `/servers/${agent.name}`);
|
|
|
|
});
|
|
|
|
});
|
2017-09-30 02:20:28 +00:00
|
|
|
|
2017-10-24 23:08:01 +00:00
|
|
|
test('when accessing servers is forbidden, show a message with a link to the tokens page', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
server.create('agent');
|
|
|
|
server.pretender.get('/v1/agent/members', () => [403, {}, null]);
|
|
|
|
|
|
|
|
visit('/servers');
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(find('[data-test-error-title]').textContent, 'Not Authorized');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
click('[data-test-error-message] a');
|
2017-10-24 23:08:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|