github.com/anuvu/nomad@v0.8.7-atom1/ui/tests/integration/job-page/parts/running-deployment-test.js (about)

     1  import { getOwner } from '@ember/application';
     2  import { test, moduleForComponent } from 'ember-qunit';
     3  import { click, find } from 'ember-native-dom-helpers';
     4  import wait from 'ember-test-helpers/wait';
     5  import hbs from 'htmlbars-inline-precompile';
     6  import moment from 'moment';
     7  import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
     8  import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
     9  
    10  moduleForComponent(
    11    'job-page/parts/running-deployment',
    12    'Integration | Component | job-page/parts/running-deployment',
    13    {
    14      integration: true,
    15      beforeEach() {
    16        fragmentSerializerInitializer(getOwner(this));
    17        window.localStorage.clear();
    18        this.store = getOwner(this).lookup('service:store');
    19        this.server = startMirage();
    20        this.server.create('namespace');
    21      },
    22      afterEach() {
    23        this.server.shutdown();
    24        window.localStorage.clear();
    25      },
    26    }
    27  );
    28  
    29  test('there is no active deployment section when the job has no active deployment', function(assert) {
    30    this.server.create('job', {
    31      type: 'service',
    32      noActiveDeployment: true,
    33      createAllocations: false,
    34    });
    35  
    36    this.store.findAll('job');
    37  
    38    return wait().then(() => {
    39      this.set('job', this.store.peekAll('job').get('firstObject'));
    40      this.render(hbs`
    41        {{job-page/parts/running-deployment job=job}})
    42      `);
    43  
    44      return wait().then(() => {
    45        assert.notOk(find('[data-test-active-deployment]'), 'No active deployment');
    46      });
    47    });
    48  });
    49  
    50  test('the active deployment section shows up for the currently running deployment', function(assert) {
    51    this.server.create('job', { type: 'service', createAllocations: false, activeDeployment: true });
    52  
    53    this.store.findAll('job');
    54  
    55    return wait().then(() => {
    56      this.set('job', this.store.peekAll('job').get('firstObject'));
    57      this.render(hbs`
    58        {{job-page/parts/running-deployment job=job}}
    59      `);
    60  
    61      return wait().then(() => {
    62        const deployment = this.get('job.runningDeployment');
    63        const version = deployment.get('version');
    64  
    65        assert.ok(find('[data-test-active-deployment]'), 'Active deployment');
    66        assert.equal(
    67          find('[data-test-active-deployment-stat="id"]').textContent.trim(),
    68          deployment.get('shortId'),
    69          'The active deployment is the most recent running deployment'
    70        );
    71  
    72        assert.equal(
    73          find('[data-test-active-deployment-stat="submit-time"]').textContent.trim(),
    74          moment(version.get('submitTime')).fromNow(),
    75          'Time since the job was submitted is in the active deployment header'
    76        );
    77  
    78        assert.equal(
    79          find('[data-test-deployment-metric="canaries"]').textContent.trim(),
    80          `${deployment.get('placedCanaries')} / ${deployment.get('desiredCanaries')}`,
    81          'Canaries, both places and desired, are in the metrics'
    82        );
    83  
    84        assert.equal(
    85          find('[data-test-deployment-metric="placed"]').textContent.trim(),
    86          deployment.get('placedAllocs'),
    87          'Placed allocs aggregates across task groups'
    88        );
    89  
    90        assert.equal(
    91          find('[data-test-deployment-metric="desired"]').textContent.trim(),
    92          deployment.get('desiredTotal'),
    93          'Desired allocs aggregates across task groups'
    94        );
    95  
    96        assert.equal(
    97          find('[data-test-deployment-metric="healthy"]').textContent.trim(),
    98          deployment.get('healthyAllocs'),
    99          'Healthy allocs aggregates across task groups'
   100        );
   101  
   102        assert.equal(
   103          find('[data-test-deployment-metric="unhealthy"]').textContent.trim(),
   104          deployment.get('unhealthyAllocs'),
   105          'Unhealthy allocs aggregates across task groups'
   106        );
   107  
   108        assert.equal(
   109          find('[data-test-deployment-notification]').textContent.trim(),
   110          deployment.get('statusDescription'),
   111          'Status description is in the metrics block'
   112        );
   113      });
   114    });
   115  });
   116  
   117  test('the active deployment section can be expanded to show task groups and allocations', function(assert) {
   118    this.server.create('node');
   119    this.server.create('job', { type: 'service', activeDeployment: true });
   120  
   121    this.store.findAll('job');
   122  
   123    return wait().then(() => {
   124      this.set('job', this.store.peekAll('job').get('firstObject'));
   125      this.render(hbs`
   126        {{job-page/parts/running-deployment job=job}}
   127      `);
   128  
   129      return wait().then(() => {
   130        assert.notOk(find('[data-test-deployment-task-groups]'), 'Task groups not found');
   131        assert.notOk(find('[data-test-deployment-allocations]'), 'Allocations not found');
   132  
   133        click('[data-test-deployment-toggle-details]');
   134  
   135        return wait().then(() => {
   136          assert.ok(find('[data-test-deployment-task-groups]'), 'Task groups found');
   137          assert.ok(find('[data-test-deployment-allocations]'), 'Allocations found');
   138        });
   139      });
   140    });
   141  });
   142  
   143  test('each task group in the expanded task group section shows task group details', function(assert) {
   144    this.server.create('node');
   145    this.server.create('job', { type: 'service', activeDeployment: true });
   146  
   147    this.store.findAll('job');
   148  
   149    return wait().then(() => {
   150      const job = this.store.peekAll('job').get('firstObject');
   151  
   152      this.set('job', job);
   153      this.render(hbs`
   154        {{job-page/parts/running-deployment job=job}}
   155      `);
   156  
   157      return wait()
   158        .then(() => {
   159          click('[data-test-deployment-toggle-details]');
   160          return wait();
   161        })
   162        .then(() => {
   163          const task = job.get('runningDeployment.taskGroupSummaries.firstObject');
   164          const findForTaskGroup = selector => find(`[data-test-deployment-task-group-${selector}]`);
   165          assert.equal(findForTaskGroup('name').textContent.trim(), task.get('name'));
   166          assert.equal(
   167            findForTaskGroup('progress-deadline').textContent.trim(),
   168            moment(task.get('requireProgressBy')).format('MM/DD/YY HH:mm:ss')
   169          );
   170        });
   171    });
   172  });