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