github.com/anuvu/nomad@v0.8.7-atom1/ui/tests/acceptance/allocation-detail-test.js (about)

     1  import $ from 'jquery';
     2  import { assign } from '@ember/polyfills';
     3  import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers';
     4  import { test } from 'qunit';
     5  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     6  import moment from 'moment';
     7  
     8  let job;
     9  let node;
    10  let allocation;
    11  
    12  moduleForAcceptance('Acceptance | allocation detail', {
    13    beforeEach() {
    14      server.create('agent');
    15  
    16      node = server.create('node');
    17      job = server.create('job', { groupCount: 0, createAllocations: false });
    18      allocation = server.create('allocation', 'withTaskWithPorts');
    19  
    20      // Make sure the node has an unhealthy driver
    21      node.update({
    22        driver: assign(node.drivers, {
    23          docker: {
    24            detected: true,
    25            healthy: false,
    26          },
    27        }),
    28      });
    29  
    30      // Make sure a task for the allocation depends on the unhealthy driver
    31      server.schema.tasks.first().update({
    32        driver: 'docker',
    33      });
    34  
    35      visit(`/allocations/${allocation.id}`);
    36    },
    37  });
    38  
    39  test('/allocation/:id should name the allocation and link to the corresponding job and node', function(assert) {
    40    assert.ok(
    41      find('[data-test-title]').textContent.includes(allocation.name),
    42      'Allocation name is in the heading'
    43    );
    44    assert.equal(
    45      find('[data-test-allocation-details] [data-test-job-link]').textContent.trim(),
    46      job.name,
    47      'Job name is in the subheading'
    48    );
    49    assert.equal(
    50      find('[data-test-allocation-details] [data-test-client-link]').textContent.trim(),
    51      node.id.split('-')[0],
    52      'Node short id is in the subheading'
    53    );
    54  
    55    andThen(() => {
    56      click('[data-test-allocation-details] [data-test-job-link]');
    57    });
    58  
    59    andThen(() => {
    60      assert.equal(currentURL(), `/jobs/${job.id}`, 'Job link navigates to the job');
    61    });
    62  
    63    visit(`/allocations/${allocation.id}`);
    64  
    65    andThen(() => {
    66      click('[data-test-allocation-details] [data-test-client-link]');
    67    });
    68  
    69    andThen(() => {
    70      assert.equal(currentURL(), `/clients/${node.id}`, 'Client link navigates to the client');
    71    });
    72  });
    73  
    74  test('/allocation/:id should list all tasks for the allocation', function(assert) {
    75    assert.equal(
    76      findAll('[data-test-task-row]').length,
    77      server.db.taskStates.where({ allocationId: allocation.id }).length,
    78      'Table lists all tasks'
    79    );
    80  });
    81  
    82  test('each task row should list high-level information for the task', function(assert) {
    83    const task = server.db.taskStates.where({ allocationId: allocation.id }).sortBy('name')[0];
    84    const taskResources = allocation.taskResourcesIds
    85      .map(id => server.db.taskResources.find(id))
    86      .sortBy('name')[0];
    87    const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
    88    const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
    89    const taskRow = $(findAll('[data-test-task-row]')[0]);
    90    const events = server.db.taskEvents.where({ taskStateId: task.id });
    91    const event = events[events.length - 1];
    92  
    93    assert.equal(
    94      taskRow
    95        .find('[data-test-name]')
    96        .text()
    97        .trim(),
    98      task.name,
    99      'Name'
   100    );
   101    assert.equal(
   102      taskRow
   103        .find('[data-test-state]')
   104        .text()
   105        .trim(),
   106      task.state,
   107      'State'
   108    );
   109    assert.equal(
   110      taskRow
   111        .find('[data-test-message]')
   112        .text()
   113        .trim(),
   114      event.displayMessage,
   115      'Event Message'
   116    );
   117    assert.equal(
   118      taskRow
   119        .find('[data-test-time]')
   120        .text()
   121        .trim(),
   122      moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'),
   123      'Event Time'
   124    );
   125  
   126    assert.ok(reservedPorts.length, 'The task has reserved ports');
   127    assert.ok(dynamicPorts.length, 'The task has dynamic ports');
   128  
   129    const addressesText = taskRow.find('[data-test-ports]').text();
   130    reservedPorts.forEach(port => {
   131      assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
   132      assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
   133    });
   134    dynamicPorts.forEach(port => {
   135      assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
   136      assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
   137    });
   138  });
   139  
   140  test('each task row should link to the task detail page', function(assert) {
   141    const task = server.db.taskStates.where({ allocationId: allocation.id }).sortBy('name')[0];
   142  
   143    click('[data-test-task-row] [data-test-name] a');
   144  
   145    andThen(() => {
   146      assert.equal(
   147        currentURL(),
   148        `/allocations/${allocation.id}/${task.name}`,
   149        'Task name in task row links to task detail'
   150      );
   151    });
   152  
   153    andThen(() => {
   154      visit(`/allocations/${allocation.id}`);
   155    });
   156  
   157    andThen(() => {
   158      click('[data-test-task-row]');
   159    });
   160  
   161    andThen(() => {
   162      assert.equal(
   163        currentURL(),
   164        `/allocations/${allocation.id}/${task.name}`,
   165        'Task row links to task detail'
   166      );
   167    });
   168  });
   169  
   170  test('tasks with an unhealthy driver have a warning icon', function(assert) {
   171    assert.ok(find('[data-test-task-row] [data-test-icon="unhealthy-driver"]'), 'Warning is shown');
   172  });
   173  
   174  test('when the allocation has not been rescheduled, the reschedule events section is not rendered', function(assert) {
   175    assert.notOk(find('[data-test-reschedule-events]'), 'Reschedule Events section exists');
   176  });
   177  
   178  test('when the allocation is not found, an error message is shown, but the URL persists', function(assert) {
   179    visit('/allocations/not-a-real-allocation');
   180  
   181    andThen(() => {
   182      assert.equal(
   183        server.pretender.handledRequests.findBy('status', 404).url,
   184        '/v1/allocation/not-a-real-allocation',
   185        'A request to the nonexistent allocation is made'
   186      );
   187      assert.equal(currentURL(), '/allocations/not-a-real-allocation', 'The URL persists');
   188      assert.ok(find('[data-test-error]'), 'Error message is shown');
   189      assert.equal(
   190        find('[data-test-error-title]').textContent,
   191        'Not Found',
   192        'Error message is for 404'
   193      );
   194    });
   195  });
   196  
   197  moduleForAcceptance('Acceptance | allocation detail (rescheduled)', {
   198    beforeEach() {
   199      server.create('agent');
   200  
   201      node = server.create('node');
   202      job = server.create('job', { createAllocations: false });
   203      allocation = server.create('allocation', 'rescheduled');
   204  
   205      visit(`/allocations/${allocation.id}`);
   206    },
   207  });
   208  
   209  test('when the allocation has been rescheduled, the reschedule events section is rendered', function(assert) {
   210    assert.ok(find('[data-test-reschedule-events]'), 'Reschedule Events section exists');
   211  });