github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/application-errors-test.js (about) 1 import { currentURL, visit } 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 ClientsList from 'nomad-ui/tests/pages/clients/list'; 7 import JobsList from 'nomad-ui/tests/pages/jobs/list'; 8 import Job from 'nomad-ui/tests/pages/jobs/detail'; 9 10 module('Acceptance | application errors ', function(hooks) { 11 setupApplicationTest(hooks); 12 setupMirage(hooks); 13 14 hooks.beforeEach(function() { 15 server.create('agent'); 16 server.create('node'); 17 server.create('job'); 18 }); 19 20 test('it passes an accessibility audit', async function(assert) { 21 server.pretender.get('/v1/nodes', () => [500, {}, null]); 22 await ClientsList.visit(); 23 await a11yAudit(assert); 24 }); 25 26 test('transitioning away from an error page resets the global error', async function(assert) { 27 server.pretender.get('/v1/nodes', () => [500, {}, null]); 28 29 await ClientsList.visit(); 30 assert.ok(ClientsList.error.isPresent, 'Application has errored'); 31 32 await JobsList.visit(); 33 assert.notOk(JobsList.error.isPresent, 'Application is no longer in an error state'); 34 }); 35 36 test('the 403 error page links to the ACL tokens page', async function(assert) { 37 const job = server.db.jobs[0]; 38 39 server.pretender.get(`/v1/job/${job.id}`, () => [403, {}, null]); 40 41 await Job.visit({ id: job.id }); 42 43 assert.ok(Job.error.isPresent, 'Error message is shown'); 44 assert.equal(Job.error.title, 'Not Authorized', 'Error message is for 403'); 45 46 await Job.error.seekHelp(); 47 assert.equal( 48 currentURL(), 49 '/settings/tokens', 50 'Error message contains a link to the tokens page' 51 ); 52 }); 53 54 test('the no leader error state gets its own error message', async function(assert) { 55 server.pretender.get('/v1/jobs', () => [500, {}, 'No cluster leader']); 56 57 await JobsList.visit(); 58 59 assert.ok(JobsList.error.isPresent, 'An error is shown'); 60 assert.equal( 61 JobsList.error.title, 62 'No Cluster Leader', 63 'The error is specifically for the lack of a cluster leader' 64 ); 65 }); 66 67 test('error pages include links to the jobs and clients pages', async function(assert) { 68 await visit('/a/non-existent/page'); 69 70 assert.ok(JobsList.error.isPresent, 'An error is shown'); 71 72 await JobsList.error.gotoJobs(); 73 assert.equal(currentURL(), '/jobs', 'Now on the jobs page'); 74 assert.notOk(JobsList.error.isPresent, 'The error is gone now'); 75 76 await visit('/a/non-existent/page'); 77 assert.ok(JobsList.error.isPresent, 'An error is shown'); 78 79 await JobsList.error.gotoClients(); 80 assert.equal(currentURL(), '/clients', 'Now on the clients page'); 81 assert.notOk(JobsList.error.isPresent, 'The error is gone now'); 82 }); 83 });