github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/integration/job-page/parts/summary-test.js (about) 1 import hbs from 'htmlbars-inline-precompile'; 2 import { find, click, 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/summary', 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('jobs with children use the children diagram', async function(assert) { 25 this.server.create('job', 'periodic', { 26 createAllocations: false, 27 }); 28 29 await this.store.findAll('job'); 30 31 this.set('job', this.store.peekAll('job').get('firstObject')); 32 33 await render(hbs` 34 {{job-page/parts/summary job=job}} 35 `); 36 37 assert.ok(find('[data-test-children-status-bar]'), 'Children status bar found'); 38 assert.notOk(find('[data-test-allocation-status-bar]'), 'Allocation status bar not found'); 39 }); 40 41 test('jobs without children use the allocations diagram', async function(assert) { 42 this.server.create('job', { 43 createAllocations: false, 44 }); 45 46 await this.store.findAll('job'); 47 48 this.set('job', this.store.peekAll('job').get('firstObject')); 49 50 await render(hbs` 51 {{job-page/parts/summary job=job}} 52 `); 53 54 assert.ok(find('[data-test-allocation-status-bar]'), 'Allocation status bar found'); 55 assert.notOk(find('[data-test-children-status-bar]'), 'Children status bar not found'); 56 }); 57 58 test('the allocations diagram lists all allocation status figures', async function(assert) { 59 this.server.create('job', { 60 createAllocations: false, 61 }); 62 63 await this.store.findAll('job'); 64 65 this.set('job', this.store.peekAll('job').get('firstObject')); 66 67 await render(hbs` 68 {{job-page/parts/summary job=job}} 69 `); 70 71 assert.equal( 72 find('[data-test-legend-value="queued"]').textContent, 73 this.get('job.queuedAllocs'), 74 `${this.get('job.queuedAllocs')} are queued` 75 ); 76 77 assert.equal( 78 find('[data-test-legend-value="starting"]').textContent, 79 this.get('job.startingAllocs'), 80 `${this.get('job.startingAllocs')} are starting` 81 ); 82 83 assert.equal( 84 find('[data-test-legend-value="running"]').textContent, 85 this.get('job.runningAllocs'), 86 `${this.get('job.runningAllocs')} are running` 87 ); 88 89 assert.equal( 90 find('[data-test-legend-value="complete"]').textContent, 91 this.get('job.completeAllocs'), 92 `${this.get('job.completeAllocs')} are complete` 93 ); 94 95 assert.equal( 96 find('[data-test-legend-value="failed"]').textContent, 97 this.get('job.failedAllocs'), 98 `${this.get('job.failedAllocs')} are failed` 99 ); 100 101 assert.equal( 102 find('[data-test-legend-value="lost"]').textContent, 103 this.get('job.lostAllocs'), 104 `${this.get('job.lostAllocs')} are lost` 105 ); 106 }); 107 108 test('the children diagram lists all children status figures', async function(assert) { 109 this.server.create('job', 'periodic', { 110 createAllocations: false, 111 }); 112 113 await this.store.findAll('job'); 114 115 this.set('job', this.store.peekAll('job').get('firstObject')); 116 117 await render(hbs` 118 {{job-page/parts/summary job=job}} 119 `); 120 121 assert.equal( 122 find('[data-test-legend-value="queued"]').textContent, 123 this.get('job.pendingChildren'), 124 `${this.get('job.pendingChildren')} are pending` 125 ); 126 127 assert.equal( 128 find('[data-test-legend-value="running"]').textContent, 129 this.get('job.runningChildren'), 130 `${this.get('job.runningChildren')} are running` 131 ); 132 133 assert.equal( 134 find('[data-test-legend-value="complete"]').textContent, 135 this.get('job.deadChildren'), 136 `${this.get('job.deadChildren')} are dead` 137 ); 138 }); 139 140 test('the summary block can be collapsed', async function(assert) { 141 this.server.create('job', { 142 createAllocations: false, 143 }); 144 145 await this.store.findAll('job'); 146 147 this.set('job', this.store.peekAll('job').get('firstObject')); 148 149 await render(hbs` 150 {{job-page/parts/summary job=job}} 151 `); 152 153 await click('[data-test-accordion-toggle]'); 154 155 assert.notOk(find('[data-test-accordion-body]'), 'No accordion body'); 156 assert.notOk(find('[data-test-legend]'), 'No legend'); 157 }); 158 159 test('when collapsed, the summary block includes an inline version of the chart', async function(assert) { 160 this.server.create('job', { 161 createAllocations: false, 162 }); 163 164 await this.store.findAll('job'); 165 166 await this.set('job', this.store.peekAll('job').get('firstObject')); 167 168 await render(hbs` 169 {{job-page/parts/summary job=job}} 170 `); 171 172 await click('[data-test-accordion-toggle]'); 173 174 assert.ok(find('[data-test-allocation-status-bar]'), 'Allocation bar still existed'); 175 assert.ok( 176 find('.inline-chart [data-test-allocation-status-bar]'), 177 'Allocation bar is rendered in an inline-chart container' 178 ); 179 }); 180 181 test('the collapsed/expanded state is persisted to localStorage', async function(assert) { 182 this.server.create('job', { 183 createAllocations: false, 184 }); 185 186 await this.store.findAll('job'); 187 188 this.set('job', this.store.peekAll('job').get('firstObject')); 189 190 await render(hbs` 191 {{job-page/parts/summary job=job}} 192 `); 193 194 assert.notOk(window.localStorage.nomadExpandJobSummary, 'No value in localStorage yet'); 195 await click('[data-test-accordion-toggle]'); 196 197 assert.equal( 198 window.localStorage.nomadExpandJobSummary, 199 'false', 200 'Value is stored for the collapsed state' 201 ); 202 }); 203 204 test('the collapsed/expanded state from localStorage is used for the initial state when available', async function(assert) { 205 this.server.create('job', { 206 createAllocations: false, 207 }); 208 209 await this.store.findAll('job'); 210 211 window.localStorage.nomadExpandJobSummary = 'false'; 212 213 this.set('job', this.store.peekAll('job').get('firstObject')); 214 215 await render(hbs` 216 {{job-page/parts/summary job=job}} 217 `); 218 219 assert.ok(find('[data-test-allocation-status-bar]'), 'Allocation bar still existed'); 220 assert.ok( 221 find('.inline-chart [data-test-allocation-status-bar]'), 222 'Allocation bar is rendered in an inline-chart container' 223 ); 224 225 await click('[data-test-accordion-toggle]'); 226 227 assert.equal( 228 window.localStorage.nomadExpandJobSummary, 229 'true', 230 'localStorage value still toggles' 231 ); 232 assert.ok(find('[data-test-accordion-body]'), 'Summary still expands'); 233 }); 234 });