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

     1  import { currentURL } from '@ember/test-helpers';
     2  import { assign } from '@ember/polyfills';
     3  import { module, test } from 'qunit';
     4  import { setupApplicationTest } from 'ember-qunit';
     5  import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
     6  import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
     7  import JobRun from 'nomad-ui/tests/pages/jobs/run';
     8  
     9  const newJobName = 'new-job';
    10  const newJobTaskGroupName = 'redis';
    11  
    12  const jsonJob = overrides => {
    13    return JSON.stringify(
    14      assign(
    15        {},
    16        {
    17          Name: newJobName,
    18          Namespace: 'default',
    19          Datacenters: ['dc1'],
    20          Priority: 50,
    21          TaskGroups: [
    22            {
    23              Name: newJobTaskGroupName,
    24              Tasks: [
    25                {
    26                  Name: 'redis',
    27                  Driver: 'docker',
    28                },
    29              ],
    30            },
    31          ],
    32        },
    33        overrides
    34      ),
    35      null,
    36      2
    37    );
    38  };
    39  
    40  module('Acceptance | job run', function(hooks) {
    41    setupApplicationTest(hooks);
    42    setupMirage(hooks);
    43    setupCodeMirror(hooks);
    44  
    45    hooks.beforeEach(function() {
    46      // Required for placing allocations (a result of creating jobs)
    47      server.create('node');
    48    });
    49  
    50    test('visiting /jobs/run', async function(assert) {
    51      await JobRun.visit();
    52  
    53      assert.equal(currentURL(), '/jobs/run');
    54    });
    55  
    56    test('when submitting a job, the site redirects to the new job overview page', async function(assert) {
    57      const spec = jsonJob();
    58  
    59      await JobRun.visit();
    60  
    61      await JobRun.editor.editor.fillIn(spec);
    62      await JobRun.editor.plan();
    63      await JobRun.editor.run();
    64      assert.equal(
    65        currentURL(),
    66        `/jobs/${newJobName}`,
    67        `Redirected to the job overview page for ${newJobName}`
    68      );
    69    });
    70  
    71    test('when submitting a job to a different namespace, the redirect to the job overview page takes namespace into account', async function(assert) {
    72      const newNamespace = 'second-namespace';
    73  
    74      server.create('namespace', { id: newNamespace });
    75      const spec = jsonJob({ Namespace: newNamespace });
    76  
    77      await JobRun.visit();
    78  
    79      await JobRun.editor.editor.fillIn(spec);
    80      await JobRun.editor.plan();
    81      await JobRun.editor.run();
    82      assert.equal(
    83        currentURL(),
    84        `/jobs/${newJobName}?namespace=${newNamespace}`,
    85        `Redirected to the job overview page for ${newJobName} and switched the namespace to ${newNamespace}`
    86      );
    87    });
    88  });