github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/integration/job-page/parts/placement-failures-test.js (about) 1 import hbs from 'htmlbars-inline-precompile'; 2 import { findAll, find, render } from '@ember/test-helpers'; 3 import { module, test } from 'qunit'; 4 import { setupRenderingTest } from 'ember-qunit'; 5 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 6 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 7 8 module('Integration | Component | job-page/parts/placement-failures', function(hooks) { 9 setupRenderingTest(hooks); 10 11 hooks.beforeEach(function() { 12 fragmentSerializerInitializer(this.owner); 13 window.localStorage.clear(); 14 this.store = this.owner.lookup('service:store'); 15 this.server = startMirage(); 16 this.server.create('namespace'); 17 }); 18 19 hooks.afterEach(function() { 20 this.server.shutdown(); 21 window.localStorage.clear(); 22 }); 23 24 test('when the job has placement failures, they are called out', async function(assert) { 25 this.server.create('job', { failedPlacements: true, createAllocations: false }); 26 await this.store.findAll('job'); 27 28 const job = this.store.peekAll('job').get('firstObject'); 29 await job.reload(); 30 31 this.set('job', job); 32 33 await render(hbs` 34 {{job-page/parts/placement-failures job=job}}) 35 `); 36 37 const failedEvaluation = this.get('job.evaluations') 38 .filterBy('hasPlacementFailures') 39 .sortBy('modifyIndex') 40 .reverse() 41 .get('firstObject'); 42 const failedTGAllocs = failedEvaluation.get('failedTGAllocs'); 43 44 assert.ok(find('[data-test-placement-failures]'), 'Placement failures section found'); 45 46 const taskGroupLabels = findAll('[data-test-placement-failure-task-group]').map(title => 47 title.textContent.trim() 48 ); 49 50 failedTGAllocs.forEach(alloc => { 51 const name = alloc.get('name'); 52 assert.ok( 53 taskGroupLabels.find(label => label.includes(name)), 54 `${name} included in placement failures list` 55 ); 56 assert.ok( 57 taskGroupLabels.find(label => label.includes(alloc.get('coalescedFailures') + 1)), 58 'The number of unplaced allocs = CoalescedFailures + 1' 59 ); 60 }); 61 }); 62 63 test('when the job has no placement failures, the placement failures section is gone', async function(assert) { 64 this.server.create('job', { noFailedPlacements: true, createAllocations: false }); 65 await this.store.findAll('job'); 66 67 const job = this.store.peekAll('job').get('firstObject'); 68 await job.reload(); 69 70 this.set('job', job); 71 72 await render(hbs` 73 {{job-page/parts/placement-failures job=job}}) 74 `); 75 76 assert.notOk(find('[data-test-placement-failures]'), 'Placement failures section not found'); 77 }); 78 });