github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/primary-metric/task-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 { 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::Task', 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 const job = this.server.create('job', { 33 groupsCount: 1, 34 groupTaskCount: 3, 35 createAllocations: false, 36 }); 37 38 // Update job > group > task names to match mockTasks 39 job.taskGroups.models[0].tasks.models.forEach((task, index) => { 40 task.update({ name: mockTasks[index].task }); 41 }); 42 43 this.server.create('allocation', { forceRunningClientStatus: true }); 44 }); 45 46 hooks.afterEach(function () { 47 this.server.shutdown(); 48 }); 49 50 const template = hbs` 51 <PrimaryMetric::Task 52 @taskState={{this.resource}} 53 @metric={{this.metric}} /> 54 `; 55 56 const preload = async (store) => { 57 await store.findAll('allocation'); 58 }; 59 60 const findResource = (store) => 61 store.peekAll('allocation').get('firstObject.states.firstObject'); 62 63 test('Must pass an accessibility audit', async function (assert) { 64 assert.expect(1); 65 66 await preload(this.store); 67 68 const resource = findResource(this.store); 69 this.setProperties({ resource, metric: 'cpu' }); 70 71 await render(template); 72 await componentA11yAudit(this.element, assert); 73 }); 74 75 primaryMetric({ 76 template, 77 preload, 78 findResource, 79 }); 80 });