github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/tests/helpers/module-for-job.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/setup-mirage';
     5  import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
     6  
     7  export default function moduleForJob(title, context, jobFactory, additionalTests) {
     8    let job;
     9  
    10    module(title, function(hooks) {
    11      setupApplicationTest(hooks);
    12      setupMirage(hooks);
    13      hooks.before(function() {
    14        if (context !== 'allocations' && context !== 'children') {
    15          throw new Error(
    16            `Invalid context provided to moduleForJob, expected either "allocations" or "children", got ${context}`
    17          );
    18        }
    19      });
    20  
    21      hooks.beforeEach(async function() {
    22        server.create('node');
    23        job = jobFactory();
    24        await JobDetail.visit({ id: job.id });
    25      });
    26  
    27      test('visiting /jobs/:job_id', async function(assert) {
    28        assert.equal(currentURL(), `/jobs/${job.id}`);
    29      });
    30  
    31      test('the subnav links to overview', async function(assert) {
    32        await JobDetail.tabFor('overview').visit();
    33        assert.equal(currentURL(), `/jobs/${job.id}`);
    34      });
    35  
    36      test('the subnav links to definition', async function(assert) {
    37        await JobDetail.tabFor('definition').visit();
    38        assert.equal(currentURL(), `/jobs/${job.id}/definition`);
    39      });
    40  
    41      test('the subnav links to versions', async function(assert) {
    42        await JobDetail.tabFor('versions').visit();
    43        assert.equal(currentURL(), `/jobs/${job.id}/versions`);
    44      });
    45  
    46      test('the subnav links to evaluations', async function(assert) {
    47        await JobDetail.tabFor('evaluations').visit();
    48        assert.equal(currentURL(), `/jobs/${job.id}/evaluations`);
    49      });
    50  
    51      if (context === 'allocations') {
    52        test('allocations for the job are shown in the overview', async function(assert) {
    53          assert.ok(JobDetail.allocationsSummary, 'Allocations are shown in the summary section');
    54          assert.notOk(JobDetail.childrenSummary, 'Children are not shown in the summary section');
    55        });
    56      }
    57  
    58      if (context === 'children') {
    59        test('children for the job are shown in the overview', async function(assert) {
    60          assert.ok(JobDetail.childrenSummary, 'Children are shown in the summary section');
    61          assert.notOk(
    62            JobDetail.allocationsSummary,
    63            'Allocations are not shown in the summary section'
    64          );
    65        });
    66      }
    67  
    68      for (var testName in additionalTests) {
    69        test(testName, async function(assert) {
    70          await additionalTests[testName](job, assert);
    71        });
    72      }
    73    });
    74  }