github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/integration/components/reschedule-event-timeline-test.js (about)

     1  import { module, test } from 'qunit';
     2  import { setupRenderingTest } from 'ember-qunit';
     3  import { find, findAll, render } from '@ember/test-helpers';
     4  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     5  import hbs from 'htmlbars-inline-precompile';
     6  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
     7  import moment from 'moment';
     8  
     9  module('Integration | Component | reschedule event timeline', function(hooks) {
    10    setupRenderingTest(hooks);
    11  
    12    hooks.beforeEach(function() {
    13      this.store = this.owner.lookup('service:store');
    14      this.server = startMirage();
    15      this.server.create('namespace');
    16      this.server.create('node');
    17      this.server.create('job', { createAllocations: false });
    18    });
    19  
    20    hooks.afterEach(function() {
    21      this.server.shutdown();
    22    });
    23  
    24    const commonTemplate = hbs`
    25      <RescheduleEventTimeline @allocation={{allocation}} />
    26    `;
    27  
    28    test('when the allocation is running, the timeline shows past allocations', async function(assert) {
    29      const attempts = 2;
    30  
    31      this.server.create('allocation', 'rescheduled', {
    32        rescheduleAttempts: attempts,
    33        rescheduleSuccess: true,
    34      });
    35  
    36      await this.store.findAll('allocation');
    37  
    38      const allocation = this.store
    39        .peekAll('allocation')
    40        .find(alloc => !alloc.get('nextAllocation.content'));
    41  
    42      this.set('allocation', allocation);
    43      await render(commonTemplate);
    44  
    45      assert.equal(
    46        findAll('[data-test-allocation]').length,
    47        attempts + 1,
    48        'Total allocations equals current allocation plus all past allocations'
    49      );
    50      assert.equal(
    51        find('[data-test-allocation]'),
    52        find(`[data-test-allocation="${allocation.id}"]`),
    53        'First allocation is the current allocation'
    54      );
    55  
    56      assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
    57      assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
    58  
    59      assert.equal(
    60        find(
    61          `[data-test-allocation="${allocation.id}"] [data-test-allocation-link]`
    62        ).textContent.trim(),
    63        allocation.get('shortId'),
    64        'The "this" allocation is correct'
    65      );
    66      assert.equal(
    67        find(
    68          `[data-test-allocation="${allocation.id}"] [data-test-allocation-status]`
    69        ).textContent.trim(),
    70        allocation.get('clientStatus'),
    71        'Allocation shows the status'
    72      );
    73  
    74      await componentA11yAudit(this.element, assert);
    75    });
    76  
    77    test('when the allocation has failed and there is a follow up evaluation, a note with a time is shown', async function(assert) {
    78      const attempts = 2;
    79  
    80      this.server.create('allocation', 'rescheduled', {
    81        rescheduleAttempts: attempts,
    82        rescheduleSuccess: false,
    83      });
    84  
    85      await this.store.findAll('allocation');
    86  
    87      const allocation = this.store
    88        .peekAll('allocation')
    89        .find(alloc => !alloc.get('nextAllocation.content'));
    90  
    91      this.set('allocation', allocation);
    92      await render(commonTemplate);
    93  
    94      assert.ok(
    95        find('[data-test-stop-warning]'),
    96        'Stop warning is shown since the last allocation failed'
    97      );
    98      assert.notOk(find('[data-test-attempt-notice]'), 'Reschdule attempt notice is not shown');
    99  
   100      await componentA11yAudit(this.element, assert);
   101    });
   102  
   103    test('when the allocation has failed and there is no follow up evaluation, a warning is shown', async function(assert) {
   104      const attempts = 2;
   105  
   106      this.server.create('allocation', 'rescheduled', {
   107        rescheduleAttempts: attempts,
   108        rescheduleSuccess: false,
   109      });
   110  
   111      const lastAllocation = server.schema.allocations.findBy({ nextAllocation: undefined });
   112      lastAllocation.update({
   113        followupEvalId: server.create('evaluation', {
   114          waitUntil: moment()
   115            .add(2, 'hours')
   116            .toDate(),
   117        }).id,
   118      });
   119  
   120      await this.store.findAll('allocation');
   121  
   122      let allocation = this.store
   123        .peekAll('allocation')
   124        .find(alloc => !alloc.get('nextAllocation.content'));
   125      this.set('allocation', allocation);
   126  
   127      await render(commonTemplate);
   128  
   129      assert.ok(
   130        find('[data-test-attempt-notice]'),
   131        'Reschedule notice is shown since the follow up eval says so'
   132      );
   133      assert.notOk(find('[data-test-stop-warning]'), 'Stop warning is not shown');
   134  
   135      await componentA11yAudit(this.element, assert);
   136    });
   137  
   138    test('when the allocation has a next allocation already, it is shown in the timeline', async function(assert) {
   139      const attempts = 2;
   140  
   141      const originalAllocation = this.server.create('allocation', 'rescheduled', {
   142        rescheduleAttempts: attempts,
   143        rescheduleSuccess: true,
   144      });
   145  
   146      await this.store.findAll('allocation');
   147  
   148      const allocation = this.store.peekAll('allocation').findBy('id', originalAllocation.id);
   149  
   150      this.set('allocation', allocation);
   151      await render(commonTemplate);
   152  
   153      assert.ok(
   154        find('[data-test-reschedule-label]').textContent.trim(),
   155        'Next Allocation',
   156        'The first allocation is the next allocation and labeled as such'
   157      );
   158  
   159      assert.equal(
   160        find('[data-test-allocation] [data-test-allocation-link]').textContent.trim(),
   161        allocation.get('nextAllocation.shortId'),
   162        'The next allocation item is for the correct allocation'
   163      );
   164  
   165      assert.equal(
   166        findAll('[data-test-allocation]')[1],
   167        find(`[data-test-allocation="${allocation.id}"]`),
   168        'Second allocation is the current allocation'
   169      );
   170  
   171      assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
   172      assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
   173    });
   174  });