github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/job-page/parts/task-groups-test.js (about)

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