github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/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      assert.expect(7);
    30  
    31      const attempts = 2;
    32  
    33      this.server.create('allocation', 'rescheduled', {
    34        rescheduleAttempts: attempts,
    35        rescheduleSuccess: true,
    36      });
    37  
    38      await this.store.findAll('allocation');
    39  
    40      const allocation = this.store
    41        .peekAll('allocation')
    42        .find((alloc) => !alloc.get('nextAllocation.content'));
    43  
    44      this.set('allocation', allocation);
    45      await render(commonTemplate);
    46  
    47      assert.equal(
    48        findAll('[data-test-allocation]').length,
    49        attempts + 1,
    50        'Total allocations equals current allocation plus all past allocations'
    51      );
    52      assert.equal(
    53        find('[data-test-allocation]'),
    54        find(`[data-test-allocation="${allocation.id}"]`),
    55        'First allocation is the current allocation'
    56      );
    57  
    58      assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
    59      assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
    60  
    61      assert.equal(
    62        find(
    63          `[data-test-allocation="${allocation.id}"] [data-test-allocation-link]`
    64        ).textContent.trim(),
    65        allocation.get('shortId'),
    66        'The "this" allocation is correct'
    67      );
    68      assert.equal(
    69        find(
    70          `[data-test-allocation="${allocation.id}"] [data-test-allocation-status]`
    71        ).textContent.trim(),
    72        allocation.get('clientStatus'),
    73        'Allocation shows the status'
    74      );
    75  
    76      await componentA11yAudit(this.element, assert);
    77    });
    78  
    79    test('when the allocation has failed and there is a follow up evaluation, a note with a time is shown', async function (assert) {
    80      assert.expect(3);
    81  
    82      const attempts = 2;
    83  
    84      this.server.create('allocation', 'rescheduled', {
    85        rescheduleAttempts: attempts,
    86        rescheduleSuccess: false,
    87      });
    88  
    89      await this.store.findAll('allocation');
    90  
    91      const allocation = this.store
    92        .peekAll('allocation')
    93        .find((alloc) => !alloc.get('nextAllocation.content'));
    94  
    95      this.set('allocation', allocation);
    96      await render(commonTemplate);
    97  
    98      assert.ok(
    99        find('[data-test-stop-warning]'),
   100        'Stop warning is shown since the last allocation failed'
   101      );
   102      assert.notOk(
   103        find('[data-test-attempt-notice]'),
   104        'Reschdule attempt notice is not shown'
   105      );
   106  
   107      await componentA11yAudit(this.element, assert);
   108    });
   109  
   110    test('when the allocation has failed and there is no follow up evaluation, a warning is shown', async function (assert) {
   111      assert.expect(3);
   112  
   113      const attempts = 2;
   114  
   115      this.server.create('allocation', 'rescheduled', {
   116        rescheduleAttempts: attempts,
   117        rescheduleSuccess: false,
   118      });
   119  
   120      const lastAllocation = server.schema.allocations.findBy({
   121        nextAllocation: undefined,
   122      });
   123      lastAllocation.update({
   124        followupEvalId: server.create('evaluation', {
   125          waitUntil: moment().add(2, 'hours').toDate(),
   126        }).id,
   127      });
   128  
   129      await this.store.findAll('allocation');
   130  
   131      let allocation = this.store
   132        .peekAll('allocation')
   133        .find((alloc) => !alloc.get('nextAllocation.content'));
   134      this.set('allocation', allocation);
   135  
   136      await render(commonTemplate);
   137  
   138      assert.ok(
   139        find('[data-test-attempt-notice]'),
   140        'Reschedule notice is shown since the follow up eval says so'
   141      );
   142      assert.notOk(find('[data-test-stop-warning]'), 'Stop warning is not shown');
   143  
   144      await componentA11yAudit(this.element, assert);
   145    });
   146  
   147    test('when the allocation has a next allocation already, it is shown in the timeline', async function (assert) {
   148      const attempts = 2;
   149  
   150      const originalAllocation = this.server.create('allocation', 'rescheduled', {
   151        rescheduleAttempts: attempts,
   152        rescheduleSuccess: true,
   153      });
   154  
   155      await this.store.findAll('allocation');
   156  
   157      const allocation = this.store
   158        .peekAll('allocation')
   159        .findBy('id', originalAllocation.id);
   160  
   161      this.set('allocation', allocation);
   162      await render(commonTemplate);
   163  
   164      assert.equal(
   165        find('[data-test-reschedule-label]').textContent.trim(),
   166        'Next Allocation',
   167        'The first allocation is the next allocation and labeled as such'
   168      );
   169  
   170      assert.equal(
   171        find(
   172          '[data-test-allocation] [data-test-allocation-link]'
   173        ).textContent.trim(),
   174        allocation.get('nextAllocation.shortId'),
   175        'The next allocation item is for the correct allocation'
   176      );
   177  
   178      assert.equal(
   179        findAll('[data-test-allocation]')[1],
   180        find(`[data-test-allocation="${allocation.id}"]`),
   181        'Second allocation is the current allocation'
   182      );
   183  
   184      assert.notOk(find('[data-test-stop-warning]'), 'No stop warning');
   185      assert.notOk(find('[data-test-attempt-notice]'), 'No attempt notice');
   186    });
   187  });