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

     1  import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers';
     2  import { test } from 'qunit';
     3  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     4  import moment from 'moment';
     5  
     6  let allocation;
     7  let task;
     8  
     9  moduleForAcceptance('Acceptance | task detail', {
    10    beforeEach() {
    11      server.create('agent');
    12      server.create('node');
    13      server.create('job', { createAllocations: false });
    14      allocation = server.create('allocation', 'withTaskWithPorts');
    15      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
    16  
    17      visit(`/allocations/${allocation.id}/${task.name}`);
    18    },
    19  });
    20  
    21  test('/allocation/:id/:task_name should name the task and list high-level task information', function(assert) {
    22    assert.ok(find('[data-test-title]').textContent.includes(task.name), 'Task name');
    23    assert.ok(find('[data-test-state]').textContent.includes(task.state), 'Task state');
    24  
    25    assert.ok(
    26      find('[data-test-started-at]').textContent.includes(
    27        moment(task.startedAt).format('MM/DD/YY HH:mm:ss')
    28      ),
    29      'Task started at'
    30    );
    31  });
    32  
    33  test('breadcrumbs match jobs / job / task group / allocation / task', function(assert) {
    34    const { jobId, taskGroup } = allocation;
    35    const job = server.db.jobs.find(jobId);
    36  
    37    const shortId = allocation.id.split('-')[0];
    38  
    39    assert.equal(
    40      find('[data-test-breadcrumb="Jobs"]').textContent.trim(),
    41      'Jobs',
    42      'Jobs is the first breadcrumb'
    43    );
    44    assert.equal(
    45      find(`[data-test-breadcrumb="${job.name}"]`).textContent.trim(),
    46      job.name,
    47      'Job is the second breadcrumb'
    48    );
    49    assert.equal(
    50      find(`[data-test-breadcrumb="${taskGroup}`).textContent.trim(),
    51      taskGroup,
    52      'Task Group is the third breadcrumb'
    53    );
    54    assert.equal(
    55      find(`[data-test-breadcrumb="${shortId}"]`).textContent.trim(),
    56      shortId,
    57      'Allocation short id is the fourth breadcrumb'
    58    );
    59    assert.equal(
    60      find(`[data-test-breadcrumb="${task.name}"]`).textContent.trim(),
    61      task.name,
    62      'Task name is the fifth breadcrumb'
    63    );
    64  
    65    click('[data-test-breadcrumb="Jobs"]');
    66    andThen(() => {
    67      assert.equal(currentURL(), '/jobs', 'Jobs breadcrumb links correctly');
    68    });
    69    andThen(() => {
    70      visit(`/allocations/${allocation.id}/${task.name}`);
    71    });
    72    andThen(() => {
    73      click(`[data-test-breadcrumb="${job.name}"]`);
    74    });
    75    andThen(() => {
    76      assert.equal(currentURL(), `/jobs/${job.id}`, 'Job breadcrumb links correctly');
    77    });
    78    andThen(() => {
    79      visit(`/allocations/${allocation.id}/${task.name}`);
    80    });
    81    andThen(() => {
    82      click(`[data-test-breadcrumb="${taskGroup}"]`);
    83    });
    84    andThen(() => {
    85      assert.equal(
    86        currentURL(),
    87        `/jobs/${job.id}/${taskGroup}`,
    88        'Task Group breadcrumb links correctly'
    89      );
    90    });
    91    andThen(() => {
    92      visit(`/allocations/${allocation.id}/${task.name}`);
    93    });
    94    andThen(() => {
    95      click(`[data-test-breadcrumb="${shortId}"]`);
    96    });
    97    andThen(() => {
    98      assert.equal(
    99        currentURL(),
   100        `/allocations/${allocation.id}`,
   101        'Allocations breadcrumb links correctly'
   102      );
   103    });
   104  });
   105  
   106  test('the addresses table lists all reserved and dynamic ports', function(assert) {
   107    const taskResources = allocation.taskResourcesIds
   108      .map(id => server.db.taskResources.find(id))
   109      .find(resources => resources.name === task.name);
   110    const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
   111    const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
   112    const addresses = reservedPorts.concat(dynamicPorts);
   113  
   114    assert.equal(
   115      findAll('[data-test-task-address]').length,
   116      addresses.length,
   117      'All addresses are listed'
   118    );
   119  });
   120  
   121  test('each address row shows the label and value of the address', function(assert) {
   122    const taskResources = allocation.taskResourcesIds
   123      .map(id => server.db.taskResources.find(id))
   124      .findBy('name', task.name);
   125    const networkAddress = taskResources.resources.Networks[0].IP;
   126    const reservedPorts = taskResources.resources.Networks[0].ReservedPorts;
   127    const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts;
   128    const address = reservedPorts.concat(dynamicPorts).sortBy('Label')[0];
   129  
   130    const addressRow = find('[data-test-task-address]');
   131    assert.equal(
   132      addressRow.querySelector('[data-test-task-address-is-dynamic]').textContent.trim(),
   133      reservedPorts.includes(address) ? 'No' : 'Yes',
   134      'Dynamic port is denoted as such'
   135    );
   136    assert.equal(
   137      addressRow.querySelector('[data-test-task-address-name]').textContent.trim(),
   138      address.Label,
   139      'Label'
   140    );
   141    assert.equal(
   142      addressRow.querySelector('[data-test-task-address-address]').textContent.trim(),
   143      `${networkAddress}:${address.Value}`,
   144      'Value'
   145    );
   146  });
   147  
   148  test('the events table lists all recent events', function(assert) {
   149    const events = server.db.taskEvents.where({ taskStateId: task.id });
   150  
   151    assert.equal(
   152      findAll('[data-test-task-event]').length,
   153      events.length,
   154      `Lists ${events.length} events`
   155    );
   156  });
   157  
   158  test('each recent event should list the time, type, and description of the event', function(assert) {
   159    const event = server.db.taskEvents.where({ taskStateId: task.id })[0];
   160    const recentEvent = findAll('[data-test-task-event]').get('lastObject');
   161  
   162    assert.equal(
   163      recentEvent.querySelector('[data-test-task-event-time]').textContent.trim(),
   164      moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'),
   165      'Event timestamp'
   166    );
   167    assert.equal(
   168      recentEvent.querySelector('[data-test-task-event-type]').textContent.trim(),
   169      event.type,
   170      'Event type'
   171    );
   172    assert.equal(
   173      recentEvent.querySelector('[data-test-task-event-message]').textContent.trim(),
   174      event.displayMessage,
   175      'Event message'
   176    );
   177  });
   178  
   179  test('when the allocation is not found, the application errors', function(assert) {
   180    visit(`/allocations/not-a-real-allocation/${task.name}`);
   181  
   182    andThen(() => {
   183      assert.equal(
   184        server.pretender.handledRequests.findBy('status', 404).url,
   185        '/v1/allocation/not-a-real-allocation',
   186        'A request to the nonexistent allocation is made'
   187      );
   188      assert.equal(
   189        currentURL(),
   190        `/allocations/not-a-real-allocation/${task.name}`,
   191        'The URL persists'
   192      );
   193      assert.ok(find('[data-test-error]'), 'Error message is shown');
   194      assert.equal(
   195        find('[data-test-error-title]').textContent,
   196        'Not Found',
   197        'Error message is for 404'
   198      );
   199    });
   200  });
   201  
   202  test('when the allocation is found but the task is not, the application errors', function(assert) {
   203    visit(`/allocations/${allocation.id}/not-a-real-task-name`);
   204  
   205    andThen(() => {
   206      assert.equal(
   207        server.pretender.handledRequests.findBy('status', 200).url,
   208        `/v1/allocation/${allocation.id}`,
   209        'A request to the allocation is made successfully'
   210      );
   211      assert.equal(
   212        currentURL(),
   213        `/allocations/${allocation.id}/not-a-real-task-name`,
   214        'The URL persists'
   215      );
   216      assert.ok(find('[data-test-error]'), 'Error message is shown');
   217      assert.equal(
   218        find('[data-test-error-title]').textContent,
   219        'Not Found',
   220        'Error message is for 404'
   221      );
   222    });
   223  });
   224  
   225  moduleForAcceptance('Acceptance | task detail (no addresses)', {
   226    beforeEach() {
   227      server.create('agent');
   228      server.create('node');
   229      server.create('job');
   230      allocation = server.create('allocation', 'withoutTaskWithPorts');
   231      task = server.db.taskStates.where({ allocationId: allocation.id })[0];
   232  
   233      visit(`/allocations/${allocation.id}/${task.name}`);
   234    },
   235  });
   236  
   237  test('when the task has no addresses, the addresses table is not shown', function(assert) {
   238    assert.notOk(find('[data-test-task-addresses]'), 'No addresses table');
   239  });