github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/integration/job-page/parts/latest-deployment-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupRenderingTest } from 'ember-qunit'; 3 import { click, find, render } from '@ember/test-helpers'; 4 import hbs from 'htmlbars-inline-precompile'; 5 import moment from 'moment'; 6 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 7 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 8 9 module('Integration | Component | job-page/parts/latest-deployment', function(hooks) { 10 setupRenderingTest(hooks); 11 12 hooks.beforeEach(function() { 13 fragmentSerializerInitializer(this.owner); 14 window.localStorage.clear(); 15 this.store = this.owner.lookup('service:store'); 16 this.server = startMirage(); 17 this.server.create('namespace'); 18 }); 19 20 hooks.afterEach(function() { 21 this.server.shutdown(); 22 window.localStorage.clear(); 23 }); 24 25 test('there is no latest deployment section when the job has no deployments', async function(assert) { 26 this.server.create('job', { 27 type: 'service', 28 noDeployments: true, 29 createAllocations: false, 30 }); 31 32 await this.store.findAll('job'); 33 34 this.set('job', this.store.peekAll('job').get('firstObject')); 35 await render(hbs` 36 {{job-page/parts/latest-deployment job=job}}) 37 `); 38 39 assert.notOk(find('[data-test-active-deployment]'), 'No active deployment'); 40 }); 41 42 test('the latest deployment section shows up for the currently running deployment', async function(assert) { 43 this.server.create('job', { 44 type: 'service', 45 createAllocations: false, 46 activeDeployment: true, 47 }); 48 49 await this.store.findAll('job'); 50 51 this.set('job', this.store.peekAll('job').get('firstObject')); 52 await render(hbs` 53 {{job-page/parts/latest-deployment job=job}} 54 `); 55 56 const deployment = await this.get('job.latestDeployment'); 57 const version = await deployment.get('version'); 58 59 assert.ok(find('[data-test-active-deployment]'), 'Active deployment'); 60 assert.ok( 61 find('[data-test-active-deployment]').classList.contains('is-info'), 62 'Running deployment gets the is-info class' 63 ); 64 assert.equal( 65 find('[data-test-active-deployment-stat="id"]').textContent.trim(), 66 deployment.get('shortId'), 67 'The active deployment is the most recent running deployment' 68 ); 69 70 assert.equal( 71 find('[data-test-active-deployment-stat="submit-time"]').textContent.trim(), 72 moment(version.get('submitTime')).fromNow(), 73 'Time since the job was submitted is in the active deployment header' 74 ); 75 76 assert.equal( 77 find('[data-test-deployment-metric="canaries"]').textContent.trim(), 78 `${deployment.get('placedCanaries')} / ${deployment.get('desiredCanaries')}`, 79 'Canaries, both places and desired, are in the metrics' 80 ); 81 82 assert.equal( 83 find('[data-test-deployment-metric="placed"]').textContent.trim(), 84 deployment.get('placedAllocs'), 85 'Placed allocs aggregates across task groups' 86 ); 87 88 assert.equal( 89 find('[data-test-deployment-metric="desired"]').textContent.trim(), 90 deployment.get('desiredTotal'), 91 'Desired allocs aggregates across task groups' 92 ); 93 94 assert.equal( 95 find('[data-test-deployment-metric="healthy"]').textContent.trim(), 96 deployment.get('healthyAllocs'), 97 'Healthy allocs aggregates across task groups' 98 ); 99 100 assert.equal( 101 find('[data-test-deployment-metric="unhealthy"]').textContent.trim(), 102 deployment.get('unhealthyAllocs'), 103 'Unhealthy allocs aggregates across task groups' 104 ); 105 106 assert.equal( 107 find('[data-test-deployment-notification]').textContent.trim(), 108 deployment.get('statusDescription'), 109 'Status description is in the metrics block' 110 ); 111 }); 112 113 test('when there is no running deployment, the latest deployment section shows up for the last deployment', async function(assert) { 114 this.server.create('job', { 115 type: 'service', 116 createAllocations: false, 117 noActiveDeployment: true, 118 }); 119 120 await this.store.findAll('job'); 121 122 this.set('job', this.store.peekAll('job').get('firstObject')); 123 await render(hbs` 124 {{job-page/parts/latest-deployment job=job}} 125 `); 126 127 assert.ok(find('[data-test-active-deployment]'), 'Active deployment'); 128 assert.notOk( 129 find('[data-test-active-deployment]').classList.contains('is-info'), 130 'Non-running deployment does not get the is-info class' 131 ); 132 }); 133 134 test('the latest deployment section can be expanded to show task groups and allocations', async function(assert) { 135 this.server.create('node'); 136 this.server.create('job', { type: 'service', activeDeployment: true }); 137 138 await this.store.findAll('job'); 139 140 this.set('job', this.store.peekAll('job').get('firstObject')); 141 await render(hbs` 142 {{job-page/parts/latest-deployment job=job}} 143 `); 144 145 assert.notOk(find('[data-test-deployment-task-groups]'), 'Task groups not found'); 146 assert.notOk(find('[data-test-deployment-allocations]'), 'Allocations not found'); 147 148 await click('[data-test-deployment-toggle-details]'); 149 150 assert.ok(find('[data-test-deployment-task-groups]'), 'Task groups found'); 151 assert.ok(find('[data-test-deployment-allocations]'), 'Allocations found'); 152 }); 153 154 test('each task group in the expanded task group section shows task group details', async function(assert) { 155 this.server.create('node'); 156 this.server.create('job', { type: 'service', activeDeployment: true }); 157 158 await this.store.findAll('job'); 159 160 const job = this.store.peekAll('job').get('firstObject'); 161 162 this.set('job', job); 163 await render(hbs` 164 {{job-page/parts/latest-deployment job=job}} 165 `); 166 167 await click('[data-test-deployment-toggle-details]'); 168 169 const task = job.get('runningDeployment.taskGroupSummaries.firstObject'); 170 const findForTaskGroup = selector => find(`[data-test-deployment-task-group-${selector}]`); 171 assert.equal(findForTaskGroup('name').textContent.trim(), task.get('name')); 172 assert.equal( 173 findForTaskGroup('progress-deadline').textContent.trim(), 174 moment(task.get('requireProgressBy')).format("MMM DD, 'YY HH:mm:ss ZZ") 175 ); 176 }); 177 });