github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/job-page/parts/task-groups-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { assign } from '@ember/polyfills';
     7  import hbs from 'htmlbars-inline-precompile';
     8  import { findAll, find, render } from '@ember/test-helpers';
     9  import { module, test } from 'qunit';
    10  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
    11  import { setupRenderingTest } from 'ember-qunit';
    12  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
    13  import {
    14    formatScheduledHertz,
    15    formatScheduledBytes,
    16  } from 'nomad-ui/utils/units';
    17  
    18  module(
    19    'Integration | Component | job-page/parts/task-groups',
    20    function (hooks) {
    21      setupRenderingTest(hooks);
    22  
    23      hooks.beforeEach(function () {
    24        window.localStorage.clear();
    25        this.store = this.owner.lookup('service:store');
    26        this.server = startMirage();
    27        this.server.create('namespace');
    28        this.server.create('node-pool');
    29      });
    30  
    31      hooks.afterEach(function () {
    32        this.server.shutdown();
    33      });
    34  
    35      const props = (job, options = {}) =>
    36        assign(
    37          {
    38            job,
    39            sortProperty: 'name',
    40            sortDescending: true,
    41          },
    42          options
    43        );
    44  
    45      test('the job detail page should list all task groups', async function (assert) {
    46        assert.expect(2);
    47  
    48        this.server.create('job', {
    49          createAllocations: false,
    50        });
    51  
    52        await this.store.findAll('job').then((jobs) => {
    53          jobs.forEach((job) => job.reload());
    54        });
    55  
    56        const job = this.store.peekAll('job').get('firstObject');
    57        this.setProperties(props(job));
    58  
    59        await render(hbs`
    60        <JobPage::Parts::TaskGroups
    61          @job={{this.job}}
    62          @sortProperty={{this.sortProperty}}
    63          @sortDescending={{this.sortDescending}}
    64        />
    65      `);
    66  
    67        assert.equal(
    68          findAll('[data-test-task-group]').length,
    69          job.get('taskGroups.length'),
    70          'One row per task group'
    71        );
    72  
    73        await componentA11yAudit(this.element, assert);
    74      });
    75  
    76      test('each row in the task group table should show basic information about the task group', async function (assert) {
    77        this.server.create('job', {
    78          createAllocations: false,
    79        });
    80  
    81        const job = await this.store.findAll('job').then(async (jobs) => {
    82          return await jobs.get('firstObject').reload();
    83        });
    84  
    85        const taskGroups = await job.get('taskGroups');
    86        const taskGroup = taskGroups.sortBy('name').reverse().get('firstObject');
    87  
    88        this.setProperties(props(job));
    89  
    90        await render(hbs`
    91        <JobPage::Parts::TaskGroups
    92          @job={{this.job}}
    93          @sortProperty={{this.sortProperty}}
    94          @sortDescending={{this.sortDescending}}
    95        />
    96      `);
    97  
    98        const taskGroupRow = find('[data-test-task-group]');
    99  
   100        assert.equal(
   101          taskGroupRow
   102            .querySelector('[data-test-task-group-name]')
   103            .textContent.trim(),
   104          taskGroup.get('name'),
   105          'Name'
   106        );
   107        assert.equal(
   108          taskGroupRow
   109            .querySelector('[data-test-task-group-count]')
   110            .textContent.trim(),
   111          taskGroup.get('count'),
   112          'Count'
   113        );
   114        assert.equal(
   115          taskGroupRow
   116            .querySelector('[data-test-task-group-volume]')
   117            .textContent.trim(),
   118          taskGroup.get('volumes.length') ? 'Yes' : '',
   119          'Volumes'
   120        );
   121        assert.equal(
   122          taskGroupRow
   123            .querySelector('[data-test-task-group-cpu]')
   124            .textContent.trim(),
   125          `${formatScheduledHertz(taskGroup.get('reservedCPU'), 'MHz')}`,
   126          'Reserved CPU'
   127        );
   128        assert.equal(
   129          taskGroupRow
   130            .querySelector('[data-test-task-group-mem]')
   131            .textContent.trim(),
   132          `${formatScheduledBytes(taskGroup.get('reservedMemory'), 'MiB')}`,
   133          'Reserved Memory'
   134        );
   135        assert.equal(
   136          taskGroupRow
   137            .querySelector('[data-test-task-group-disk]')
   138            .textContent.trim(),
   139          `${formatScheduledBytes(
   140            taskGroup.get('reservedEphemeralDisk'),
   141            'MiB'
   142          )}`,
   143          'Reserved Disk'
   144        );
   145      });
   146    }
   147  );