github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/integration/job-page/parts/latest-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/latest-deployment',
    12    'Integration | Component | job-page/parts/latest-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 latest deployment section when the job has no deployments', function(assert) {
    30    this.server.create('job', {
    31      type: 'service',
    32      noDeployments: 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/latest-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 latest 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/latest-deployment job=job}}
    59      `);
    60  
    61      return wait().then(() => {
    62        const deployment = this.get('job.latestDeployment');
    63        const version = deployment.get('version');
    64  
    65        assert.ok(find('[data-test-active-deployment]'), 'Active deployment');
    66        assert.ok(
    67          find('[data-test-active-deployment]').classList.contains('is-info'),
    68          'Running deployment gets the is-info class'
    69        );
    70        assert.equal(
    71          find('[data-test-active-deployment-stat="id"]').textContent.trim(),
    72          deployment.get('shortId'),
    73          'The active deployment is the most recent running deployment'
    74        );
    75  
    76        assert.equal(
    77          find('[data-test-active-deployment-stat="submit-time"]').textContent.trim(),
    78          moment(version.get('submitTime')).fromNow(),
    79          'Time since the job was submitted is in the active deployment header'
    80        );
    81  
    82        assert.equal(
    83          find('[data-test-deployment-metric="canaries"]').textContent.trim(),
    84          `${deployment.get('placedCanaries')} / ${deployment.get('desiredCanaries')}`,
    85          'Canaries, both places and desired, are in the metrics'
    86        );
    87  
    88        assert.equal(
    89          find('[data-test-deployment-metric="placed"]').textContent.trim(),
    90          deployment.get('placedAllocs'),
    91          'Placed allocs aggregates across task groups'
    92        );
    93  
    94        assert.equal(
    95          find('[data-test-deployment-metric="desired"]').textContent.trim(),
    96          deployment.get('desiredTotal'),
    97          'Desired allocs aggregates across task groups'
    98        );
    99  
   100        assert.equal(
   101          find('[data-test-deployment-metric="healthy"]').textContent.trim(),
   102          deployment.get('healthyAllocs'),
   103          'Healthy allocs aggregates across task groups'
   104        );
   105  
   106        assert.equal(
   107          find('[data-test-deployment-metric="unhealthy"]').textContent.trim(),
   108          deployment.get('unhealthyAllocs'),
   109          'Unhealthy allocs aggregates across task groups'
   110        );
   111  
   112        assert.equal(
   113          find('[data-test-deployment-notification]').textContent.trim(),
   114          deployment.get('statusDescription'),
   115          'Status description is in the metrics block'
   116        );
   117      });
   118    });
   119  });
   120  
   121  test('when there is no running deployment, the latest deployment section shows up for the last deployment', function(assert) {
   122    this.server.create('job', {
   123      type: 'service',
   124      createAllocations: false,
   125      noActiveDeployment: true,
   126    });
   127  
   128    this.store.findAll('job');
   129  
   130    return wait().then(() => {
   131      this.set('job', this.store.peekAll('job').get('firstObject'));
   132      this.render(hbs`
   133        {{job-page/parts/latest-deployment job=job}}
   134      `);
   135  
   136      return wait().then(() => {
   137        assert.ok(find('[data-test-active-deployment]'), 'Active deployment');
   138        assert.notOk(
   139          find('[data-test-active-deployment]').classList.contains('is-info'),
   140          'Non-running deployment does not get the is-info class'
   141        );
   142      });
   143    });
   144  });
   145  
   146  test('the latest deployment section can be expanded to show task groups and allocations', function(assert) {
   147    this.server.create('node');
   148    this.server.create('job', { type: 'service', activeDeployment: true });
   149  
   150    this.store.findAll('job');
   151  
   152    return wait().then(() => {
   153      this.set('job', this.store.peekAll('job').get('firstObject'));
   154      this.render(hbs`
   155        {{job-page/parts/latest-deployment job=job}}
   156      `);
   157  
   158      return wait().then(() => {
   159        assert.notOk(find('[data-test-deployment-task-groups]'), 'Task groups not found');
   160        assert.notOk(find('[data-test-deployment-allocations]'), 'Allocations not found');
   161  
   162        click('[data-test-deployment-toggle-details]');
   163  
   164        return wait().then(() => {
   165          assert.ok(find('[data-test-deployment-task-groups]'), 'Task groups found');
   166          assert.ok(find('[data-test-deployment-allocations]'), 'Allocations found');
   167        });
   168      });
   169    });
   170  });
   171  
   172  test('each task group in the expanded task group section shows task group details', function(assert) {
   173    this.server.create('node');
   174    this.server.create('job', { type: 'service', activeDeployment: true });
   175  
   176    this.store.findAll('job');
   177  
   178    return wait().then(() => {
   179      const job = this.store.peekAll('job').get('firstObject');
   180  
   181      this.set('job', job);
   182      this.render(hbs`
   183        {{job-page/parts/latest-deployment job=job}}
   184      `);
   185  
   186      return wait()
   187        .then(() => {
   188          click('[data-test-deployment-toggle-details]');
   189          return wait();
   190        })
   191        .then(() => {
   192          const task = job.get('runningDeployment.taskGroupSummaries.firstObject');
   193          const findForTaskGroup = selector => find(`[data-test-deployment-task-group-${selector}]`);
   194          assert.equal(findForTaskGroup('name').textContent.trim(), task.get('name'));
   195          assert.equal(
   196            findForTaskGroup('progress-deadline').textContent.trim(),
   197            moment(task.get('requireProgressBy')).format('MM/DD/YY HH:mm:ss')
   198          );
   199        });
   200    });
   201  });