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