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 02:03:26 +00:00
|
|
|
import ServerDetail from 'nomad-ui/tests/pages/servers/detail';
|
2021-05-13 17:29:51 +00:00
|
|
|
import formatHost from 'nomad-ui/utils/format-host';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
let agent;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | server detail', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(async function () {
|
2017-09-19 14:47:10 +00:00
|
|
|
server.createList('agent', 3);
|
|
|
|
agent = server.db.agents[0];
|
2021-07-11 19:50:42 +00:00
|
|
|
await ServerDetail.visit({ name: agent.name });
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
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('visiting /servers/:server_name', async function (assert) {
|
2021-07-11 19:50:42 +00:00
|
|
|
assert.equal(currentURL(), `/servers/${encodeURIComponent(agent.name)}`);
|
|
|
|
assert.equal(document.title, `Server ${agent.name} - Nomad`);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2018-07-10 02:03:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the server is the leader, the title shows a leader badge', async function (assert) {
|
2021-07-11 19:50:42 +00:00
|
|
|
assert.ok(ServerDetail.title.includes(agent.name));
|
2020-06-16 04:06:17 +00:00
|
|
|
assert.ok(ServerDetail.hasLeaderBadge);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the details ribbon displays basic information about the server', async function (assert) {
|
2021-07-08 12:01:15 +00:00
|
|
|
assert.ok(ServerDetail.serverStatus.includes(agent.member.Status));
|
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
ServerDetail.address.includes(
|
|
|
|
formatHost(agent.member.Address, agent.member.Tags.port)
|
|
|
|
)
|
2021-07-08 12:01:15 +00:00
|
|
|
);
|
|
|
|
assert.ok(ServerDetail.datacenter.includes(agent.member.Tags.dc));
|
2020-06-16 04:06:17 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the server detail page should list all tags for the server', async function (assert) {
|
2021-07-08 12:01:15 +00:00
|
|
|
const tags = Object.keys(agent.member.Tags)
|
2021-12-28 14:45:20 +00:00
|
|
|
.map((name) => ({ name, value: agent.member.Tags[name] }))
|
2019-03-13 00:04:16 +00:00
|
|
|
.sortBy('name');
|
|
|
|
|
|
|
|
assert.equal(ServerDetail.tags.length, tags.length, '# of tags');
|
|
|
|
ServerDetail.tags.forEach((tagRow, index) => {
|
|
|
|
const tag = tags[index];
|
|
|
|
assert.equal(tagRow.name, tag.name, `Label: ${tag.name}`);
|
|
|
|
assert.equal(tagRow.value, tag.value, `Value: ${tag.value}`);
|
|
|
|
});
|
2018-07-10 02:03:26 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the server is not the leader, there is no leader badge', async function (assert) {
|
2021-07-11 19:50:42 +00:00
|
|
|
await ServerDetail.visit({ name: server.db.agents[1].name });
|
2020-06-16 04:06:17 +00:00
|
|
|
assert.notOk(ServerDetail.hasLeaderBadge);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when the server is not found, an error message is shown, but the URL persists', async function (assert) {
|
2019-03-14 06:44:53 +00:00
|
|
|
await ServerDetail.visit({ name: 'not-a-real-server' });
|
2017-09-29 00:05:41 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
'/servers/not-a-real-server',
|
|
|
|
'The URL persists'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
ServerDetail.error.title,
|
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
2017-09-29 00:05:41 +00:00
|
|
|
});
|
|
|
|
});
|