github.com/emate/nomad@v0.8.2-wo-binpacking/ui/tests/acceptance/task-detail-test.js (about) 1 import { click, findAll, currentURL, find, visit } from 'ember-native-dom-helpers'; 2 import { test } from 'qunit'; 3 import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance'; 4 import moment from 'moment'; 5 import ipParts from 'nomad-ui/utils/ip-parts'; 6 7 let allocation; 8 let task; 9 10 moduleForAcceptance('Acceptance | task detail', { 11 beforeEach() { 12 server.create('agent'); 13 server.create('node'); 14 server.create('job', { createAllocations: false }); 15 allocation = server.create('allocation', 'withTaskWithPorts'); 16 task = server.db.taskStates.where({ allocationId: allocation.id })[0]; 17 18 visit(`/allocations/${allocation.id}/${task.name}`); 19 }, 20 }); 21 22 test('/allocation/:id/:task_name should name the task and list high-level task information', function(assert) { 23 assert.ok(find('[data-test-title]').textContent.includes(task.name), 'Task name'); 24 assert.ok(find('[data-test-state]').textContent.includes(task.state), 'Task state'); 25 26 assert.ok( 27 find('[data-test-started-at]').textContent.includes( 28 moment(task.startedAt).format('MM/DD/YY HH:mm:ss') 29 ), 30 'Task started at' 31 ); 32 }); 33 34 test('breadcrumbs match jobs / job / task group / allocation / task', function(assert) { 35 const { jobId, taskGroup } = allocation; 36 const job = server.db.jobs.find(jobId); 37 38 const shortId = allocation.id.split('-')[0]; 39 40 assert.equal( 41 find('[data-test-breadcrumb="Jobs"]').textContent.trim(), 42 'Jobs', 43 'Jobs is the first breadcrumb' 44 ); 45 assert.equal( 46 find(`[data-test-breadcrumb="${job.name}"]`).textContent.trim(), 47 job.name, 48 'Job is the second breadcrumb' 49 ); 50 assert.equal( 51 find(`[data-test-breadcrumb="${taskGroup}`).textContent.trim(), 52 taskGroup, 53 'Task Group is the third breadcrumb' 54 ); 55 assert.equal( 56 find(`[data-test-breadcrumb="${shortId}"]`).textContent.trim(), 57 shortId, 58 'Allocation short id is the fourth breadcrumb' 59 ); 60 assert.equal( 61 find(`[data-test-breadcrumb="${task.name}"]`).textContent.trim(), 62 task.name, 63 'Task name is the fifth breadcrumb' 64 ); 65 66 click('[data-test-breadcrumb="Jobs"]'); 67 andThen(() => { 68 assert.equal(currentURL(), '/jobs', 'Jobs breadcrumb links correctly'); 69 }); 70 andThen(() => { 71 visit(`/allocations/${allocation.id}/${task.name}`); 72 }); 73 andThen(() => { 74 click(`[data-test-breadcrumb="${job.name}"]`); 75 }); 76 andThen(() => { 77 assert.equal(currentURL(), `/jobs/${job.id}`, 'Job breadcrumb links correctly'); 78 }); 79 andThen(() => { 80 visit(`/allocations/${allocation.id}/${task.name}`); 81 }); 82 andThen(() => { 83 click(`[data-test-breadcrumb="${taskGroup}"]`); 84 }); 85 andThen(() => { 86 assert.equal( 87 currentURL(), 88 `/jobs/${job.id}/${taskGroup}`, 89 'Task Group breadcrumb links correctly' 90 ); 91 }); 92 andThen(() => { 93 visit(`/allocations/${allocation.id}/${task.name}`); 94 }); 95 andThen(() => { 96 click(`[data-test-breadcrumb="${shortId}"]`); 97 }); 98 andThen(() => { 99 assert.equal( 100 currentURL(), 101 `/allocations/${allocation.id}`, 102 'Allocations breadcrumb links correctly' 103 ); 104 }); 105 }); 106 107 test('the addresses table lists all reserved and dynamic ports', function(assert) { 108 const taskResources = allocation.taskResourcesIds 109 .map(id => server.db.taskResources.find(id)) 110 .find(resources => resources.name === task.name); 111 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 112 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 113 const addresses = reservedPorts.concat(dynamicPorts); 114 115 assert.equal( 116 findAll('[data-test-task-address]').length, 117 addresses.length, 118 'All addresses are listed' 119 ); 120 }); 121 122 test('each address row shows the label and value of the address', function(assert) { 123 const node = server.db.nodes.find(allocation.nodeId); 124 const taskResources = allocation.taskResourcesIds 125 .map(id => server.db.taskResources.find(id)) 126 .findBy('name', task.name); 127 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 128 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 129 const address = reservedPorts.concat(dynamicPorts).sortBy('Label')[0]; 130 131 const addressRow = find('[data-test-task-address]'); 132 assert.equal( 133 addressRow.querySelector('[data-test-task-address-is-dynamic]').textContent.trim(), 134 reservedPorts.includes(address) ? 'No' : 'Yes', 135 'Dynamic port is denoted as such' 136 ); 137 assert.equal( 138 addressRow.querySelector('[data-test-task-address-name]').textContent.trim(), 139 address.Label, 140 'Label' 141 ); 142 assert.equal( 143 addressRow.querySelector('[data-test-task-address-address]').textContent.trim(), 144 `${ipParts(node.httpAddr).address}:${address.Value}`, 145 'Value' 146 ); 147 }); 148 149 test('the events table lists all recent events', function(assert) { 150 const events = server.db.taskEvents.where({ taskStateId: task.id }); 151 152 assert.equal( 153 findAll('[data-test-task-event]').length, 154 events.length, 155 `Lists ${events.length} events` 156 ); 157 }); 158 159 test('each recent event should list the time, type, and description of the event', function(assert) { 160 const event = server.db.taskEvents.where({ taskStateId: task.id })[0]; 161 const recentEvent = findAll('[data-test-task-event]').get('lastObject'); 162 163 assert.equal( 164 recentEvent.querySelector('[data-test-task-event-time]').textContent.trim(), 165 moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'), 166 'Event timestamp' 167 ); 168 assert.equal( 169 recentEvent.querySelector('[data-test-task-event-type]').textContent.trim(), 170 event.type, 171 'Event type' 172 ); 173 assert.equal( 174 recentEvent.querySelector('[data-test-task-event-message]').textContent.trim(), 175 event.displayMessage, 176 'Event message' 177 ); 178 }); 179 180 test('when the allocation is not found, the application errors', function(assert) { 181 visit(`/allocations/not-a-real-allocation/${task.name}`); 182 183 andThen(() => { 184 assert.equal( 185 server.pretender.handledRequests.findBy('status', 404).url, 186 '/v1/allocation/not-a-real-allocation', 187 'A request to the nonexistent allocation is made' 188 ); 189 assert.equal( 190 currentURL(), 191 `/allocations/not-a-real-allocation/${task.name}`, 192 'The URL persists' 193 ); 194 assert.ok(find('[data-test-error]'), 'Error message is shown'); 195 assert.equal( 196 find('[data-test-error-title]').textContent, 197 'Not Found', 198 'Error message is for 404' 199 ); 200 }); 201 }); 202 203 test('when the allocation is found but the task is not, the application errors', function(assert) { 204 visit(`/allocations/${allocation.id}/not-a-real-task-name`); 205 206 andThen(() => { 207 assert.equal( 208 server.pretender.handledRequests.findBy('status', 200).url, 209 `/v1/allocation/${allocation.id}`, 210 'A request to the allocation is made successfully' 211 ); 212 assert.equal( 213 currentURL(), 214 `/allocations/${allocation.id}/not-a-real-task-name`, 215 'The URL persists' 216 ); 217 assert.ok(find('[data-test-error]'), 'Error message is shown'); 218 assert.equal( 219 find('[data-test-error-title]').textContent, 220 'Not Found', 221 'Error message is for 404' 222 ); 223 }); 224 }); 225 226 moduleForAcceptance('Acceptance | task detail (no addresses)', { 227 beforeEach() { 228 server.create('agent'); 229 server.create('node'); 230 server.create('job'); 231 allocation = server.create('allocation', 'withoutTaskWithPorts'); 232 task = server.db.taskStates.where({ allocationId: allocation.id })[0]; 233 234 visit(`/allocations/${allocation.id}/${task.name}`); 235 }, 236 }); 237 238 test('when the task has no addresses, the addresses table is not shown', function(assert) { 239 assert.notOk(find('[data-test-task-addresses]'), 'No addresses table'); 240 });