github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/job-allocations-test.js (about)

     1  import { test } from 'qunit';
     2  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     3  import Allocations from 'nomad-ui/tests/pages/jobs/job/allocations';
     4  
     5  let job;
     6  let allocations;
     7  
     8  const makeSearchAllocations = server => {
     9    Array(10)
    10      .fill(null)
    11      .map((_, index) => {
    12        server.create('allocation', {
    13          id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`,
    14        });
    15      });
    16  };
    17  
    18  moduleForAcceptance('Acceptance | job allocations', {
    19    beforeEach() {
    20      server.create('node');
    21  
    22      job = server.create('job', { noFailedPlacements: true, createAllocations: false });
    23    },
    24  });
    25  
    26  test('lists all allocations for the job', function(assert) {
    27    server.createList('allocation', Allocations.pageSize - 1);
    28    allocations = server.schema.allocations.where({ jobId: job.id }).models;
    29  
    30    Allocations.visit({ id: job.id });
    31  
    32    andThen(() => {
    33      assert.equal(
    34        Allocations.allocations.length,
    35        Allocations.pageSize - 1,
    36        'Allocations are shown in a table'
    37      );
    38  
    39      const sortedAllocations = allocations.sortBy('modifyIndex').reverse();
    40  
    41      Allocations.allocations.forEach((allocation, index) => {
    42        const shortId = sortedAllocations[index].id.split('-')[0];
    43        assert.equal(allocation.shortId, shortId, `Allocation ${index} is ${shortId}`);
    44      });
    45    });
    46  });
    47  
    48  test('allocations table is sortable', function(assert) {
    49    server.createList('allocation', Allocations.pageSize - 1);
    50    allocations = server.schema.allocations.where({ jobId: job.id }).models;
    51  
    52    Allocations.visit({ id: job.id });
    53  
    54    andThen(() => {
    55      Allocations.sortBy('taskGroupName');
    56  
    57      andThen(() => {
    58        assert.equal(
    59          currentURL(),
    60          `/jobs/${job.id}/allocations?sort=taskGroupName`,
    61          'the URL persists the sort parameter'
    62        );
    63        const sortedAllocations = allocations.sortBy('taskGroup').reverse();
    64        Allocations.allocations.forEach((allocation, index) => {
    65          const shortId = sortedAllocations[index].id.split('-')[0];
    66          assert.equal(
    67            allocation.shortId,
    68            shortId,
    69            `Allocation ${index} is ${shortId} with task group ${sortedAllocations[index].taskGroup}`
    70          );
    71        });
    72      });
    73    });
    74  });
    75  
    76  test('allocations table is searchable', function(assert) {
    77    makeSearchAllocations(server);
    78  
    79    allocations = server.schema.allocations.where({ jobId: job.id }).models;
    80    Allocations.visit({ id: job.id });
    81  
    82    andThen(() => {
    83      Allocations.search('ffffff');
    84    });
    85  
    86    andThen(() => {
    87      assert.equal(Allocations.allocations.length, 5, 'List is filtered by search term');
    88    });
    89  });
    90  
    91  test('when a search yields no results, the search box remains', function(assert) {
    92    makeSearchAllocations(server);
    93  
    94    allocations = server.schema.allocations.where({ jobId: job.id }).models;
    95    Allocations.visit({ id: job.id });
    96  
    97    andThen(() => {
    98      Allocations.search('^nothing will ever match this long regex$');
    99    });
   100  
   101    andThen(() => {
   102      assert.equal(
   103        Allocations.emptyState.headline,
   104        'No Matches',
   105        'List is empty and the empty state is about search'
   106      );
   107  
   108      assert.ok(Allocations.hasSearchBox, 'Search box is still shown');
   109    });
   110  });