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