Acceptance tests for scaling events

This commit is contained in:
Michael Lange 2020-07-27 23:18:10 -07:00
parent 8a995a0db8
commit 4b7f431981
5 changed files with 75 additions and 14 deletions

View file

@ -1,7 +1,7 @@
import { inject as service } from '@ember/service';
import { alias, readOnly } from '@ember/object/computed';
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { action, computed, get } from '@ember/object';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
@ -51,6 +51,15 @@ export default class TaskGroupController extends Controller.extend(
@alias('listSorted') listToSearch;
@alias('listSearched') sortedAllocations;
@computed('model.scaleState.events.@each.time', function() {
const events = get(this, 'model.scaleState.events');
if (events) {
return events.sortBy('time').reverse();
}
return [];
})
sortedScaleEvents;
@computed('model.job.runningDeployment')
get tooltipText() {
if (this.can.cannot('scale job')) return "You aren't allowed to scale task groups";

View file

@ -138,34 +138,35 @@
<LifecycleChart @tasks={{this.model.tasks}} />
{{#if this.model.scaleState.isVisible}}
{{! this is where the accordion goes }}
<div data-test-scaling-events class="boxed-section">
<div class="boxed-section-head">
Recent Scaling Events
</div>
<div class="boxed-section-body">
<ListAccordion @source={{this.model.scaleState.events}} @key="time" as |a|>
<ListAccordion data-test-scale-events @source={{this.sortedScaleEvents}} @key="time" as |a|>
<a.head @buttonLabel="details" @isExpandable={{a.item.hasMeta}} class="with-columns">
<div class="columns inline-definitions">
<div class="column is-3">
<span class="icon-field">
<span class="icon-container" title="{{if a.item.error "Error event"}}">
<span class="icon-container" title="{{if a.item.error "Error event"}}" data-test-error={{a.item.error}}>
{{#if a.item.error}}{{x-icon "cancel-circle-fill" class="is-danger"}}{{/if}}
</span>
<span data-test-time>{{format-ts a.item.time}}</span>
<span data-test-time title="{{format-ts a.item.time}}">{{format-month-ts a.item.time}}</span>
</span>
</div>
<div class="column is-2">
{{#if a.item.count}}
{{#if a.item.increased}}
{{x-icon "arrow-up" class="is-danger"}}
{{else}}
{{x-icon "arrow-down" class="is-primary"}}
{{/if}}
<span>{{a.item.count}}</span>
{{#if (gte a.item.count 0)}}
<span data-test-count-icon>
{{#if a.item.increased}}
{{x-icon "arrow-up" class="is-danger"}}
{{else}}
{{x-icon "arrow-down" class="is-primary"}}
{{/if}}
</span>
<span data-test-count>{{a.item.count}}</span>
{{/if}}
</div>
<div class="column">
<div class="column" data-test-message>
{{a.item.message}}
</div>
</div>

View file

@ -3,5 +3,5 @@ import { Model, hasMany, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
task_groups: hasMany('task-group'),
job_summary: belongsTo('job-summary'),
job_scale: belongsTo('job-scale'),
jobScale: belongsTo('job-scale'),
});

View file

@ -406,4 +406,39 @@ module('Acceptance | task group detail', function(hooks) {
await TaskGroup.visit({ id: job.id, name: taskGroup.name });
},
});
test('when a task group has no scaling events, there is no recent scaling events section', async function(assert) {
const taskGroupScale = job.jobScale.taskGroupScales.models.find(m => m.name === taskGroup.name);
taskGroupScale.update({ events: [] });
taskGroupScale.save();
await TaskGroup.visit({ id: job.id, name: taskGroup.name });
assert.notOk(TaskGroup.hasScaleEvents);
});
test('the recent scaling events section shows all recent scaling events in reverse chronological order', async function(assert) {
const taskGroupScale = job.jobScale.taskGroupScales.models.find(m => m.name === taskGroup.name);
const scaleEvents = taskGroupScale.events.models.sortBy('time').reverse();
await TaskGroup.visit({ id: job.id, name: taskGroup.name });
assert.ok(TaskGroup.hasScaleEvents);
scaleEvents.forEach((scaleEvent, idx) => {
const ScaleEvent = TaskGroup.scaleEvents[idx];
assert.equal(ScaleEvent.time, moment(scaleEvent.time / 1000000).format('MMM DD HH:mm:ss ZZ'));
assert.equal(ScaleEvent.message, scaleEvent.message);
assert.equal(ScaleEvent.count, scaleEvent.count);
if (scaleEvent.error) {
assert.ok(ScaleEvent.error);
}
if (Object.keys(scaleEvent.meta).length) {
assert.ok(ScaleEvent.isToggleable);
} else {
assert.notOk(ScaleEvent.isToggleable);
}
});
});
});

View file

@ -53,6 +53,22 @@ export default create({
permissions: text('[data-test-volume-permissions]'),
}),
hasScaleEvents: isPresent('[data-test-scale-events]'),
scaleEvents: collection('[data-test-scale-events] [data-test-accordion-head]', {
error: isPresent('[data-test-error]'),
time: text('[data-test-time]'),
count: text('[data-test-count]'),
countIcon: { scope: '[data-test-count-icon]' },
message: text('[data-test-message]'),
isToggleable: isPresent('[data-test-accordion-toggle]:not(.is-invisible)'),
toggle: clickable('[data-test-accordion-toggle]'),
}),
scaleEventBodies: collection('[data-test-scale-events] [data-test-accordion-body]', {
meta: text(),
}),
error: error(),
emptyState: {