github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/placement-failure-test.js (about) 1 import { find, findAll, render } from '@ember/test-helpers'; 2 import { module, test } from 'qunit'; 3 import { setupRenderingTest } from 'ember-qunit'; 4 import { assign } from '@ember/polyfills'; 5 import hbs from 'htmlbars-inline-precompile'; 6 import cleanWhitespace from '../../utils/clean-whitespace'; 7 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 8 9 module('Integration | Component | placement failures', function (hooks) { 10 setupRenderingTest(hooks); 11 12 const commonTemplate = hbs` 13 <PlacementFailure @taskGroup={{taskGroup}} /> 14 `; 15 16 test('should render the placement failure (basic render)', async function (assert) { 17 assert.expect(12); 18 19 const name = 'Placement Failure'; 20 const failures = 11; 21 this.set( 22 'taskGroup', 23 createFixture( 24 { 25 coalescedFailures: failures - 1, 26 }, 27 name 28 ) 29 ); 30 31 await render(commonTemplate); 32 33 assert.equal( 34 cleanWhitespace( 35 find('[data-test-placement-failure-task-group]').firstChild.wholeText 36 ), 37 name, 38 'Title is rendered with the name of the placement failure' 39 ); 40 assert.equal( 41 parseInt( 42 find('[data-test-placement-failure-coalesced-failures]').textContent 43 ), 44 failures, 45 'Title is rendered correctly with a count of unplaced' 46 ); 47 assert.equal( 48 findAll('[data-test-placement-failure-no-evaluated-nodes]').length, 49 1, 50 'No evaluated nodes message shown' 51 ); 52 assert.equal( 53 findAll('[data-test-placement-failure-no-nodes-available]').length, 54 1, 55 'No nodes in datacenter message shown' 56 ); 57 assert.equal( 58 findAll('[data-test-placement-failure-class-filtered]').length, 59 1, 60 'Class filtered message shown' 61 ); 62 assert.equal( 63 findAll('[data-test-placement-failure-constraint-filtered]').length, 64 1, 65 'Constraint filtered message shown' 66 ); 67 assert.equal( 68 findAll('[data-test-placement-failure-nodes-exhausted]').length, 69 1, 70 'Node exhausted message shown' 71 ); 72 assert.equal( 73 findAll('[data-test-placement-failure-class-exhausted]').length, 74 1, 75 'Class exhausted message shown' 76 ); 77 assert.equal( 78 findAll('[data-test-placement-failure-dimension-exhausted]').length, 79 1, 80 'Dimension exhausted message shown' 81 ); 82 assert.equal( 83 findAll('[data-test-placement-failure-quota-exhausted]').length, 84 1, 85 'Quota exhausted message shown' 86 ); 87 assert.equal( 88 findAll('[data-test-placement-failure-scores]').length, 89 1, 90 'Scores message shown' 91 ); 92 93 await componentA11yAudit(this.element, assert); 94 }); 95 96 test('should render correctly when a node is not evaluated', async function (assert) { 97 assert.expect(3); 98 99 this.set( 100 'taskGroup', 101 createFixture({ 102 nodesEvaluated: 1, 103 nodesExhausted: 0, 104 }) 105 ); 106 107 await render(commonTemplate); 108 109 assert.equal( 110 findAll('[data-test-placement-failure-no-evaluated-nodes]').length, 111 0, 112 'No evaluated nodes message shown' 113 ); 114 assert.equal( 115 findAll('[data-test-placement-failure-nodes-exhausted]').length, 116 0, 117 'Nodes exhausted message NOT shown when there are no nodes exhausted' 118 ); 119 120 await componentA11yAudit(this.element, assert); 121 }); 122 123 function createFixture(obj = {}, name = 'Placement Failure') { 124 return { 125 name: name, 126 placementFailures: assign( 127 { 128 name: name, 129 coalescedFailures: 10, 130 nodesEvaluated: 0, 131 nodesAvailable: { 132 datacenter: 0, 133 }, 134 classFiltered: { 135 filtered: 1, 136 }, 137 constraintFiltered: { 138 'prop = val': 1, 139 }, 140 nodesExhausted: 3, 141 classExhausted: { 142 class: 3, 143 }, 144 dimensionExhausted: { 145 iops: 3, 146 }, 147 quotaExhausted: { 148 quota: 'dimension', 149 }, 150 scores: { 151 name: 3, 152 }, 153 }, 154 obj 155 ), 156 }; 157 } 158 });