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