github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/primary-metric/allocation-test.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import { setupRenderingTest } from 'ember-qunit';
     7  import { module, test } from 'qunit';
     8  import { findAll, render } from '@ember/test-helpers';
     9  import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
    10  import hbs from 'htmlbars-inline-precompile';
    11  import { setupPrimaryMetricMocks, primaryMetric } from './primary-metric';
    12  import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
    13  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
    14  
    15  const mockTasks = [
    16    { task: 'One', reservedCPU: 200, reservedMemory: 500, cpu: [], memory: [] },
    17    { task: 'Two', reservedCPU: 100, reservedMemory: 200, cpu: [], memory: [] },
    18    { task: 'Three', reservedCPU: 300, reservedMemory: 100, cpu: [], memory: [] },
    19  ];
    20  
    21  module('Integration | Component | PrimaryMetric::Allocation', function (hooks) {
    22    setupRenderingTest(hooks);
    23    setupPrimaryMetricMocks(hooks, [...mockTasks]);
    24  
    25    hooks.beforeEach(function () {
    26      fragmentSerializerInitializer(this.owner);
    27      this.store = this.owner.lookup('service:store');
    28      this.server = startMirage();
    29      this.server.create('namespace');
    30      this.server.create('node-pool');
    31      this.server.create('node');
    32      this.server.create('job', {
    33        groupsCount: 1,
    34        groupTaskCount: 3,
    35        createAllocations: false,
    36      });
    37      this.server.create('allocation');
    38    });
    39  
    40    hooks.afterEach(function () {
    41      this.server.shutdown();
    42    });
    43  
    44    const template = hbs`
    45      <PrimaryMetric::Allocation
    46        @allocation={{this.resource}}
    47        @metric={{this.metric}} />
    48    `;
    49  
    50    const preload = async (store) => {
    51      await store.findAll('allocation');
    52    };
    53  
    54    const findResource = (store) =>
    55      store.peekAll('allocation').get('firstObject');
    56  
    57    test('Must pass an accessibility audit', async function (assert) {
    58      assert.expect(1);
    59  
    60      await preload(this.store);
    61  
    62      const resource = findResource(this.store);
    63      this.setProperties({ resource, metric: 'cpu' });
    64  
    65      await render(template);
    66      await componentA11yAudit(this.element, assert);
    67    });
    68  
    69    test('Each task for the allocation gets its own line', async function (assert) {
    70      await preload(this.store);
    71  
    72      const resource = findResource(this.store);
    73      this.setProperties({ resource, metric: 'cpu' });
    74  
    75      await render(template);
    76      assert.equal(findAll('[data-test-chart-area]').length, mockTasks.length);
    77    });
    78  
    79    primaryMetric({
    80      template,
    81      preload,
    82      findResource,
    83    });
    84  });