github.com/hernad/nomad@v1.6.112/ui/tests/acceptance/client-monitor-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { currentURL } from '@ember/test-helpers'; 7 import { run } from '@ember/runloop'; 8 import { module, test } from 'qunit'; 9 import { setupApplicationTest } from 'ember-qunit'; 10 import { setupMirage } from 'ember-cli-mirage/test-support'; 11 import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; 12 import ClientMonitor from 'nomad-ui/tests/pages/clients/monitor'; 13 import Layout from 'nomad-ui/tests/pages/layout'; 14 15 let node; 16 let managementToken; 17 let clientToken; 18 19 module('Acceptance | client monitor', function (hooks) { 20 setupApplicationTest(hooks); 21 setupMirage(hooks); 22 23 hooks.beforeEach(function () { 24 server.create('node-pool'); 25 node = server.create('node'); 26 27 managementToken = server.create('token'); 28 clientToken = server.create('token'); 29 30 window.localStorage.nomadTokenSecret = managementToken.secretId; 31 32 server.create('agent'); 33 run.later(run, run.cancelTimers, 500); 34 }); 35 36 test('it passes an accessibility audit', async function (assert) { 37 assert.expect(1); 38 39 await ClientMonitor.visit({ id: node.id }); 40 await a11yAudit(assert); 41 }); 42 43 test('/clients/:id/monitor should have a breadcrumb trail linking back to clients', async function (assert) { 44 await ClientMonitor.visit({ id: node.id }); 45 46 assert.equal(Layout.breadcrumbFor('clients.index').text, 'Clients'); 47 assert.equal( 48 Layout.breadcrumbFor('clients.client').text, 49 `Client ${node.id.split('-')[0]}` 50 ); 51 52 await Layout.breadcrumbFor('clients.index').visit(); 53 assert.equal(currentURL(), '/clients'); 54 }); 55 56 test('the monitor page immediately streams agent monitor output at the info level', async function (assert) { 57 await ClientMonitor.visit({ id: node.id }); 58 59 const logRequest = server.pretender.handledRequests.find((req) => 60 req.url.startsWith('/v1/agent/monitor') 61 ); 62 assert.ok(ClientMonitor.logsArePresent); 63 assert.ok(logRequest); 64 assert.ok(logRequest.url.includes('log_level=info')); 65 }); 66 67 test('switching the log level persists the new log level as a query param', async function (assert) { 68 await ClientMonitor.visit({ id: node.id }); 69 await ClientMonitor.selectLogLevel('Debug'); 70 assert.equal(currentURL(), `/clients/${node.id}/monitor?level=debug`); 71 }); 72 73 test('when the current access token does not include the agent:read rule, a descriptive error message is shown', async function (assert) { 74 window.localStorage.nomadTokenSecret = clientToken.secretId; 75 76 await ClientMonitor.visit({ id: node.id }); 77 assert.notOk(ClientMonitor.logsArePresent); 78 assert.ok(ClientMonitor.error.isShown); 79 assert.equal(ClientMonitor.error.title, 'Not Authorized'); 80 assert.ok(ClientMonitor.error.message.includes('agent:read')); 81 82 await ClientMonitor.error.seekHelp(); 83 assert.equal(currentURL(), '/settings/tokens'); 84 }); 85 });