github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/job-versions-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 a11yAudit from 'nomad-ui/tests/helpers/a11y-audit'; 6 import Versions from 'nomad-ui/tests/pages/jobs/job/versions'; 7 import moment from 'moment'; 8 9 let job; 10 let versions; 11 12 module('Acceptance | job versions', function(hooks) { 13 setupApplicationTest(hooks); 14 setupMirage(hooks); 15 16 hooks.beforeEach(async function() { 17 job = server.create('job', { createAllocations: false }); 18 versions = server.db.jobVersions.where({ jobId: job.id }); 19 20 await Versions.visit({ id: job.id }); 21 }); 22 23 test('it passes an accessibility audit', async function(assert) { 24 await a11yAudit(assert); 25 }); 26 27 test('/jobs/:id/versions should list all job versions', async function(assert) { 28 assert.ok(Versions.versions.length, versions.length, 'Each version gets a row in the timeline'); 29 assert.equal(document.title, `Job ${job.name} versions - Nomad`); 30 }); 31 32 test('each version mentions the version number, the stability, and the submitted time', async function(assert) { 33 const version = versions.sortBy('submitTime').reverse()[0]; 34 const formattedSubmitTime = moment(version.submitTime / 1000000).format( 35 "MMM DD, 'YY HH:mm:ss ZZ" 36 ); 37 const versionRow = Versions.versions.objectAt(0); 38 39 assert.ok(versionRow.text.includes(`Version #${version.version}`), 'Version #'); 40 assert.equal(versionRow.stability, version.stable.toString(), 'Stability'); 41 assert.equal(versionRow.submitTime, formattedSubmitTime, 'Submit time'); 42 }); 43 44 test('when the job for the versions is not found, an error message is shown, but the URL persists', async function(assert) { 45 await Versions.visit({ id: 'not-a-real-job' }); 46 47 assert.equal( 48 server.pretender.handledRequests 49 .filter(request => !request.url.includes('policy')) 50 .findBy('status', 404).url, 51 '/v1/job/not-a-real-job', 52 'A request to the nonexistent job is made' 53 ); 54 assert.equal(currentURL(), '/jobs/not-a-real-job/versions', 'The URL persists'); 55 assert.ok(Versions.error.isPresent, 'Error message is shown'); 56 assert.equal(Versions.error.title, 'Not Found', 'Error message is for 404'); 57 }); 58 });