github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/task-detail-test.js (about) 1 import { currentURL } from 'ember-native-dom-helpers'; 2 import { test } from 'qunit'; 3 import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance'; 4 import Task from 'nomad-ui/tests/pages/allocations/task/detail'; 5 import moment from 'moment'; 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 Task.visit({ id: allocation.id, name: 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(Task.title.includes(task.name), 'Task name'); 24 assert.ok(Task.state.includes(task.state), 'Task state'); 25 26 assert.ok( 27 Task.startedAt.includes(moment(task.startedAt).format('MM/DD/YY HH:mm:ss')), 28 'Task started at' 29 ); 30 }); 31 32 test('breadcrumbs match jobs / job / task group / allocation / task', function(assert) { 33 const { jobId, taskGroup } = allocation; 34 const job = server.db.jobs.find(jobId); 35 36 const shortId = allocation.id.split('-')[0]; 37 38 assert.equal(Task.breadcrumbFor('jobs.index').text, 'Jobs', 'Jobs is the first breadcrumb'); 39 assert.equal(Task.breadcrumbFor('jobs.job.index').text, job.name, 'Job is the second breadcrumb'); 40 assert.equal( 41 Task.breadcrumbFor('jobs.job.task-group').text, 42 taskGroup, 43 'Task Group is the third breadcrumb' 44 ); 45 assert.equal( 46 Task.breadcrumbFor('allocations.allocation').text, 47 shortId, 48 'Allocation short id is the fourth breadcrumb' 49 ); 50 assert.equal( 51 Task.breadcrumbFor('allocations.allocation.task').text, 52 task.name, 53 'Task name is the fifth breadcrumb' 54 ); 55 56 Task.breadcrumbFor('jobs.index').visit(); 57 andThen(() => { 58 assert.equal(currentURL(), '/jobs', 'Jobs breadcrumb links correctly'); 59 }); 60 andThen(() => { 61 Task.visit({ id: allocation.id, name: task.name }); 62 }); 63 andThen(() => { 64 Task.breadcrumbFor('jobs.job.index').visit(); 65 }); 66 andThen(() => { 67 assert.equal(currentURL(), `/jobs/${job.id}`, 'Job breadcrumb links correctly'); 68 }); 69 andThen(() => { 70 Task.visit({ id: allocation.id, name: task.name }); 71 }); 72 andThen(() => { 73 Task.breadcrumbFor('jobs.job.task-group').visit(); 74 }); 75 andThen(() => { 76 assert.equal( 77 currentURL(), 78 `/jobs/${job.id}/${taskGroup}`, 79 'Task Group breadcrumb links correctly' 80 ); 81 }); 82 andThen(() => { 83 Task.visit({ id: allocation.id, name: task.name }); 84 }); 85 andThen(() => { 86 Task.breadcrumbFor('allocations.allocation').visit(); 87 }); 88 andThen(() => { 89 assert.equal( 90 currentURL(), 91 `/allocations/${allocation.id}`, 92 'Allocations breadcrumb links correctly' 93 ); 94 }); 95 }); 96 97 test('the addresses table lists all reserved and dynamic ports', function(assert) { 98 const taskResources = allocation.taskResourcesIds 99 .map(id => server.db.taskResources.find(id)) 100 .find(resources => resources.name === task.name); 101 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 102 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 103 const addresses = reservedPorts.concat(dynamicPorts); 104 105 assert.equal(Task.addresses.length, addresses.length, 'All addresses are listed'); 106 }); 107 108 test('each address row shows the label and value of the address', function(assert) { 109 const taskResources = allocation.taskResourcesIds 110 .map(id => server.db.taskResources.find(id)) 111 .findBy('name', task.name); 112 const networkAddress = taskResources.resources.Networks[0].IP; 113 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 114 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 115 const address = reservedPorts.concat(dynamicPorts).sortBy('Label')[0]; 116 117 const addressRow = Task.addresses.objectAt(0); 118 assert.equal( 119 addressRow.isDynamic, 120 reservedPorts.includes(address) ? 'No' : 'Yes', 121 'Dynamic port is denoted as such' 122 ); 123 assert.equal(addressRow.name, address.Label, 'Label'); 124 assert.equal(addressRow.address, `${networkAddress}:${address.Value}`, 'Value'); 125 }); 126 127 test('the events table lists all recent events', function(assert) { 128 const events = server.db.taskEvents.where({ taskStateId: task.id }); 129 130 assert.equal(Task.events.length, events.length, `Lists ${events.length} events`); 131 }); 132 133 test('each recent event should list the time, type, and description of the event', function(assert) { 134 const event = server.db.taskEvents.where({ taskStateId: task.id })[0]; 135 const recentEvent = Task.events.objectAt(Task.events.length - 1); 136 137 assert.equal( 138 recentEvent.time, 139 moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'), 140 'Event timestamp' 141 ); 142 assert.equal(recentEvent.type, event.type, 'Event type'); 143 assert.equal(recentEvent.message, event.displayMessage, 'Event message'); 144 }); 145 146 test('when the allocation is not found, the application errors', function(assert) { 147 Task.visit({ id: 'not-a-real-allocation', name: task.name }); 148 149 andThen(() => { 150 assert.equal( 151 server.pretender.handledRequests.findBy('status', 404).url, 152 '/v1/allocation/not-a-real-allocation', 153 'A request to the nonexistent allocation is made' 154 ); 155 assert.equal( 156 currentURL(), 157 `/allocations/not-a-real-allocation/${task.name}`, 158 'The URL persists' 159 ); 160 assert.ok(Task.error.isPresent, 'Error message is shown'); 161 assert.equal(Task.error.title, 'Not Found', 'Error message is for 404'); 162 }); 163 }); 164 165 test('when the allocation is found but the task is not, the application errors', function(assert) { 166 Task.visit({ id: allocation.id, name: 'not-a-real-task-name' }); 167 168 andThen(() => { 169 assert.ok( 170 server.pretender.handledRequests 171 .filterBy('status', 200) 172 .mapBy('url') 173 .includes(`/v1/allocation/${allocation.id}`), 174 'A request to the allocation is made successfully' 175 ); 176 assert.equal( 177 currentURL(), 178 `/allocations/${allocation.id}/not-a-real-task-name`, 179 'The URL persists' 180 ); 181 assert.ok(Task.error.isPresent, 'Error message is shown'); 182 assert.equal(Task.error.title, 'Not Found', 'Error message is for 404'); 183 }); 184 }); 185 186 moduleForAcceptance('Acceptance | task detail (no addresses)', { 187 beforeEach() { 188 server.create('agent'); 189 server.create('node'); 190 server.create('job'); 191 allocation = server.create('allocation', 'withoutTaskWithPorts'); 192 task = server.db.taskStates.where({ allocationId: allocation.id })[0]; 193 194 Task.visit({ id: allocation.id, name: task.name }); 195 }, 196 }); 197 198 test('when the task has no addresses, the addresses table is not shown', function(assert) { 199 assert.notOk(Task.hasAddresses, 'No addresses table'); 200 });