2017-12-15 21:39:18 +00:00
|
|
|
import $ from 'jquery';
|
2017-09-29 00:05:41 +00:00
|
|
|
import { 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';
|
|
|
|
|
|
|
|
let agent;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | server detail', {
|
|
|
|
beforeEach() {
|
|
|
|
server.createList('agent', 3);
|
|
|
|
agent = server.db.agents[0];
|
|
|
|
visit(`/servers/${agent.name}`);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('visiting /servers/:server_name', function(assert) {
|
|
|
|
assert.equal(currentURL(), `/servers/${agent.name}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the server detail page should list all tags for the server', function(assert) {
|
|
|
|
const tags = agent.tags;
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(findAll('[data-test-server-tag]').length, Object.keys(tags).length, '# of tags');
|
2017-10-24 18:29:00 +00:00
|
|
|
Object.keys(tags)
|
|
|
|
.map(name => ({ name, value: tags[name] }))
|
|
|
|
.sortBy('name')
|
|
|
|
.forEach((tag, index) => {
|
|
|
|
const row = $(`.server-tags tbody tr:eq(${index})`);
|
|
|
|
assert.equal(row.find('td:eq(0)').text(), tag.name, `Label: ${tag.name}`);
|
|
|
|
assert.equal(row.find('td:eq(1)').text(), tag.value, `Value: ${tag.value}`);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('the list of servers from /servers should still be present', function(assert) {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-server-agent-row]').length,
|
|
|
|
server.db.agents.length,
|
|
|
|
'# of servers'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('the active server should be denoted in the table', function(assert) {
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
findAll('[data-test-server-agent-row].is-active').length,
|
|
|
|
1,
|
|
|
|
'Only one active server'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find('[data-test-server-agent-row].is-active [data-test-server-name]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
agent.name,
|
|
|
|
'Active server matches current route'
|
|
|
|
);
|
|
|
|
});
|
2017-09-29 00:05:41 +00:00
|
|
|
|
|
|
|
test('when the server is not found, an error message is shown, but the URL persists', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
visit('/servers/not-a-real-server');
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(currentURL(), '/servers/not-a-real-server', 'The URL persists');
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(find('[data-test-error]'), 'Error message is shown');
|
2017-09-29 00:05:41 +00:00
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-error-title]').textContent,
|
2017-09-29 00:05:41 +00:00
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|