github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/primary-metric/node-test.js (about) 1 import { setupRenderingTest } from 'ember-qunit'; 2 import { module, test } from 'qunit'; 3 import { find, render } from '@ember/test-helpers'; 4 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 5 import hbs from 'htmlbars-inline-precompile'; 6 import { setupPrimaryMetricMocks, primaryMetric } from './primary-metric'; 7 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 8 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 9 import { formatScheduledHertz } from 'nomad-ui/utils/units'; 10 11 module('Integration | Component | PrimaryMetric::Node', function (hooks) { 12 setupRenderingTest(hooks); 13 setupPrimaryMetricMocks(hooks); 14 15 hooks.beforeEach(function () { 16 fragmentSerializerInitializer(this.owner); 17 this.store = this.owner.lookup('service:store'); 18 this.server = startMirage(); 19 this.server.create('namespace'); 20 this.server.create('node'); 21 }); 22 23 hooks.afterEach(function () { 24 this.server.shutdown(); 25 }); 26 27 const template = hbs` 28 <PrimaryMetric::Node 29 @node={{this.resource}} 30 @metric={{this.metric}} /> 31 `; 32 33 const preload = async (store) => { 34 await store.findAll('node'); 35 }; 36 37 const findResource = (store) => store.peekAll('node').get('firstObject'); 38 39 test('Must pass an accessibility audit', async function (assert) { 40 assert.expect(1); 41 42 await preload(this.store); 43 44 const resource = findResource(this.store); 45 this.setProperties({ resource, metric: 'cpu' }); 46 47 await render(template); 48 await componentA11yAudit(this.element, assert); 49 }); 50 51 test('When the node has a reserved amount for the metric, a horizontal annotation is shown', async function (assert) { 52 this.server.create('node', 'reserved', { id: 'withAnnotation' }); 53 await preload(this.store); 54 55 const resource = this.store.peekRecord('node', 'withAnnotation'); 56 this.setProperties({ resource, metric: 'cpu' }); 57 58 await render(template); 59 60 assert.ok(find('[data-test-annotation]')); 61 assert.equal( 62 find('[data-test-annotation]').textContent.trim(), 63 `${formatScheduledHertz(resource.reserved.cpu, 'MHz')} reserved` 64 ); 65 }); 66 67 primaryMetric({ 68 template, 69 preload, 70 findResource, 71 }); 72 });