github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/acceptance/job-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 moduleForJob from 'nomad-ui/tests/helpers/module-for-job'; 5 6 moduleForJob('Acceptance | job detail (batch)', () => server.create('job', { type: 'batch' })); 7 moduleForJob('Acceptance | job detail (system)', () => server.create('job', { type: 'system' })); 8 moduleForJob('Acceptance | job detail (periodic)', () => server.create('job', 'periodic')); 9 10 moduleForJob('Acceptance | job detail (parameterized)', () => 11 server.create('job', 'parameterized') 12 ); 13 14 moduleForJob('Acceptance | job detail (periodic child)', () => { 15 const parent = server.create('job', 'periodic'); 16 return server.db.jobs.where({ parentId: parent.id })[0]; 17 }); 18 19 moduleForJob('Acceptance | job detail (parameterized child)', () => { 20 const parent = server.create('job', 'parameterized'); 21 return server.db.jobs.where({ parentId: parent.id })[0]; 22 }); 23 24 moduleForJob('Acceptance | job detail (service)', () => server.create('job', { type: 'service' }), { 25 'the subnav links to deployment': (job, assert) => { 26 click(find('[data-test-tab="deployments"] a')); 27 andThen(() => { 28 assert.equal(currentURL(), `/jobs/${job.id}/deployments`); 29 }); 30 }, 31 }); 32 33 let job; 34 35 test('when the job is not found, an error message is shown, but the URL persists', function(assert) { 36 visit('/jobs/not-a-real-job'); 37 38 andThen(() => { 39 assert.equal( 40 server.pretender.handledRequests.findBy('status', 404).url, 41 '/v1/job/not-a-real-job', 42 'A request to the non-existent job is made' 43 ); 44 assert.equal(currentURL(), '/jobs/not-a-real-job', 'The URL persists'); 45 assert.ok(find('[data-test-error]'), 'Error message is shown'); 46 assert.equal( 47 find('[data-test-error-title]').textContent, 48 'Not Found', 49 'Error message is for 404' 50 ); 51 }); 52 }); 53 54 moduleForAcceptance('Acceptance | job detail (with namespaces)', { 55 beforeEach() { 56 server.createList('namespace', 2); 57 server.create('node'); 58 job = server.create('job', { type: 'service', namespaceId: server.db.namespaces[1].name }); 59 server.createList('job', 3, { namespaceId: server.db.namespaces[0].name }); 60 }, 61 }); 62 63 test('when there are namespaces, the job detail page states the namespace for the job', function(assert) { 64 const namespace = server.db.namespaces.find(job.namespaceId); 65 visit(`/jobs/${job.id}?namespace=${namespace.name}`); 66 67 andThen(() => { 68 assert.ok( 69 find('[data-test-job-stat="namespace"]').textContent.includes(namespace.name), 70 'Namespace included in stats' 71 ); 72 }); 73 }); 74 75 test('when switching namespaces, the app redirects to /jobs with the new namespace', function(assert) { 76 const namespace = server.db.namespaces.find(job.namespaceId); 77 const otherNamespace = server.db.namespaces.toArray().find(ns => ns !== namespace).name; 78 const label = otherNamespace === 'default' ? 'Default Namespace' : otherNamespace; 79 80 visit(`/jobs/${job.id}?namespace=${namespace.name}`); 81 82 andThen(() => { 83 selectChoose('[data-test-namespace-switcher]', label); 84 }); 85 86 andThen(() => { 87 assert.equal(currentURL().split('?')[0], '/jobs', 'Navigated to /jobs'); 88 const jobs = server.db.jobs 89 .where({ namespace: otherNamespace }) 90 .sortBy('modifyIndex') 91 .reverse(); 92 assert.equal( 93 findAll('[data-test-job-row]').length, 94 jobs.length, 95 'Shows the right number of jobs' 96 ); 97 jobs.forEach((job, index) => { 98 const jobRow = findAll('[data-test-job-row]')[index]; 99 assert.equal( 100 jobRow.querySelector('[data-test-job-name]').textContent.trim(), 101 job.name, 102 `Job ${index} is right` 103 ); 104 }); 105 }); 106 });