2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
2023-06-30 21:07:57 +00:00
|
|
|
import {
|
|
|
|
click,
|
|
|
|
currentURL,
|
|
|
|
findAll,
|
|
|
|
triggerKeyEvent,
|
|
|
|
} from '@ember/test-helpers';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { run } from '@ember/runloop';
|
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-11 19:31:37 +00:00
|
|
|
import TaskLogs from 'nomad-ui/tests/pages/allocations/task/logs';
|
2022-09-22 14:58:52 +00:00
|
|
|
import percySnapshot from '@percy/ember';
|
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2017-11-16 02:13:28 +00:00
|
|
|
|
|
|
|
let allocation;
|
|
|
|
let task;
|
2022-09-22 14:58:52 +00:00
|
|
|
let job;
|
2017-11-16 02:13:28 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | task logs', 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 () {
|
2022-09-22 14:58:52 +00:00
|
|
|
faker.seed(1);
|
2017-11-16 02:13:28 +00:00
|
|
|
server.create('agent');
|
2023-06-22 17:11:44 +00:00
|
|
|
server.create('node-pool');
|
2017-11-16 02:13:28 +00:00
|
|
|
server.create('node', 'forceIPv4');
|
2022-09-22 14:58:52 +00:00
|
|
|
job = server.create('job', { createAllocations: false });
|
2017-11-16 02:13:28 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
allocation = server.create('allocation', {
|
|
|
|
jobId: job.id,
|
|
|
|
clientStatus: 'running',
|
|
|
|
});
|
2017-11-16 02:13:28 +00:00
|
|
|
task = server.db.taskStates.where({ allocationId: allocation.id })[0];
|
|
|
|
|
|
|
|
run.later(run, run.cancelTimers, 1000);
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-11-16 02:13:28 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2022-09-22 14:58:52 +00:00
|
|
|
await TaskLogs.visit({ id: allocation.id, name: task.name });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2022-09-27 14:25:04 +00:00
|
|
|
await percySnapshot(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/allocation/:id/:task_name/logs should have a log component', async function (assert) {
|
2022-09-22 14:58:52 +00:00
|
|
|
await TaskLogs.visit({ id: allocation.id, name: task.name });
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocation.id}/${task.name}/logs`,
|
|
|
|
'No redirect'
|
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(TaskLogs.hasTaskLog, 'Task log component found');
|
2023-06-22 14:38:17 +00:00
|
|
|
assert.ok(document.title.includes(`Task ${task.name}`));
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-11-16 02:13:28 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the stdout log immediately starts streaming', async function (assert) {
|
2022-09-22 14:58:52 +00:00
|
|
|
await TaskLogs.visit({ id: allocation.id, name: task.name });
|
2019-03-13 00:04:16 +00:00
|
|
|
const node = server.db.nodes.find(allocation.nodeId);
|
2021-12-28 16:08:12 +00:00
|
|
|
const logUrlRegex = new RegExp(
|
|
|
|
`${node.httpAddr}/v1/client/fs/logs/${allocation.id}`
|
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(
|
2021-12-28 16:08:12 +00:00
|
|
|
server.pretender.handledRequests.filter((req) =>
|
|
|
|
logUrlRegex.test(req.url)
|
|
|
|
).length,
|
2019-03-13 00:04:16 +00:00
|
|
|
'Log requests were made'
|
|
|
|
);
|
|
|
|
});
|
2022-09-22 14:58:52 +00:00
|
|
|
|
2023-06-30 21:07:57 +00:00
|
|
|
test('logs can be word-wrapped', async function (assert) {
|
|
|
|
await TaskLogs.visit({ id: allocation.id, name: task.name });
|
|
|
|
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
|
|
|
|
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 100);
|
|
|
|
await click('[data-test-word-wrap-toggle]');
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isChecked();
|
|
|
|
assert.dom('[data-test-output]').hasClass('wrapped');
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 100);
|
|
|
|
await click('[data-test-word-wrap-toggle]');
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
|
|
|
|
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');
|
|
|
|
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('logs in sidebar can be word-wrapped', async function (assert) {
|
|
|
|
await TaskLogs.visitParentJob({
|
|
|
|
id: job.id,
|
|
|
|
allocationId: allocation.id,
|
|
|
|
name: task.name,
|
|
|
|
});
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
const taskRow = [
|
|
|
|
...findAll('.task-sub-row').filter((row) => {
|
|
|
|
return row.textContent.includes(task.name);
|
|
|
|
}),
|
|
|
|
][0];
|
|
|
|
|
|
|
|
await click(taskRow.querySelector('button.logs-sidebar-trigger'));
|
|
|
|
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
|
|
|
|
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 500);
|
|
|
|
|
|
|
|
// type "ww" to trigger word wrap
|
|
|
|
const W_KEY = 87;
|
|
|
|
triggerKeyEvent('.sidebar', 'keydown', W_KEY);
|
|
|
|
await triggerKeyEvent('.sidebar', 'keydown', W_KEY);
|
|
|
|
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isChecked();
|
|
|
|
assert.dom('[data-test-output]').hasClass('wrapped');
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
triggerKeyEvent('.sidebar', 'keydown', W_KEY);
|
|
|
|
await triggerKeyEvent('.sidebar', 'keydown', W_KEY);
|
|
|
|
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
|
|
|
|
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');
|
|
|
|
|
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
|
2022-09-22 14:58:52 +00:00
|
|
|
test('logs are accessible in a sidebar context', async function (assert) {
|
|
|
|
await TaskLogs.visitParentJob({
|
|
|
|
id: job.id,
|
|
|
|
allocationId: allocation.id,
|
|
|
|
name: task.name,
|
|
|
|
});
|
|
|
|
assert.notOk(TaskLogs.sidebarIsPresent, 'Sidebar is not present');
|
|
|
|
|
|
|
|
run.later(() => {
|
|
|
|
run.cancelTimers();
|
|
|
|
}, 500);
|
|
|
|
|
2023-06-07 21:01:35 +00:00
|
|
|
const taskRow = [
|
|
|
|
...findAll('.task-sub-row').filter((row) => {
|
|
|
|
return row.textContent.includes(task.name);
|
|
|
|
}),
|
|
|
|
][0];
|
|
|
|
|
|
|
|
await click(taskRow.querySelector('button.logs-sidebar-trigger'));
|
2022-09-22 14:58:52 +00:00
|
|
|
|
|
|
|
assert.ok(TaskLogs.sidebarIsPresent, 'Sidebar is present');
|
|
|
|
assert
|
|
|
|
.dom('.task-context-sidebar h1.title')
|
|
|
|
.includesText(task.name, 'Sidebar title is correct');
|
|
|
|
assert
|
|
|
|
.dom('.task-context-sidebar h1.title')
|
|
|
|
.includesText(task.state, 'Task state is correctly displayed');
|
2022-11-21 19:55:13 +00:00
|
|
|
await percySnapshot(assert, {
|
2023-01-17 17:08:41 +00:00
|
|
|
percyCSS: `
|
|
|
|
.allocation-row td { display: none; }
|
|
|
|
.task-events table td:nth-child(1) { color: transparent; }
|
|
|
|
`,
|
2022-11-21 19:55:13 +00:00
|
|
|
});
|
2022-09-22 14:58:52 +00:00
|
|
|
|
|
|
|
await click('.sidebar button.close');
|
|
|
|
assert.notOk(TaskLogs.sidebarIsPresent, 'Sidebar is not present');
|
|
|
|
});
|
2017-11-16 02:13:28 +00:00
|
|
|
});
|