github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/primary-metric/node-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 { find, 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  import { formatScheduledHertz } from 'nomad-ui/utils/units';
    15  
    16  module('Integration | Component | PrimaryMetric::Node', function (hooks) {
    17    setupRenderingTest(hooks);
    18    setupPrimaryMetricMocks(hooks);
    19  
    20    hooks.beforeEach(function () {
    21      fragmentSerializerInitializer(this.owner);
    22      this.store = this.owner.lookup('service:store');
    23      this.server = startMirage();
    24      this.server.create('namespace');
    25      this.server.create('node-pool');
    26      this.server.create('node');
    27    });
    28  
    29    hooks.afterEach(function () {
    30      this.server.shutdown();
    31    });
    32  
    33    const template = hbs`
    34      <PrimaryMetric::Node
    35        @node={{this.resource}}
    36        @metric={{this.metric}} />
    37    `;
    38  
    39    const preload = async (store) => {
    40      await store.findAll('node');
    41    };
    42  
    43    const findResource = (store) => store.peekAll('node').get('firstObject');
    44  
    45    test('Must pass an accessibility audit', async function (assert) {
    46      assert.expect(1);
    47  
    48      await preload(this.store);
    49  
    50      const resource = findResource(this.store);
    51      this.setProperties({ resource, metric: 'cpu' });
    52  
    53      await render(template);
    54      await componentA11yAudit(this.element, assert);
    55    });
    56  
    57    test('When the node has a reserved amount for the metric, a horizontal annotation is shown', async function (assert) {
    58      this.server.create('node', 'reserved', { id: 'withAnnotation' });
    59      await preload(this.store);
    60  
    61      const resource = this.store.peekRecord('node', 'withAnnotation');
    62      this.setProperties({ resource, metric: 'cpu' });
    63  
    64      await render(template);
    65  
    66      assert.ok(find('[data-test-annotation]'));
    67      assert.equal(
    68        find('[data-test-annotation]').textContent.trim(),
    69        `${formatScheduledHertz(resource.reserved.cpu, 'MHz')} reserved`
    70      );
    71    });
    72  
    73    primaryMetric({
    74      template,
    75      preload,
    76      findResource,
    77    });
    78  });