github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/acceptance/task-logs-test.js (about)

     1  /* eslint-disable qunit/require-expect */
     2  import { click, currentURL } from '@ember/test-helpers';
     3  import { run } from '@ember/runloop';
     4  import { module, test } from 'qunit';
     5  import { setupApplicationTest } from 'ember-qunit';
     6  import { setupMirage } from 'ember-cli-mirage/test-support';
     7  import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
     8  import TaskLogs from 'nomad-ui/tests/pages/allocations/task/logs';
     9  import percySnapshot from '@percy/ember';
    10  import faker from 'nomad-ui/mirage/faker';
    11  
    12  let allocation;
    13  let task;
    14  let job;
    15  
    16  module('Acceptance | task logs', function (hooks) {
    17    setupApplicationTest(hooks);
    18    setupMirage(hooks);
    19  
    20    hooks.beforeEach(async function () {
    21      faker.seed(1);
    22      server.create('agent');
    23      server.create('node', 'forceIPv4');
    24      job = server.create('job', { createAllocations: false });
    25  
    26      allocation = server.create('allocation', {
    27        jobId: job.id,
    28        clientStatus: 'running',
    29      });
    30      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
    31  
    32      run.later(run, run.cancelTimers, 1000);
    33    });
    34  
    35    test('it passes an accessibility audit', async function (assert) {
    36      await TaskLogs.visit({ id: allocation.id, name: task.name });
    37      await a11yAudit(assert);
    38      await percySnapshot(assert);
    39    });
    40  
    41    test('/allocation/:id/:task_name/logs should have a log component', async function (assert) {
    42      await TaskLogs.visit({ id: allocation.id, name: task.name });
    43      assert.equal(
    44        currentURL(),
    45        `/allocations/${allocation.id}/${task.name}/logs`,
    46        'No redirect'
    47      );
    48      assert.ok(TaskLogs.hasTaskLog, 'Task log component found');
    49      assert.equal(document.title, `Task ${task.name} logs - Nomad`);
    50    });
    51  
    52    test('the stdout log immediately starts streaming', async function (assert) {
    53      await TaskLogs.visit({ id: allocation.id, name: task.name });
    54      const node = server.db.nodes.find(allocation.nodeId);
    55      const logUrlRegex = new RegExp(
    56        `${node.httpAddr}/v1/client/fs/logs/${allocation.id}`
    57      );
    58      assert.ok(
    59        server.pretender.handledRequests.filter((req) =>
    60          logUrlRegex.test(req.url)
    61        ).length,
    62        'Log requests were made'
    63      );
    64    });
    65  
    66    test('logs are accessible in a sidebar context', async function (assert) {
    67      await TaskLogs.visitParentJob({
    68        id: job.id,
    69        allocationId: allocation.id,
    70        name: task.name,
    71      });
    72      assert.notOk(TaskLogs.sidebarIsPresent, 'Sidebar is not present');
    73  
    74      run.later(() => {
    75        run.cancelTimers();
    76      }, 500);
    77  
    78      await click('button.logs-sidebar-trigger');
    79  
    80      assert.ok(TaskLogs.sidebarIsPresent, 'Sidebar is present');
    81      assert
    82        .dom('.task-context-sidebar h1.title')
    83        .includesText(task.name, 'Sidebar title is correct');
    84      assert
    85        .dom('.task-context-sidebar h1.title')
    86        .includesText(task.state, 'Task state is correctly displayed');
    87      await percySnapshot(assert, {
    88        percyCSS: '.allocation-row td { display: none; }',
    89      });
    90  
    91      await click('.sidebar button.close');
    92      assert.notOk(TaskLogs.sidebarIsPresent, 'Sidebar is not present');
    93    });
    94  });