github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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';
     5  import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
     6  
     7  // eslint-disable-next-line ember/no-test-module-for
     8  export default function moduleForJob(title, context, jobFactory, additionalTests) {
     9    let job;
    10  
    11    module(title, function(hooks) {
    12      setupApplicationTest(hooks);
    13      setupMirage(hooks);
    14      hooks.before(function() {
    15        if (context !== 'allocations' && context !== 'children') {
    16          throw new Error(
    17            `Invalid context provided to moduleForJob, expected either "allocations" or "children", got ${context}`
    18          );
    19        }
    20      });
    21  
    22      hooks.beforeEach(async function() {
    23        server.create('node');
    24        job = jobFactory();
    25        await JobDetail.visit({ id: job.id });
    26      });
    27  
    28      test('visiting /jobs/:job_id', async function(assert) {
    29        assert.equal(currentURL(), `/jobs/${job.id}`);
    30        assert.equal(document.title, `Job ${job.name} - Nomad`);
    31      });
    32  
    33      test('the subnav links to overview', async function(assert) {
    34        await JobDetail.tabFor('overview').visit();
    35        assert.equal(currentURL(), `/jobs/${job.id}`);
    36      });
    37  
    38      test('the subnav links to definition', async function(assert) {
    39        await JobDetail.tabFor('definition').visit();
    40        assert.equal(currentURL(), `/jobs/${job.id}/definition`);
    41      });
    42  
    43      test('the subnav links to versions', async function(assert) {
    44        await JobDetail.tabFor('versions').visit();
    45        assert.equal(currentURL(), `/jobs/${job.id}/versions`);
    46      });
    47  
    48      test('the subnav links to evaluations', async function(assert) {
    49        await JobDetail.tabFor('evaluations').visit();
    50        assert.equal(currentURL(), `/jobs/${job.id}/evaluations`);
    51      });
    52  
    53      test('the title buttons are dependent on job status', async function(assert) {
    54        if (job.status === 'dead') {
    55          assert.ok(JobDetail.start.isPresent);
    56          assert.notOk(JobDetail.stop.isPresent);
    57          assert.notOk(JobDetail.execButton.isPresent);
    58        } else {
    59          assert.notOk(JobDetail.start.isPresent);
    60          assert.ok(JobDetail.stop.isPresent);
    61          assert.ok(JobDetail.execButton.isPresent);
    62        }
    63      });
    64  
    65      if (context === 'allocations') {
    66        test('allocations for the job are shown in the overview', async function(assert) {
    67          assert.ok(JobDetail.allocationsSummary, 'Allocations are shown in the summary section');
    68          assert.notOk(JobDetail.childrenSummary, 'Children are not shown in the summary section');
    69        });
    70  
    71        test('clicking in an allocation row navigates to that allocation', async function(assert) {
    72          const allocationRow = JobDetail.allocations[0];
    73          const allocationId = allocationRow.id;
    74  
    75          await allocationRow.visitRow();
    76  
    77          assert.equal(
    78            currentURL(),
    79            `/allocations/${allocationId}`,
    80            'Allocation row links to allocation detail'
    81          );
    82        });
    83      }
    84  
    85      if (context === 'children') {
    86        test('children for the job are shown in the overview', async function(assert) {
    87          assert.ok(JobDetail.childrenSummary, 'Children are shown in the summary section');
    88          assert.notOk(
    89            JobDetail.allocationsSummary,
    90            'Allocations are not shown in the summary section'
    91          );
    92        });
    93      }
    94  
    95      for (var testName in additionalTests) {
    96        test(testName, async function(assert) {
    97          await additionalTests[testName].call(this, job, assert);
    98        });
    99      }
   100    });
   101  }