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

     1  import { run } from '@ember/runloop';
     2  import { getOwner } from '@ember/application';
     3  import { test, moduleForComponent } from 'ember-qunit';
     4  import { findAll } from 'ember-native-dom-helpers';
     5  import wait from 'ember-test-helpers/wait';
     6  import hbs from 'htmlbars-inline-precompile';
     7  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     8  
     9  moduleForComponent(
    10    'job-page/parts/evaluations',
    11    'Integration | Component | job-page/parts/evaluations',
    12    {
    13      integration: true,
    14      beforeEach() {
    15        window.localStorage.clear();
    16        this.store = getOwner(this).lookup('service:store');
    17        this.server = startMirage();
    18        this.server.create('namespace');
    19      },
    20      afterEach() {
    21        this.server.shutdown();
    22        window.localStorage.clear();
    23      },
    24    }
    25  );
    26  
    27  test('lists all evaluations for the job', function(assert) {
    28    let job;
    29  
    30    this.server.create('job', { noFailedPlacements: true, createAllocations: false });
    31    this.store.findAll('job');
    32  
    33    return wait().then(() => {
    34      run(() => {
    35        job = this.store.peekAll('job').get('firstObject');
    36      });
    37  
    38      this.setProperties({ job });
    39  
    40      this.render(hbs`
    41        {{job-page/parts/evaluations job=job}}
    42      `);
    43  
    44      return wait().then(() => {
    45        const evaluationRows = findAll('[data-test-evaluation]');
    46        assert.equal(
    47          evaluationRows.length,
    48          job.get('evaluations.length'),
    49          'All evaluations are listed'
    50        );
    51  
    52        job
    53          .get('evaluations')
    54          .sortBy('modifyIndex')
    55          .reverse()
    56          .forEach((evaluation, index) => {
    57            assert.equal(
    58              evaluationRows[index].querySelector('[data-test-id]').textContent.trim(),
    59              evaluation.get('shortId'),
    60              `Evaluation ${index} is ${evaluation.get('shortId')}`
    61            );
    62          });
    63      });
    64    });
    65  });