2020-06-16 00:59:55 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
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';
|
2020-06-16 00:59:55 +00:00
|
|
|
import ClientMonitor from 'nomad-ui/tests/pages/clients/monitor';
|
2020-12-10 17:51:22 +00:00
|
|
|
import Layout from 'nomad-ui/tests/pages/layout';
|
2020-06-16 00:59:55 +00:00
|
|
|
|
|
|
|
let node;
|
|
|
|
let managementToken;
|
|
|
|
let clientToken;
|
|
|
|
|
|
|
|
module('Acceptance | client monitor', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
|
|
|
node = server.create('node');
|
|
|
|
|
|
|
|
managementToken = server.create('token');
|
|
|
|
clientToken = server.create('token');
|
|
|
|
|
|
|
|
window.localStorage.nomadTokenSecret = managementToken.secretId;
|
|
|
|
|
|
|
|
server.create('agent');
|
|
|
|
run.later(run, run.cancelTimers, 500);
|
|
|
|
});
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
|
|
await ClientMonitor.visit({ id: node.id });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2020-06-16 00:59:55 +00:00
|
|
|
test('/clients/:id/monitor should have a breadcrumb trail linking back to clients', async function(assert) {
|
|
|
|
await ClientMonitor.visit({ id: node.id });
|
|
|
|
|
2020-12-10 17:51:22 +00:00
|
|
|
assert.equal(Layout.breadcrumbFor('clients.index').text, 'Clients');
|
|
|
|
assert.equal(Layout.breadcrumbFor('clients.client').text, node.id.split('-')[0]);
|
2020-06-16 00:59:55 +00:00
|
|
|
|
2020-12-10 17:51:22 +00:00
|
|
|
await Layout.breadcrumbFor('clients.index').visit();
|
2020-06-16 00:59:55 +00:00
|
|
|
assert.equal(currentURL(), '/clients');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('the monitor page immediately streams agent monitor output at the info level', async function(assert) {
|
|
|
|
await ClientMonitor.visit({ id: node.id });
|
|
|
|
|
|
|
|
const logRequest = server.pretender.handledRequests.find(req =>
|
|
|
|
req.url.startsWith('/v1/agent/monitor')
|
|
|
|
);
|
|
|
|
assert.ok(ClientMonitor.logsArePresent);
|
|
|
|
assert.ok(logRequest);
|
|
|
|
assert.ok(logRequest.url.includes('log_level=info'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('switching the log level persists the new log level as a query param', async function(assert) {
|
|
|
|
await ClientMonitor.visit({ id: node.id });
|
|
|
|
await ClientMonitor.selectLogLevel('Debug');
|
|
|
|
assert.equal(currentURL(), `/clients/${node.id}/monitor?level=debug`);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the current access token does not include the agent:read rule, a descriptive error message is shown', async function(assert) {
|
|
|
|
window.localStorage.nomadTokenSecret = clientToken.secretId;
|
|
|
|
|
|
|
|
await ClientMonitor.visit({ id: node.id });
|
|
|
|
assert.notOk(ClientMonitor.logsArePresent);
|
|
|
|
assert.ok(ClientMonitor.error.isShown);
|
|
|
|
assert.equal(ClientMonitor.error.title, 'Not Authorized');
|
|
|
|
assert.ok(ClientMonitor.error.message.includes('agent:read'));
|
|
|
|
|
|
|
|
await ClientMonitor.error.seekHelp();
|
|
|
|
assert.equal(currentURL(), '/settings/tokens');
|
|
|
|
});
|
|
|
|
});
|