2019-03-13 00:08:16 +00:00
|
|
|
import { currentURL, visit } from '@ember/test-helpers';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-07-11 18:41:34 +00:00
|
|
|
import ClientsList from 'nomad-ui/tests/pages/clients/list';
|
|
|
|
import JobsList from 'nomad-ui/tests/pages/jobs/list';
|
|
|
|
import Job from 'nomad-ui/tests/pages/jobs/detail';
|
2017-10-12 19:35:00 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | application errors ', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2017-10-12 19:35:00 +00:00
|
|
|
server.create('agent');
|
|
|
|
server.create('node');
|
|
|
|
server.create('job');
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-10-12 19:35:00 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(1);
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
server.pretender.get('/v1/nodes', () => [500, {}, null]);
|
|
|
|
await ClientsList.visit();
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('transitioning away from an error page resets the global error', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.pretender.get('/v1/nodes', () => [500, {}, null]);
|
2017-10-12 19:35:00 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await ClientsList.visit();
|
2018-07-11 18:41:34 +00:00
|
|
|
assert.ok(ClientsList.error.isPresent, 'Application has errored');
|
2017-10-12 19:35:00 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.notOk(
|
|
|
|
JobsList.error.isPresent,
|
|
|
|
'Application is no longer in an error state'
|
|
|
|
);
|
2017-10-12 19:35:00 +00:00
|
|
|
});
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the 403 error page links to the ACL tokens page', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
const job = server.db.jobs[0];
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
server.pretender.get(`/v1/job/${job.id}`, () => [403, {}, null]);
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Job.visit({ id: job.id });
|
2017-10-12 23:56:20 +00:00
|
|
|
|
2018-07-11 18:41:34 +00:00
|
|
|
assert.ok(Job.error.isPresent, 'Error message is shown');
|
|
|
|
assert.equal(Job.error.title, 'Not Authorized', 'Error message is for 403');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
|
|
|
await Job.error.seekHelp();
|
2017-10-12 23:56:20 +00:00
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
'/settings/tokens',
|
|
|
|
'Error message contains a link to the tokens page'
|
|
|
|
);
|
|
|
|
});
|
2018-07-31 21:32:17 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the no leader error state gets its own error message', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
server.pretender.get('/v1/jobs', () => [500, {}, 'No cluster leader']);
|
2018-07-31 21:32:17 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await JobsList.visit();
|
2018-07-31 21:32:17 +00:00
|
|
|
|
|
|
|
assert.ok(JobsList.error.isPresent, 'An error is shown');
|
|
|
|
assert.equal(
|
|
|
|
JobsList.error.title,
|
|
|
|
'No Cluster Leader',
|
|
|
|
'The error is specifically for the lack of a cluster leader'
|
|
|
|
);
|
|
|
|
});
|
2018-11-08 00:19:45 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('error pages include links to the jobs and clients pages', async function (assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
await visit('/a/non-existent/page');
|
2018-11-08 00:19:45 +00:00
|
|
|
|
|
|
|
assert.ok(JobsList.error.isPresent, 'An error is shown');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
|
|
|
await JobsList.error.gotoJobs();
|
2018-11-08 00:19:45 +00:00
|
|
|
assert.equal(currentURL(), '/jobs', 'Now on the jobs page');
|
|
|
|
assert.notOk(JobsList.error.isPresent, 'The error is gone now');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await visit('/a/non-existent/page');
|
2018-11-08 00:19:45 +00:00
|
|
|
assert.ok(JobsList.error.isPresent, 'An error is shown');
|
2019-03-14 06:44:53 +00:00
|
|
|
|
|
|
|
await JobsList.error.gotoClients();
|
2018-11-08 00:19:45 +00:00
|
|
|
assert.equal(currentURL(), '/clients', 'Now on the clients page');
|
|
|
|
assert.notOk(JobsList.error.isPresent, 'The error is gone now');
|
|
|
|
});
|
|
|
|
});
|