github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/acceptance/jobs-list-test.js (about) 1 import { click, find, findAll, currentURL, visit, fillIn } from 'ember-native-dom-helpers'; 2 import { test } from 'qunit'; 3 import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance'; 4 5 moduleForAcceptance('Acceptance | jobs list', { 6 beforeEach() { 7 // Required for placing allocations (a result of creating jobs) 8 server.create('node'); 9 }, 10 }); 11 12 test('visiting /jobs', function(assert) { 13 visit('/jobs'); 14 15 andThen(() => { 16 assert.equal(currentURL(), '/jobs'); 17 }); 18 }); 19 20 test('/jobs should list the first page of jobs sorted by modify index', function(assert) { 21 const jobsCount = 11; 22 const pageSize = 10; 23 server.createList('job', jobsCount, { createAllocations: false }); 24 25 visit('/jobs'); 26 27 andThen(() => { 28 const sortedJobs = server.db.jobs.sortBy('modifyIndex').reverse(); 29 assert.equal(findAll('[data-test-job-row]').length, pageSize); 30 for (var jobNumber = 0; jobNumber < pageSize; jobNumber++) { 31 const jobRow = findAll('[data-test-job-row]')[jobNumber]; 32 assert.equal( 33 jobRow.querySelector('[data-test-job-name]').textContent, 34 sortedJobs[jobNumber].name, 35 'Jobs are ordered' 36 ); 37 } 38 }); 39 }); 40 41 test('each job row should contain information about the job', function(assert) { 42 server.createList('job', 2); 43 const job = server.db.jobs.sortBy('modifyIndex').reverse()[0]; 44 const taskGroups = server.db.taskGroups.where({ jobId: job.id }); 45 46 visit('/jobs'); 47 48 andThen(() => { 49 const jobRow = find('[data-test-job-row]'); 50 51 assert.equal(jobRow.querySelector('[data-test-job-name]').textContent, job.name, 'Name'); 52 assert.equal( 53 jobRow.querySelector('[data-test-job-name] a').getAttribute('href'), 54 `/ui/jobs/${job.id}`, 55 'Detail Link' 56 ); 57 assert.equal( 58 jobRow.querySelector('[data-test-job-status]').textContent.trim(), 59 job.status, 60 'Status' 61 ); 62 assert.equal(jobRow.querySelector('[data-test-job-type]').textContent, typeForJob(job), 'Type'); 63 assert.equal( 64 jobRow.querySelector('[data-test-job-priority]').textContent, 65 job.priority, 66 'Priority' 67 ); 68 andThen(() => { 69 assert.equal( 70 jobRow.querySelector('[data-test-job-task-groups]').textContent.trim(), 71 taskGroups.length, 72 '# Groups' 73 ); 74 }); 75 }); 76 }); 77 78 test('each job row should link to the corresponding job', function(assert) { 79 server.create('job'); 80 const job = server.db.jobs[0]; 81 82 visit('/jobs'); 83 84 andThen(() => { 85 click('[data-test-job-name] a'); 86 }); 87 88 andThen(() => { 89 assert.equal(currentURL(), `/jobs/${job.id}`); 90 }); 91 }); 92 93 test('when there are no jobs, there is an empty message', function(assert) { 94 visit('/jobs'); 95 96 andThen(() => { 97 assert.ok(find('[data-test-empty-jobs-list]')); 98 assert.equal(find('[data-test-empty-jobs-list-headline]').textContent, 'No Jobs'); 99 }); 100 }); 101 102 test('when there are jobs, but no matches for a search result, there is an empty message', function(assert) { 103 server.create('job', { name: 'cat 1' }); 104 server.create('job', { name: 'cat 2' }); 105 106 visit('/jobs'); 107 108 andThen(() => { 109 fillIn('[data-test-jobs-search] input', 'dog'); 110 }); 111 112 andThen(() => { 113 assert.ok(find('[data-test-empty-jobs-list]')); 114 assert.equal(find('[data-test-empty-jobs-list-headline]').textContent, 'No Matches'); 115 }); 116 }); 117 118 test('when the namespace query param is set, only matching jobs are shown and the namespace value is forwarded to app state', function(assert) { 119 server.createList('namespace', 2); 120 const job1 = server.create('job', { namespaceId: server.db.namespaces[0].id }); 121 const job2 = server.create('job', { namespaceId: server.db.namespaces[1].id }); 122 123 visit('/jobs'); 124 125 andThen(() => { 126 assert.equal(findAll('[data-test-job-row]').length, 1, 'One job in the default namespace'); 127 assert.equal(find('[data-test-job-name]').textContent, job1.name, 'The correct job is shown'); 128 }); 129 130 const secondNamespace = server.db.namespaces[1]; 131 visit(`/jobs?namespace=${secondNamespace.id}`); 132 133 andThen(() => { 134 assert.equal( 135 findAll('[data-test-job-row]').length, 136 1, 137 `One job in the ${secondNamespace.name} namespace` 138 ); 139 assert.equal(find('[data-test-job-name]').textContent, job2.name, 'The correct job is shown'); 140 }); 141 }); 142 143 test('when accessing jobs is forbidden, show a message with a link to the tokens page', function(assert) { 144 server.pretender.get('/v1/jobs', () => [403, {}, null]); 145 146 visit('/jobs'); 147 148 andThen(() => { 149 assert.equal(find('[data-test-error-title]').textContent, 'Not Authorized'); 150 }); 151 152 andThen(() => { 153 click('[data-test-error-message] a'); 154 }); 155 156 andThen(() => { 157 assert.equal(currentURL(), '/settings/tokens'); 158 }); 159 }); 160 161 function typeForJob(job) { 162 return job.periodic ? 'periodic' : job.parameterized ? 'parameterized' : job.type; 163 }