github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/acceptance/job-allocations-test.js (about) 1 import { currentURL } from '@ember/test-helpers'; 2 import { module, test } from 'qunit'; 3 import { setupApplicationTest } from 'ember-qunit'; 4 import { setupMirage } from 'ember-cli-mirage/test-support'; 5 import Allocations from 'nomad-ui/tests/pages/jobs/job/allocations'; 6 7 let job; 8 let allocations; 9 10 const makeSearchAllocations = server => { 11 Array(10) 12 .fill(null) 13 .map((_, index) => { 14 server.create('allocation', { 15 id: index < 5 ? `ffffff-dddddd-${index}` : `111111-222222-${index}`, 16 shallow: true, 17 }); 18 }); 19 }; 20 21 module('Acceptance | job allocations', function(hooks) { 22 setupApplicationTest(hooks); 23 setupMirage(hooks); 24 25 hooks.beforeEach(function() { 26 server.create('node'); 27 28 job = server.create('job', { noFailedPlacements: true, createAllocations: false }); 29 }); 30 31 test('lists all allocations for the job', async function(assert) { 32 server.createList('allocation', Allocations.pageSize - 1, { shallow: true }); 33 allocations = server.schema.allocations.where({ jobId: job.id }).models; 34 35 await Allocations.visit({ id: job.id }); 36 37 assert.equal( 38 Allocations.allocations.length, 39 Allocations.pageSize - 1, 40 'Allocations are shown in a table' 41 ); 42 43 const sortedAllocations = allocations.sortBy('modifyIndex').reverse(); 44 45 Allocations.allocations.forEach((allocation, index) => { 46 const shortId = sortedAllocations[index].id.split('-')[0]; 47 assert.equal(allocation.shortId, shortId, `Allocation ${index} is ${shortId}`); 48 }); 49 50 assert.equal(document.title, `Job ${job.name} allocations - Nomad`); 51 }); 52 53 test('allocations table is sortable', async function(assert) { 54 server.createList('allocation', Allocations.pageSize - 1); 55 allocations = server.schema.allocations.where({ jobId: job.id }).models; 56 57 await Allocations.visit({ id: job.id }); 58 await Allocations.sortBy('taskGroupName'); 59 60 assert.equal( 61 currentURL(), 62 `/jobs/${job.id}/allocations?sort=taskGroupName`, 63 'the URL persists the sort parameter' 64 ); 65 const sortedAllocations = allocations.sortBy('taskGroup').reverse(); 66 Allocations.allocations.forEach((allocation, index) => { 67 const shortId = sortedAllocations[index].id.split('-')[0]; 68 assert.equal( 69 allocation.shortId, 70 shortId, 71 `Allocation ${index} is ${shortId} with task group ${sortedAllocations[index].taskGroup}` 72 ); 73 }); 74 }); 75 76 test('allocations table is searchable', async function(assert) { 77 makeSearchAllocations(server); 78 79 allocations = server.schema.allocations.where({ jobId: job.id }).models; 80 81 await Allocations.visit({ id: job.id }); 82 await Allocations.search('ffffff'); 83 84 assert.equal(Allocations.allocations.length, 5, 'List is filtered by search term'); 85 }); 86 87 test('when a search yields no results, the search box remains', async function(assert) { 88 makeSearchAllocations(server); 89 90 allocations = server.schema.allocations.where({ jobId: job.id }).models; 91 92 await Allocations.visit({ id: job.id }); 93 await Allocations.search('^nothing will ever match this long regex$'); 94 95 assert.equal( 96 Allocations.emptyState.headline, 97 'No Matches', 98 'List is empty and the empty state is about search' 99 ); 100 101 assert.ok(Allocations.hasSearchBox, 'Search box is still shown'); 102 }); 103 104 test('when the job for the allocations is not found, an error message is shown, but the URL persists', async function(assert) { 105 await Allocations.visit({ id: 'not-a-real-job' }); 106 107 assert.equal( 108 server.pretender.handledRequests 109 .filter(request => !request.url.includes('policy')) 110 .findBy('status', 404).url, 111 '/v1/job/not-a-real-job', 112 'A request to the nonexistent job is made' 113 ); 114 assert.equal(currentURL(), '/jobs/not-a-real-job/allocations', 'The URL persists'); 115 assert.ok(Allocations.error.isPresent, 'Error message is shown'); 116 assert.equal(Allocations.error.title, 'Not Found', 'Error message is for 404'); 117 }); 118 });