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