github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/integration/reschedule-event-timeline-test.js (about)

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