github.com/aminovpavel/nomad@v0.11.8/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  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        assert.equal(document.title, `Job ${job.name} - Nomad`);
    30      });
    31  
    32      test('the subnav links to overview', async function(assert) {
    33        await JobDetail.tabFor('overview').visit();
    34        assert.equal(currentURL(), `/jobs/${job.id}`);
    35      });
    36  
    37      test('the subnav links to definition', async function(assert) {
    38        await JobDetail.tabFor('definition').visit();
    39        assert.equal(currentURL(), `/jobs/${job.id}/definition`);
    40      });
    41  
    42      test('the subnav links to versions', async function(assert) {
    43        await JobDetail.tabFor('versions').visit();
    44        assert.equal(currentURL(), `/jobs/${job.id}/versions`);
    45      });
    46  
    47      test('the subnav links to evaluations', async function(assert) {
    48        await JobDetail.tabFor('evaluations').visit();
    49        assert.equal(currentURL(), `/jobs/${job.id}/evaluations`);
    50      });
    51  
    52      test('the title buttons are dependent on job status', async function(assert) {
    53        if (job.status === 'dead') {
    54          assert.ok(JobDetail.start.isPresent);
    55          assert.notOk(JobDetail.stop.isPresent);
    56          assert.notOk(JobDetail.execButton.isPresent);
    57        } else {
    58          assert.notOk(JobDetail.start.isPresent);
    59          assert.ok(JobDetail.stop.isPresent);
    60          assert.ok(JobDetail.execButton.isPresent);
    61        }
    62      });
    63  
    64      if (context === 'allocations') {
    65        test('allocations for the job are shown in the overview', async function(assert) {
    66          assert.ok(JobDetail.allocationsSummary, 'Allocations are shown in the summary section');
    67          assert.notOk(JobDetail.childrenSummary, 'Children are not shown in the summary section');
    68        });
    69  
    70        test('clicking in an allocation row navigates to that allocation', async function(assert) {
    71          const allocationRow = JobDetail.allocations[0];
    72          const allocationId = allocationRow.id;
    73  
    74          await allocationRow.visitRow();
    75  
    76          assert.equal(
    77            currentURL(),
    78            `/allocations/${allocationId}`,
    79            'Allocation row links to allocation detail'
    80          );
    81        });
    82      }
    83  
    84      if (context === 'children') {
    85        test('children for the job are shown in the overview', async function(assert) {
    86          assert.ok(JobDetail.childrenSummary, 'Children are shown in the summary section');
    87          assert.notOk(
    88            JobDetail.allocationsSummary,
    89            'Allocations are not shown in the summary section'
    90          );
    91        });
    92      }
    93  
    94      for (var testName in additionalTests) {
    95        test(testName, async function(assert) {
    96          await additionalTests[testName](job, assert);
    97        });
    98      }
    99    });
   100  }