github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/tests/acceptance/allocation-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 7 const { $ } = Ember; 8 9 let job; 10 let node; 11 let allocation; 12 13 moduleForAcceptance('Acceptance | allocation detail', { 14 beforeEach() { 15 server.create('agent'); 16 17 node = server.create('node'); 18 job = server.create('job', { groupCount: 0 }); 19 allocation = server.create('allocation', 'withTaskWithPorts', { 20 useMessagePassthru: true, 21 }); 22 23 visit(`/allocations/${allocation.id}`); 24 }, 25 }); 26 27 test('/allocation/:id should name the allocation and link to the corresponding job and node', function( 28 assert 29 ) { 30 assert.ok(find('h1').textContent.includes(allocation.name), 'Allocation name is in the heading'); 31 assert.equal( 32 find('.inline-definitions .job-link a').textContent.trim(), 33 job.name, 34 'Job name is in the subheading' 35 ); 36 assert.equal( 37 find('.inline-definitions .node-link a').textContent.trim(), 38 node.id.split('-')[0], 39 'Node short id is in the subheading' 40 ); 41 42 andThen(() => { 43 click('.inline-definitions .job-link a'); 44 }); 45 46 andThen(() => { 47 assert.equal(currentURL(), `/jobs/${job.id}`, 'Job link navigates to the job'); 48 }); 49 50 visit(`/allocations/${allocation.id}`); 51 52 andThen(() => { 53 click('.inline-definitions .node-link a'); 54 }); 55 56 andThen(() => { 57 assert.equal(currentURL(), `/clients/${node.id}`, 'Client link navigates to the client'); 58 }); 59 }); 60 61 test('/allocation/:id should list all tasks for the allocation', function(assert) { 62 assert.equal( 63 findAll('.tasks tbody tr').length, 64 server.db.taskStates.where({ allocationId: allocation.id }).length, 65 'Table lists all tasks' 66 ); 67 }); 68 69 test('each task row should list high-level information for the task', function(assert) { 70 const task = server.db.taskStates.where({ allocationId: allocation.id }).sortBy('name')[0]; 71 const taskResources = allocation.taskResourcesIds 72 .map(id => server.db.taskResources.find(id)) 73 .sortBy('name')[0]; 74 const reservedPorts = taskResources.resources.Networks[0].ReservedPorts; 75 const dynamicPorts = taskResources.resources.Networks[0].DynamicPorts; 76 const taskRow = $(findAll('.tasks tbody tr')[0]); 77 const events = server.db.taskEvents.where({ taskStateId: task.id }); 78 const event = events[events.length - 1]; 79 80 assert.equal( 81 taskRow 82 .find('td:eq(0)') 83 .text() 84 .trim(), 85 task.name, 86 'Name' 87 ); 88 assert.equal( 89 taskRow 90 .find('td:eq(1)') 91 .text() 92 .trim(), 93 task.state, 94 'State' 95 ); 96 assert.equal( 97 taskRow 98 .find('td:eq(2)') 99 .text() 100 .trim(), 101 event.message, 102 'Event Message' 103 ); 104 assert.equal( 105 taskRow 106 .find('td:eq(3)') 107 .text() 108 .trim(), 109 moment(event.time / 1000000).format('MM/DD/YY HH:mm:ss'), 110 'Event Time' 111 ); 112 113 assert.ok(reservedPorts.length, 'The task has reserved ports'); 114 assert.ok(dynamicPorts.length, 'The task has dynamic ports'); 115 116 const addressesText = taskRow.find('td:eq(4)').text(); 117 reservedPorts.forEach(port => { 118 assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`); 119 assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`); 120 }); 121 dynamicPorts.forEach(port => { 122 assert.ok(addressesText.includes(port.Label), `Found label ${port.Label}`); 123 assert.ok(addressesText.includes(port.Value), `Found value ${port.Value}`); 124 }); 125 }); 126 127 test('when the allocation is not found, an error message is shown, but the URL persists', function( 128 assert 129 ) { 130 visit('/allocations/not-a-real-allocation'); 131 132 andThen(() => { 133 assert.equal( 134 server.pretender.handledRequests.findBy('status', 404).url, 135 '/v1/allocation/not-a-real-allocation', 136 'A request to the non-existent allocation is made' 137 ); 138 assert.equal(currentURL(), '/allocations/not-a-real-allocation', 'The URL persists'); 139 assert.ok(find('.error-message'), 'Error message is shown'); 140 assert.equal( 141 find('.error-message .title').textContent, 142 'Not Found', 143 'Error message is for 404' 144 ); 145 }); 146 });