github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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 includes allocations and link to the allocation detail page', function(assert) { 35 assert.equal( 36 find('[data-test-breadcrumb="allocations"]').textContent.trim(), 37 'Allocations', 38 'Allocations is the first breadcrumb' 39 ); 40 assert.equal( 41 find('[data-test-breadcrumb="allocations"]').getAttribute('href'), 42 '#', 43 "Allocations breadcrumb doesn't link anywhere" 44 ); 45 assert.equal( 46 find('[data-test-breadcrumb="allocation"]').textContent.trim(), 47 allocation.id.split('-')[0], 48 'Allocation short id is the second breadcrumb' 49 ); 50 assert.equal( 51 find('[data-test-breadcrumb="task"]').textContent.trim(), 52 task.name, 53 'Task name is the third breadcrumb' 54 ); 55 56 click('[data-test-breadcrumb="allocation"]'); 57 andThen(() => { 58 assert.equal( 59 currentURL(), 60 `/allocations/${allocation.id}`, 61 'Second breadcrumb links back to the allocation detail' 62 ); 63 }); 64 }); 65 66 test('the addresses table lists all reserved and dynamic ports', function(assert) { 67 const taskResources = allocation.taskResourcesIds 68 .map(id => server.db.taskResources.find(id)) 69 .find(resources => resources.name === task.name); 70 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 71 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 72 const addresses = reservedPorts.concat(dynamicPorts); 73 74 assert.equal( 75 findAll('[data-test-task-address]').length, 76 addresses.length, 77 'All addresses are listed' 78 ); 79 }); 80 81 test('each address row shows the label and value of the address', function(assert) { 82 const node = server.db.nodes.find(allocation.nodeId); 83 const taskResources = allocation.taskResourcesIds 84 .map(id => server.db.taskResources.find(id)) 85 .findBy('name', task.name); 86 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 87 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 88 const address = reservedPorts.concat(dynamicPorts).sortBy('Label')[0]; 89 90 const addressRow = find('[data-test-task-address]'); 91 assert.equal( 92 addressRow.querySelector('[data-test-task-address-is-dynamic]').textContent.trim(), 93 reservedPorts.includes(address) ? 'No' : 'Yes', 94 'Dynamic port is denoted as such' 95 ); 96 assert.equal( 97 addressRow.querySelector('[data-test-task-address-name]').textContent.trim(), 98 address.Label, 99 'Label' 100 ); 101 assert.equal( 102 addressRow.querySelector('[data-test-task-address-address]').textContent.trim(), 103 `${ipParts(node.httpAddr).address}:${address.Value}`, 104 'Value' 105 ); 106 }); 107 108 test('the events table lists all recent events', function(assert) { 109 const events = server.db.taskEvents.where({ taskStateId: task.id }); 110 111 assert.equal( 112 findAll('[data-test-task-event]').length, 113 events.length, 114 `Lists ${events.length} events` 115 ); 116 }); 117 118 test('each recent event should list the time, type, and description of the event', function(assert) { 119 const event = server.db.taskEvents.where({ taskStateId: task.id })[0]; 120 const recentEvent = findAll('[data-test-task-event]').get('lastObject'); 121 122 assert.equal( 123 recentEvent.querySelector('[data-test-task-event-time]').textContent.trim(), 124 moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'), 125 'Event timestamp' 126 ); 127 assert.equal( 128 recentEvent.querySelector('[data-test-task-event-type]').textContent.trim(), 129 event.type, 130 'Event type' 131 ); 132 assert.equal( 133 recentEvent.querySelector('[data-test-task-event-message]').textContent.trim(), 134 event.message, 135 'Event message' 136 ); 137 }); 138 139 test('when the allocation is not found, the application errors', function(assert) { 140 visit(`/allocations/not-a-real-allocation/${task.name}`); 141 142 andThen(() => { 143 assert.equal( 144 server.pretender.handledRequests.findBy('status', 404).url, 145 '/v1/allocation/not-a-real-allocation', 146 'A request to the non-existent allocation is made' 147 ); 148 assert.equal( 149 currentURL(), 150 `/allocations/not-a-real-allocation/${task.name}`, 151 'The URL persists' 152 ); 153 assert.ok(find('[data-test-error]'), 'Error message is shown'); 154 assert.equal( 155 find('[data-test-error-title]').textContent, 156 'Not Found', 157 'Error message is for 404' 158 ); 159 }); 160 }); 161 162 test('when the allocation is found but the task is not, the application errors', function(assert) { 163 visit(`/allocations/${allocation.id}/not-a-real-task-name`); 164 165 andThen(() => { 166 assert.equal( 167 server.pretender.handledRequests.findBy('status', 200).url, 168 `/v1/allocation/${allocation.id}`, 169 'A request to the allocation is made successfully' 170 ); 171 assert.equal( 172 currentURL(), 173 `/allocations/${allocation.id}/not-a-real-task-name`, 174 'The URL persists' 175 ); 176 assert.ok(find('[data-test-error]'), 'Error message is shown'); 177 assert.equal( 178 find('[data-test-error-title]').textContent, 179 'Not Found', 180 'Error message is for 404' 181 ); 182 }); 183 }); 184 185 moduleForAcceptance('Acceptance | task detail (no addresses)', { 186 beforeEach() { 187 server.create('agent'); 188 server.create('node'); 189 server.create('job'); 190 allocation = server.create('allocation', 'withoutTaskWithPorts'); 191 task = server.db.taskStates.where({ allocationId: allocation.id })[0]; 192 193 visit(`/allocations/${allocation.id}/${task.name}`); 194 }, 195 }); 196 197 test('when the task has no addresses, the addresses table is not shown', function(assert) { 198 assert.notOk(find('[data-test-task-addresses]'), 'No addresses table'); 199 });