github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/tests/integration/job-page/periodic-test.js (about)

     1  import { getOwner } from '@ember/application';
     2  import { test, moduleForComponent } from 'ember-qunit';
     3  import { click, findAll } from 'ember-native-dom-helpers';
     4  import wait from 'ember-test-helpers/wait';
     5  import hbs from 'htmlbars-inline-precompile';
     6  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     7  
     8  moduleForComponent('job-page/periodic', 'Integration | Component | job-page/periodic', {
     9    integration: true,
    10    beforeEach() {
    11      window.localStorage.clear();
    12      this.store = getOwner(this).lookup('service:store');
    13      this.server = startMirage();
    14      this.server.create('namespace');
    15    },
    16    afterEach() {
    17      this.server.shutdown();
    18      window.localStorage.clear();
    19    },
    20  });
    21  
    22  test('Clicking Force Launch launches a new periodic child job', function(assert) {
    23    const childrenCount = 3;
    24  
    25    this.server.create('job', 'periodic', {
    26      id: 'parent',
    27      childrenCount,
    28      createAllocations: false,
    29    });
    30  
    31    this.store.findAll('job');
    32  
    33    return wait().then(() => {
    34      const job = this.store.peekAll('job').findBy('plainId', 'parent');
    35      this.setProperties({
    36        job,
    37        sortProperty: 'name',
    38        sortDescending: true,
    39        currentPage: 1,
    40        gotoJob: () => {},
    41      });
    42  
    43      this.render(hbs`
    44        {{job-page/periodic
    45          job=job
    46          sortProperty=sortProperty
    47          sortDescending=sortDescending
    48          currentPage=currentPage
    49          gotoJob=gotoJob}}
    50      `);
    51  
    52      return wait().then(() => {
    53        const currentJobCount = server.db.jobs.length;
    54  
    55        assert.equal(
    56          findAll('[data-test-job-name]').length,
    57          childrenCount,
    58          'The new periodic job launch is in the children list'
    59        );
    60  
    61        click('[data-test-force-launch]');
    62  
    63        return wait().then(() => {
    64          const id = job.get('plainId');
    65          const namespace = job.get('namespace.name') || 'default';
    66          let expectedURL = `/v1/job/${id}/periodic/force`;
    67          if (namespace !== 'default') {
    68            expectedURL += `?namespace=${namespace}`;
    69          }
    70  
    71          assert.ok(
    72            server.pretender.handledRequests
    73              .filterBy('method', 'POST')
    74              .find(req => req.url === expectedURL),
    75            'POST URL was correct'
    76          );
    77  
    78          assert.ok(server.db.jobs.length, currentJobCount + 1, 'POST request was made');
    79  
    80          return wait().then(() => {
    81            assert.equal(
    82              findAll('[data-test-job-name]').length,
    83              childrenCount + 1,
    84              'The new periodic job launch is in the children list'
    85            );
    86          });
    87        });
    88      });
    89    });
    90  });