github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/integration/components/job-page/parts/latest-deployment-test.js (about)

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