github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/job-page/parts/placement-failures-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 /* eslint-disable qunit/require-expect */ 7 /* Mirage fixtures are random so we can't expect a set number of assertions */ 8 import hbs from 'htmlbars-inline-precompile'; 9 import { findAll, find, render } from '@ember/test-helpers'; 10 import { module, test } from 'qunit'; 11 import { setupRenderingTest } from 'ember-qunit'; 12 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 13 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 14 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 15 16 module( 17 'Integration | Component | job-page/parts/placement-failures', 18 function (hooks) { 19 setupRenderingTest(hooks); 20 21 hooks.beforeEach(function () { 22 fragmentSerializerInitializer(this.owner); 23 window.localStorage.clear(); 24 this.store = this.owner.lookup('service:store'); 25 this.server = startMirage(); 26 this.server.create('namespace'); 27 this.server.create('node-pool'); 28 }); 29 30 hooks.afterEach(function () { 31 this.server.shutdown(); 32 window.localStorage.clear(); 33 }); 34 35 test('when the job has placement failures, they are called out', async function (assert) { 36 this.server.create('job', { 37 failedPlacements: true, 38 createAllocations: false, 39 }); 40 await this.store.findAll('job'); 41 42 const job = this.store.peekAll('job').get('firstObject'); 43 await job.reload(); 44 45 this.set('job', job); 46 47 await render(hbs` 48 <JobPage::Parts::PlacementFailures @job={{job}} />) 49 `); 50 51 const failedEvaluation = this.get('job.evaluations') 52 .filterBy('hasPlacementFailures') 53 .sortBy('modifyIndex') 54 .reverse() 55 .get('firstObject'); 56 const failedTGAllocs = failedEvaluation.get('failedTGAllocs'); 57 58 assert.ok( 59 find('[data-test-placement-failures]'), 60 'Placement failures section found' 61 ); 62 63 const taskGroupLabels = findAll( 64 '[data-test-placement-failure-task-group]' 65 ).map((title) => title.textContent.trim()); 66 67 failedTGAllocs.forEach((alloc) => { 68 const name = alloc.get('name'); 69 assert.ok( 70 taskGroupLabels.find((label) => label.includes(name)), 71 `${name} included in placement failures list` 72 ); 73 assert.ok( 74 taskGroupLabels.find((label) => 75 label.includes(alloc.get('coalescedFailures') + 1) 76 ), 77 'The number of unplaced allocs = CoalescedFailures + 1' 78 ); 79 }); 80 81 await componentA11yAudit(this.element, assert); 82 }); 83 84 test('when the job has no placement failures, the placement failures section is gone', async function (assert) { 85 this.server.create('job', { 86 noFailedPlacements: true, 87 createAllocations: false, 88 }); 89 await this.store.findAll('job'); 90 91 const job = this.store.peekAll('job').get('firstObject'); 92 await job.reload(); 93 94 this.set('job', job); 95 96 await render(hbs` 97 <JobPage::Parts::PlacementFailures @job={{job}} />) 98 `); 99 100 assert.notOk( 101 find('[data-test-placement-failures]'), 102 'Placement failures section not found' 103 ); 104 }); 105 } 106 );