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