github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/primary-metric/task-test.js (about) 1 import { setupRenderingTest } from 'ember-qunit'; 2 import { module, test } from 'qunit'; 3 import { 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::Task', 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 const job = this.server.create('job', { 27 groupsCount: 1, 28 groupTaskCount: 3, 29 createAllocations: false, 30 }); 31 32 // Update job > group > task names to match mockTasks 33 job.taskGroups.models[0].tasks.models.forEach((task, index) => { 34 task.update({ name: mockTasks[index].task }); 35 }); 36 37 this.server.create('allocation', { forceRunningClientStatus: true }); 38 }); 39 40 hooks.afterEach(function () { 41 this.server.shutdown(); 42 }); 43 44 const template = hbs` 45 <PrimaryMetric::Task 46 @taskState={{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.states.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 primaryMetric({ 70 template, 71 preload, 72 findResource, 73 }); 74 });