github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/job-definition-test.js (about)

     1  import { currentURL } from 'ember-native-dom-helpers';
     2  import { test } from 'qunit';
     3  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     4  import Definition from 'nomad-ui/tests/pages/jobs/job/definition';
     5  
     6  let job;
     7  
     8  moduleForAcceptance('Acceptance | job definition', {
     9    beforeEach() {
    10      server.create('node');
    11      server.create('job');
    12      job = server.db.jobs[0];
    13      Definition.visit({ id: job.id });
    14    },
    15  });
    16  
    17  test('visiting /jobs/:job_id/definition', function(assert) {
    18    assert.equal(currentURL(), `/jobs/${job.id}/definition`);
    19  });
    20  
    21  test('the job definition page contains a json viewer component', function(assert) {
    22    assert.ok(Definition.jsonViewer, 'JSON viewer found');
    23  });
    24  
    25  test('the job definition page requests the job to display in an unmutated form', function(assert) {
    26    const jobURL = `/v1/job/${job.id}`;
    27    const jobRequests = server.pretender.handledRequests
    28      .map(req => req.url.split('?')[0])
    29      .filter(url => url === jobURL);
    30    assert.ok(jobRequests.length === 2, 'Two requests for the job were made');
    31  });
    32  
    33  test('the job definition can be edited', function(assert) {
    34    assert.notOk(Definition.editor.isPresent, 'Editor is not shown on load');
    35  
    36    Definition.edit();
    37  
    38    andThen(() => {
    39      assert.ok(Definition.editor.isPresent, 'Editor is shown after clicking edit');
    40      assert.notOk(Definition.jsonViewer, 'Editor replaces the JSON viewer');
    41    });
    42  });
    43  
    44  test('when in editing mode, the action can be canceled, showing the read-only definition again', function(assert) {
    45    Definition.edit();
    46  
    47    andThen(() => {
    48      Definition.editor.cancelEditing();
    49    });
    50  
    51    andThen(() => {
    52      assert.ok(Definition.jsonViewer, 'The JSON Viewer is back');
    53      assert.notOk(Definition.editor.isPresent, 'The editor is gone');
    54    });
    55  });
    56  
    57  test('when in editing mode, the editor is prepopulated with the job definition', function(assert) {
    58    const requests = server.pretender.handledRequests;
    59    const jobDefinition = requests.findBy('url', `/v1/job/${job.id}`).responseText;
    60    const formattedJobDefinition = JSON.stringify(JSON.parse(jobDefinition), null, 2);
    61  
    62    Definition.edit();
    63  
    64    andThen(() => {
    65      assert.equal(
    66        Definition.editor.editor.contents,
    67        formattedJobDefinition,
    68        'The editor already has the job definition in it'
    69      );
    70    });
    71  });
    72  
    73  test('when changes are submitted, the site redirects to the job overview page', function(assert) {
    74    Definition.edit();
    75  
    76    andThen(() => {
    77      Definition.editor.plan();
    78      Definition.editor.run();
    79    });
    80  
    81    andThen(() => {
    82      assert.equal(currentURL(), `/jobs/${job.id}`, 'Now on the job overview page');
    83    });
    84  });