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-03-13 01:09:19 +00:00
|
|
|
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
2018-07-10 02:03:26 +00:00
|
|
|
import ServerDetail from 'nomad-ui/tests/pages/servers/detail';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
let agent;
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | server detail', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2017-09-19 14:47:10 +00:00
|
|
|
server.createList('agent', 3);
|
|
|
|
agent = server.db.agents[0];
|
2018-07-10 02:03:26 +00:00
|
|
|
ServerDetail.visit({ name: agent.name });
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('visiting /servers/:server_name', function(assert) {
|
|
|
|
assert.equal(currentURL(), `/servers/${encodeURIComponent(agent.name)}`);
|
|
|
|
});
|
2018-07-10 02:03:26 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('the server detail page should list all tags for the server', function(assert) {
|
|
|
|
const tags = Object.keys(agent.tags)
|
|
|
|
.map(name => ({ name, value: agent.tags[name] }))
|
|
|
|
.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
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('the list of servers from /servers should still be present', function(assert) {
|
|
|
|
assert.equal(ServerDetail.servers.length, server.db.agents.length, '# of servers');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('the active server should be denoted in the table', function(assert) {
|
|
|
|
const activeServers = ServerDetail.servers.filter(server => server.isActive);
|
2018-07-10 02:03:26 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(activeServers.length, 1, 'Only one active server');
|
|
|
|
assert.equal(ServerDetail.activeServer.name, agent.name, 'Active server matches current route');
|
|
|
|
});
|
2017-09-29 00:05:41 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('when the server is not found, an error message is shown, but the URL persists', function(assert) {
|
|
|
|
ServerDetail.visit({ name: 'not-a-real-server' });
|
2017-09-29 00:05:41 +00:00
|
|
|
|
|
|
|
assert.equal(currentURL(), '/servers/not-a-real-server', 'The URL persists');
|
2018-07-10 02:03:26 +00:00
|
|
|
assert.equal(ServerDetail.error.title, 'Not Found', 'Error message is for 404');
|
2017-09-29 00:05:41 +00:00
|
|
|
});
|
|
|
|
});
|