github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/acceptance/job-detail-test.js (about)

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