github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/acceptance/allocation-detail-test.js (about)

     1  import $ from 'jquery';
     2  import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers';
     3  import { test } from 'qunit';
     4  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     5  import moment from 'moment';
     6  
     7  let job;
     8  let node;
     9  let allocation;
    10  
    11  moduleForAcceptance('Acceptance | allocation detail', {
    12    beforeEach() {
    13      server.create('agent');
    14  
    15      node = server.create('node');
    16      job = server.create('job', { groupCount: 0 });
    17      allocation = server.create('allocation', 'withTaskWithPorts');
    18  
    19      visit(`/allocations/${allocation.id}`);
    20    },
    21  });
    22  
    23  test('/allocation/:id should name the allocation and link to the corresponding job and node', function(assert) {
    24    assert.ok(
    25      find('[data-test-title]').textContent.includes(allocation.name),
    26      'Allocation name is in the heading'
    27    );
    28    assert.equal(
    29      find('[data-test-allocation-details] [data-test-job-link]').textContent.trim(),
    30      job.name,
    31      'Job name is in the subheading'
    32    );
    33    assert.equal(
    34      find('[data-test-allocation-details] [data-test-client-link]').textContent.trim(),
    35      node.id.split('-')[0],
    36      'Node short id is in the subheading'
    37    );
    38  
    39    andThen(() => {
    40      click('[data-test-allocation-details] [data-test-job-link]');
    41    });
    42  
    43    andThen(() => {
    44      assert.equal(currentURL(), `/jobs/${job.id}`, 'Job link navigates to the job');
    45    });
    46  
    47    visit(`/allocations/${allocation.id}`);
    48  
    49    andThen(() => {
    50      click('[data-test-allocation-details] [data-test-client-link]');
    51    });
    52  
    53    andThen(() => {
    54      assert.equal(currentURL(), `/clients/${node.id}`, 'Client link navigates to the client');
    55    });
    56  });
    57  
    58  test('/allocation/:id should list all tasks for the allocation', function(assert) {
    59    assert.equal(
    60      findAll('[data-test-task-row]').length,
    61      server.db.taskStates.where({ allocationId: allocation.id }).length,
    62      'Table lists all tasks'
    63    );
    64  });
    65  
    66  test('each task row should list high-level information for the task', function(assert) {
    67    const task = server.db.taskStates.where({ allocationId: allocation.id }).sortBy('name')[0];
    68    const taskResources = allocation.taskResourcesIds
    69      .map(id => server.db.taskResources.find(id))
    70      .sortBy('name')[0];
    71    const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
    72    const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
    73    const taskRow = $(findAll('[data-test-task-row]')[0]);
    74    const events = server.db.taskEvents.where({ taskStateId: task.id });
    75    const event = events[events.length - 1];
    76  
    77    assert.equal(
    78      taskRow
    79        .find('[data-test-name]')
    80        .text()
    81        .trim(),
    82      task.name,
    83      'Name'
    84    );
    85    assert.equal(
    86      taskRow
    87        .find('[data-test-state]')
    88        .text()
    89        .trim(),
    90      task.state,
    91      'State'
    92    );
    93    assert.equal(
    94      taskRow
    95        .find('[data-test-message]')
    96        .text()
    97        .trim(),
    98      event.message,
    99      'Event Message'
   100    );
   101    assert.equal(
   102      taskRow
   103        .find('[data-test-time]')
   104        .text()
   105        .trim(),
   106      moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'),
   107      'Event Time'
   108    );
   109  
   110    assert.ok(reservedPorts.length, 'The task has reserved ports');
   111    assert.ok(dynamicPorts.length, 'The task has dynamic ports');
   112  
   113    const addressesText = taskRow.find('[data-test-ports]').text();
   114    reservedPorts.forEach(port => {
   115      assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
   116      assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
   117    });
   118    dynamicPorts.forEach(port => {
   119      assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`);
   120      assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`);
   121    });
   122  });
   123  
   124  test('when the allocation is not found, an error message is shown, but the URL persists', function(assert) {
   125    visit('/allocations/not-a-real-allocation');
   126  
   127    andThen(() => {
   128      assert.equal(
   129        server.pretender.handledRequests.findBy('status', 404).url,
   130        '/v1/allocation/not-a-real-allocation',
   131        'A request to the non-existent allocation is made'
   132      );
   133      assert.equal(currentURL(), '/allocations/not-a-real-allocation', 'The URL persists');
   134      assert.ok(find('[data-test-error]'), 'Error message is shown');
   135      assert.equal(
   136        find('[data-test-error-title]').textContent,
   137        'Not Found',
   138        'Error message is for 404'
   139      );
   140    });
   141  });