github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/primary-metric/allocation-test.js (about) 1 import { setupRenderingTest } from 'ember-qunit'; 2 import { module, test } from 'qunit'; 3 import { findAll, 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 10 const mockTasks = [ 11 { task: 'One', reservedCPU: 200, reservedMemory: 500, cpu: [], memory: [] }, 12 { task: 'Two', reservedCPU: 100, reservedMemory: 200, cpu: [], memory: [] }, 13 { task: 'Three', reservedCPU: 300, reservedMemory: 100, cpu: [], memory: [] }, 14 ]; 15 16 module('Integration | Component | PrimaryMetric::Allocation', function (hooks) { 17 setupRenderingTest(hooks); 18 setupPrimaryMetricMocks(hooks, [...mockTasks]); 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'); 26 this.server.create('job', { 27 groupsCount: 1, 28 groupTaskCount: 3, 29 createAllocations: false, 30 }); 31 this.server.create('allocation'); 32 }); 33 34 hooks.afterEach(function () { 35 this.server.shutdown(); 36 }); 37 38 const template = hbs` 39 <PrimaryMetric::Allocation 40 @allocation={{this.resource}} 41 @metric={{this.metric}} /> 42 `; 43 44 const preload = async (store) => { 45 await store.findAll('allocation'); 46 }; 47 48 const findResource = (store) => 49 store.peekAll('allocation').get('firstObject'); 50 51 test('Must pass an accessibility audit', async function (assert) { 52 assert.expect(1); 53 54 await preload(this.store); 55 56 const resource = findResource(this.store); 57 this.setProperties({ resource, metric: 'cpu' }); 58 59 await render(template); 60 await componentA11yAudit(this.element, assert); 61 }); 62 63 test('Each task for the allocation gets its own line', async function (assert) { 64 await preload(this.store); 65 66 const resource = findResource(this.store); 67 this.setProperties({ resource, metric: 'cpu' }); 68 69 await render(template); 70 assert.equal(findAll('[data-test-chart-area]').length, mockTasks.length); 71 }); 72 73 primaryMetric({ 74 template, 75 preload, 76 findResource, 77 }); 78 });