open-nomad/ui/tests/acceptance/servers-list-test.js

89 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-03-13 00:08:16 +00:00
import { currentURL } from '@ember/test-helpers';
2019-03-13 00:04:16 +00:00
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
2019-09-26 18:47:07 +00:00
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import { findLeader } from '../../mirage/config';
2018-07-10 01:12:46 +00:00
import ServersList from 'nomad-ui/tests/pages/servers/list';
import formatHost from 'nomad-ui/utils/format-host';
2018-07-10 01:12:46 +00:00
const minimumSetup = () => {
server.createList('node', 1);
server.createList('agent', 1);
2018-07-10 01:12:46 +00:00
};
const agentSort = leader => (a, b) => {
if (formatHost(a.member.Address, a.member.Tags.port) === leader) {
2018-07-10 01:12:46 +00:00
return 1;
} else if (formatHost(b.member.Address, b.member.Tags.port) === leader) {
2018-07-10 01:12:46 +00:00
return -1;
}
return 0;
};
2019-03-13 00:04:16 +00:00
module('Acceptance | servers list', function(hooks) {
setupApplicationTest(hooks);
2019-03-13 01:09:19 +00:00
setupMirage(hooks);
test('it passes an accessibility audit', async function(assert) {
minimumSetup();
await ServersList.visit();
await a11yAudit(assert);
});
test('/servers should list all servers', async function(assert) {
2019-03-13 00:04:16 +00:00
server.createList('node', 1);
server.createList('agent', 10);
2019-03-13 00:04:16 +00:00
const leader = findLeader(server.schema);
const sortedAgents = server.db.agents.sort(agentSort(leader)).reverse();
await ServersList.visit();
2018-07-10 01:12:46 +00:00
assert.equal(ServersList.servers.length, ServersList.pageSize, 'List is stopped at pageSize');
ServersList.servers.forEach((server, index) => {
assert.equal(server.name, sortedAgents[index].member.Name, 'Servers are ordered');
2018-07-10 01:12:46 +00:00
});
assert.equal(document.title, 'Servers - Nomad');
});
test('each server should show high-level info of the server', async function(assert) {
2019-03-13 00:04:16 +00:00
minimumSetup();
const agent = server.db.agents[0];
await ServersList.visit();
2018-07-10 01:12:46 +00:00
const agentRow = ServersList.servers.objectAt(0);
assert.equal(agentRow.name, agent.member.Name, 'Name');
assert.equal(agentRow.status, agent.member.Status, 'Status');
2018-07-10 01:12:46 +00:00
assert.equal(agentRow.leader, 'True', 'Leader?');
assert.equal(agentRow.address, agent.member.Address, 'Address');
assert.equal(agentRow.serfPort, agent.member.Port, 'Serf Port');
assert.equal(agentRow.datacenter, agent.member.Tags.dc, 'Datacenter');
});
test('each server should link to the server detail page', async function(assert) {
2019-03-13 00:04:16 +00:00
minimumSetup();
const agent = server.db.agents[0];
await ServersList.visit();
await ServersList.servers.objectAt(0).clickRow();
assert.equal(currentURL(), `/servers/${agent.member.Name}`, 'Now at the server detail page');
});
test('when accessing servers is forbidden, show a message with a link to the tokens page', async function(assert) {
2019-03-13 00:04:16 +00:00
server.create('agent');
server.pretender.get('/v1/agent/members', () => [403, {}, null]);
await ServersList.visit();
2018-07-10 01:12:46 +00:00
assert.equal(ServersList.error.title, 'Not Authorized');
await ServersList.error.seekHelp();
assert.equal(currentURL(), '/settings/tokens');
});
});