2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
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';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-07-10 00:07:38 +00:00
|
|
|
import { findLeader } from '../../mirage/config';
|
2018-07-10 01:12:46 +00:00
|
|
|
import ServersList from 'nomad-ui/tests/pages/servers/list';
|
2021-05-13 17:29:51 +00:00
|
|
|
import formatHost from 'nomad-ui/utils/format-host';
|
2022-05-05 20:05:13 +00:00
|
|
|
import percySnapshot from '@percy/ember';
|
2022-09-14 15:27:48 +00:00
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2018-07-10 01:12:46 +00:00
|
|
|
const minimumSetup = () => {
|
2022-09-27 14:24:53 +00:00
|
|
|
faker.seed(1);
|
2018-07-10 00:07:38 +00:00
|
|
|
server.createList('node', 1);
|
|
|
|
server.createList('agent', 1);
|
2018-07-10 01:12:46 +00:00
|
|
|
};
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const agentSort = (leader) => (a, b) => {
|
2021-07-08 12:01:15 +00:00
|
|
|
if (formatHost(a.member.Address, a.member.Tags.port) === leader) {
|
2018-07-10 01:12:46 +00:00
|
|
|
return 1;
|
2021-07-08 12:01:15 +00:00
|
|
|
} else if (formatHost(b.member.Address, b.member.Tags.port) === leader) {
|
2018-07-10 01:12:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | servers list', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2020-07-28 17:59:14 +00:00
|
|
|
minimumSetup();
|
|
|
|
await ServersList.visit();
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/servers should list all servers', async function (assert) {
|
2022-09-14 15:27:48 +00:00
|
|
|
faker.seed(1);
|
2019-03-13 00:04:16 +00:00
|
|
|
server.createList('node', 1);
|
|
|
|
server.createList('agent', 10);
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const leader = findLeader(server.schema);
|
|
|
|
const sortedAgents = server.db.agents.sort(agentSort(leader)).reverse();
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServersList.visit();
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2022-05-05 20:05:13 +00:00
|
|
|
await percySnapshot(assert);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
ServersList.servers.length,
|
|
|
|
ServersList.pageSize,
|
|
|
|
'List is stopped at pageSize'
|
|
|
|
);
|
2018-07-10 01:12:46 +00:00
|
|
|
|
|
|
|
ServersList.servers.forEach((server, index) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
server.name,
|
|
|
|
sortedAgents[index].name,
|
|
|
|
'Servers are ordered'
|
|
|
|
);
|
2018-07-10 01:12:46 +00:00
|
|
|
});
|
2019-07-17 20:02:58 +00:00
|
|
|
|
2023-02-02 21:29:04 +00:00
|
|
|
assert.equal(document.title, 'Servers - Mirage - Nomad');
|
2018-07-10 00:07:38 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
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];
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServersList.visit();
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2018-07-10 01:12:46 +00:00
|
|
|
const agentRow = ServersList.servers.objectAt(0);
|
|
|
|
|
2021-07-11 19:50:42 +00:00
|
|
|
assert.equal(agentRow.name, agent.name, 'Name');
|
2021-07-08 12:01:15 +00:00
|
|
|
assert.equal(agentRow.status, agent.member.Status, 'Status');
|
2018-07-10 01:12:46 +00:00
|
|
|
assert.equal(agentRow.leader, 'True', 'Leader?');
|
2021-07-08 12:01:15 +00:00
|
|
|
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');
|
2021-10-22 14:33:06 +00:00
|
|
|
assert.equal(agentRow.version, agent.version, 'Version');
|
2018-07-10 00:07:38 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
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];
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServersList.visit();
|
|
|
|
await ServersList.servers.objectAt(0).clickRow();
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/servers/${agent.name}`,
|
|
|
|
'Now at the server detail page'
|
|
|
|
);
|
2018-07-10 00:07:38 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
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]);
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServersList.visit();
|
2018-07-10 01:12:46 +00:00
|
|
|
assert.equal(ServersList.error.title, 'Not Authorized');
|
2018-07-10 00:07:38 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServersList.error.seekHelp();
|
2018-07-10 00:07:38 +00:00
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|