github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/integration/job-page/parts/latest-deployment-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 { click, find } from 'ember-native-dom-helpers';
     5  import hbs from 'htmlbars-inline-precompile';
     6  import moment from 'moment';
     7  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     8  import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
     9  
    10  module('Integration | Component | job-page/parts/latest-deployment', function(hooks) {
    11    setupRenderingTest(hooks);
    12  
    13    hooks.beforeEach(function() {
    14      fragmentSerializerInitializer(this.owner);
    15      window.localStorage.clear();
    16      this.store = this.owner.lookup('service:store');
    17      this.server = startMirage();
    18      this.server.create('namespace');
    19    });
    20  
    21    hooks.afterEach(function() {
    22      this.server.shutdown();
    23      window.localStorage.clear();
    24    });
    25  
    26    test('there is no latest deployment section when the job has no deployments', function(assert) {
    27      this.server.create('job', {
    28        type: 'service',
    29        noDeployments: true,
    30        createAllocations: false,
    31      });
    32  
    33      this.store.findAll('job');
    34  
    35      return settled().then(async () => {
    36        this.set('job', this.store.peekAll('job').get('firstObject'));
    37        await render(hbs`
    38          {{job-page/parts/latest-deployment job=job}})
    39        `);
    40  
    41        return settled().then(() => {
    42          assert.notOk(find('[data-test-active-deployment]'), 'No active deployment');
    43        });
    44      });
    45    });
    46  
    47    test('the latest deployment section shows up for the currently running deployment', function(assert) {
    48      this.server.create('job', {
    49        type: 'service',
    50        createAllocations: false,
    51        activeDeployment: true,
    52      });
    53  
    54      this.store.findAll('job');
    55  
    56      return settled().then(async () => {
    57        this.set('job', this.store.peekAll('job').get('firstObject'));
    58        await render(hbs`
    59          {{job-page/parts/latest-deployment job=job}}
    60        `);
    61  
    62        return settled().then(() => {
    63          const deployment = this.get('job.latestDeployment');
    64          const version = deployment.get('version');
    65  
    66          assert.ok(find('[data-test-active-deployment]'), 'Active deployment');
    67          assert.ok(
    68            find('[data-test-active-deployment]').classList.contains('is-info'),
    69            'Running deployment gets the is-info class'
    70          );
    71          assert.equal(
    72            find('[data-test-active-deployment-stat="id"]').textContent.trim(),
    73            deployment.get('shortId'),
    74            'The active deployment is the most recent running deployment'
    75          );
    76  
    77          assert.equal(
    78            find('[data-test-active-deployment-stat="submit-time"]').textContent.trim(),
    79            moment(version.get('submitTime')).fromNow(),
    80            'Time since the job was submitted is in the active deployment header'
    81          );
    82  
    83          assert.equal(
    84            find('[data-test-deployment-metric="canaries"]').textContent.trim(),
    85            `${deployment.get('placedCanaries')} / ${deployment.get('desiredCanaries')}`,
    86            'Canaries, both places and desired, are in the metrics'
    87          );
    88  
    89          assert.equal(
    90            find('[data-test-deployment-metric="placed"]').textContent.trim(),
    91            deployment.get('placedAllocs'),
    92            'Placed allocs aggregates across task groups'
    93          );
    94  
    95          assert.equal(
    96            find('[data-test-deployment-metric="desired"]').textContent.trim(),
    97            deployment.get('desiredTotal'),
    98            'Desired allocs aggregates across task groups'
    99          );
   100  
   101          assert.equal(
   102            find('[data-test-deployment-metric="healthy"]').textContent.trim(),
   103            deployment.get('healthyAllocs'),
   104            'Healthy allocs aggregates across task groups'
   105          );
   106  
   107          assert.equal(
   108            find('[data-test-deployment-metric="unhealthy"]').textContent.trim(),
   109            deployment.get('unhealthyAllocs'),
   110            'Unhealthy allocs aggregates across task groups'
   111          );
   112  
   113          assert.equal(
   114            find('[data-test-deployment-notification]').textContent.trim(),
   115            deployment.get('statusDescription'),
   116            'Status description is in the metrics block'
   117          );
   118        });
   119      });
   120    });
   121  
   122    test('when there is no running deployment, the latest deployment section shows up for the last deployment', function(assert) {
   123      this.server.create('job', {
   124        type: 'service',
   125        createAllocations: false,
   126        noActiveDeployment: true,
   127      });
   128  
   129      this.store.findAll('job');
   130  
   131      return settled().then(async () => {
   132        this.set('job', this.store.peekAll('job').get('firstObject'));
   133        await render(hbs`
   134          {{job-page/parts/latest-deployment job=job}}
   135        `);
   136  
   137        return settled().then(() => {
   138          assert.ok(find('[data-test-active-deployment]'), 'Active deployment');
   139          assert.notOk(
   140            find('[data-test-active-deployment]').classList.contains('is-info'),
   141            'Non-running deployment does not get the is-info class'
   142          );
   143        });
   144      });
   145    });
   146  
   147    test('the latest deployment section can be expanded to show task groups and allocations', function(assert) {
   148      this.server.create('node');
   149      this.server.create('job', { type: 'service', activeDeployment: true });
   150  
   151      this.store.findAll('job');
   152  
   153      return settled().then(async () => {
   154        this.set('job', this.store.peekAll('job').get('firstObject'));
   155        await render(hbs`
   156          {{job-page/parts/latest-deployment job=job}}
   157        `);
   158  
   159        return settled().then(() => {
   160          assert.notOk(find('[data-test-deployment-task-groups]'), 'Task groups not found');
   161          assert.notOk(find('[data-test-deployment-allocations]'), 'Allocations not found');
   162  
   163          click('[data-test-deployment-toggle-details]');
   164  
   165          return settled().then(() => {
   166            assert.ok(find('[data-test-deployment-task-groups]'), 'Task groups found');
   167            assert.ok(find('[data-test-deployment-allocations]'), 'Allocations found');
   168          });
   169        });
   170      });
   171    });
   172  
   173    test('each task group in the expanded task group section shows task group details', function(assert) {
   174      this.server.create('node');
   175      this.server.create('job', { type: 'service', activeDeployment: true });
   176  
   177      this.store.findAll('job');
   178  
   179      return settled().then(async () => {
   180        const job = this.store.peekAll('job').get('firstObject');
   181  
   182        this.set('job', job);
   183        await render(hbs`
   184          {{job-page/parts/latest-deployment job=job}}
   185        `);
   186  
   187        return settled()
   188          .then(() => {
   189            click('[data-test-deployment-toggle-details]');
   190            return settled();
   191          })
   192          .then(() => {
   193            const task = job.get('runningDeployment.taskGroupSummaries.firstObject');
   194            const findForTaskGroup = selector =>
   195              find(`[data-test-deployment-task-group-${selector}]`);
   196            assert.equal(findForTaskGroup('name').textContent.trim(), task.get('name'));
   197            assert.equal(
   198              findForTaskGroup('progress-deadline').textContent.trim(),
   199              moment(task.get('requireProgressBy')).format("MMM DD, 'YY HH:mm:ss ZZ")
   200            );
   201          });
   202      });
   203    });
   204  });