2020-04-30 13:15:19 +00:00
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
|
import { render, settled } from '@ember/test-helpers';
|
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
2020-08-25 17:17:18 +00:00
|
|
|
|
import { set } from '@ember/object';
|
2020-08-25 15:56:02 +00:00
|
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-04-30 13:15:19 +00:00
|
|
|
|
import { create } from 'ember-cli-page-object';
|
|
|
|
|
import LifecycleChart from 'nomad-ui/tests/pages/components/lifecycle-chart';
|
|
|
|
|
|
|
|
|
|
const Chart = create(LifecycleChart);
|
|
|
|
|
|
|
|
|
|
const tasks = [
|
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'main',
|
2020-08-25 17:17:18 +00:00
|
|
|
|
name: 'main two: 3',
|
2020-04-30 13:15:19 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'main',
|
2020-08-25 17:17:18 +00:00
|
|
|
|
name: 'main one: 2',
|
2020-04-30 13:15:19 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2020-08-25 17:17:18 +00:00
|
|
|
|
lifecycleName: 'prestart-ephemeral',
|
|
|
|
|
name: 'prestart ephemeral: 0',
|
2020-04-30 13:15:19 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
2020-08-25 17:17:18 +00:00
|
|
|
|
lifecycleName: 'prestart-sidecar',
|
|
|
|
|
name: 'prestart sidecar: 1',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'poststart-ephemeral',
|
|
|
|
|
name: 'poststart ephemeral: 5',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'poststart-sidecar',
|
|
|
|
|
name: 'poststart sidecar: 4',
|
|
|
|
|
},
|
2020-09-01 16:49:36 +00:00
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'poststop',
|
|
|
|
|
name: 'poststop: 6',
|
|
|
|
|
},
|
2020-04-30 13:15:19 +00:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
module('Integration | Component | lifecycle-chart', function(hooks) {
|
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
|
|
test('it renders stateless phases and lifecycle- and name-sorted tasks', async function(assert) {
|
|
|
|
|
this.set('tasks', tasks);
|
|
|
|
|
|
2020-07-09 17:30:11 +00:00
|
|
|
|
await render(hbs`<LifecycleChart @tasks={{tasks}} />`);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
assert.ok(Chart.isPresent);
|
|
|
|
|
|
|
|
|
|
assert.equal(Chart.phases[0].name, 'Prestart');
|
|
|
|
|
assert.equal(Chart.phases[1].name, 'Main');
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.equal(Chart.phases[2].name, 'Poststart');
|
2020-09-01 16:49:36 +00:00
|
|
|
|
assert.equal(Chart.phases[3].name, 'Poststop');
|
2020-04-30 13:15:19 +00:00
|
|
|
|
|
|
|
|
|
Chart.phases.forEach(phase => assert.notOk(phase.isActive));
|
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.deepEqual(Chart.tasks.mapBy('name'), [
|
|
|
|
|
'prestart ephemeral: 0',
|
|
|
|
|
'prestart sidecar: 1',
|
|
|
|
|
'main one: 2',
|
|
|
|
|
'main two: 3',
|
|
|
|
|
'poststart sidecar: 4',
|
|
|
|
|
'poststart ephemeral: 5',
|
2020-09-01 16:49:36 +00:00
|
|
|
|
'poststop: 6',
|
2020-08-25 17:17:18 +00:00
|
|
|
|
]);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
assert.deepEqual(Chart.tasks.mapBy('lifecycle'), [
|
|
|
|
|
'Prestart Task',
|
|
|
|
|
'Sidecar Task',
|
|
|
|
|
'Main Task',
|
|
|
|
|
'Main Task',
|
2020-08-25 17:17:18 +00:00
|
|
|
|
'Sidecar Task',
|
|
|
|
|
'Poststart Task',
|
2020-09-01 16:49:36 +00:00
|
|
|
|
'Poststop Task',
|
2020-04-30 13:15:19 +00:00
|
|
|
|
]);
|
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.ok(Chart.tasks[0].isPrestartEphemeral);
|
|
|
|
|
assert.ok(Chart.tasks[1].isPrestartSidecar);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
assert.ok(Chart.tasks[2].isMain);
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.ok(Chart.tasks[4].isPoststartSidecar);
|
|
|
|
|
assert.ok(Chart.tasks[5].isPoststartEphemeral);
|
2020-09-01 16:49:36 +00:00
|
|
|
|
assert.ok(Chart.tasks[6].isPoststop);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
|
|
|
|
|
Chart.tasks.forEach(task => {
|
|
|
|
|
assert.notOk(task.isActive);
|
|
|
|
|
assert.notOk(task.isFinished);
|
|
|
|
|
});
|
2020-08-25 15:56:02 +00:00
|
|
|
|
|
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('it doesn’t render when there’s only one phase', async function(assert) {
|
|
|
|
|
this.set('tasks', [
|
|
|
|
|
{
|
|
|
|
|
lifecycleName: 'main',
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2020-07-09 17:30:11 +00:00
|
|
|
|
await render(hbs`<LifecycleChart @tasks={{tasks}} />`);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
assert.notOk(Chart.isPresent);
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
test('it renders all phases when there are any non-main tasks', async function(assert) {
|
2020-09-01 16:49:36 +00:00
|
|
|
|
this.set('tasks', [tasks[0], tasks[6]]);
|
2020-08-25 17:17:18 +00:00
|
|
|
|
|
|
|
|
|
await render(hbs`<LifecycleChart @tasks={{tasks}} />`);
|
2020-09-01 17:02:10 +00:00
|
|
|
|
assert.equal(Chart.phases.length, 4);
|
2020-08-25 17:17:18 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-30 13:15:19 +00:00
|
|
|
|
test('it reflects phase and task states when states are passed in', async function(assert) {
|
|
|
|
|
this.set(
|
|
|
|
|
'taskStates',
|
|
|
|
|
tasks.map(task => {
|
|
|
|
|
return { task };
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
2020-07-09 17:30:11 +00:00
|
|
|
|
await render(hbs`<LifecycleChart @taskStates={{taskStates}} />`);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
assert.ok(Chart.isPresent);
|
|
|
|
|
|
|
|
|
|
Chart.phases.forEach(phase => assert.notOk(phase.isActive));
|
|
|
|
|
|
|
|
|
|
Chart.tasks.forEach(task => {
|
|
|
|
|
assert.notOk(task.isActive);
|
|
|
|
|
assert.notOk(task.isFinished);
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
// Change poststart-ephemeral to be running
|
|
|
|
|
this.set('taskStates.4.state', 'running');
|
2020-04-30 13:15:19 +00:00
|
|
|
|
await settled();
|
|
|
|
|
|
2020-08-25 15:56:02 +00:00
|
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-04-30 13:15:19 +00:00
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.ok(Chart.tasks[5].isActive);
|
|
|
|
|
|
|
|
|
|
assert.ok(Chart.phases[1].isActive);
|
|
|
|
|
assert.notOk(
|
|
|
|
|
Chart.phases[2].isActive,
|
|
|
|
|
'the poststart phase is nested within main and should never have the active class'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.set('taskStates.4.finishedAt', new Date());
|
2020-04-30 13:15:19 +00:00
|
|
|
|
await settled();
|
|
|
|
|
|
2020-08-25 17:17:18 +00:00
|
|
|
|
assert.ok(Chart.tasks[5].isFinished);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
testName: 'expected active phases',
|
2020-09-01 16:49:36 +00:00
|
|
|
|
runningTaskNames: ['prestart ephemeral', 'main one', 'poststop'],
|
|
|
|
|
activePhaseNames: ['Prestart', 'Main', 'Poststop'],
|
2020-08-25 17:17:18 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: 'sidecar task states don’t affect phase active states',
|
|
|
|
|
runningTaskNames: ['prestart sidecar', 'poststart sidecar'],
|
|
|
|
|
activePhaseNames: [],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
testName: 'poststart ephemeral task states affect main phase active state',
|
|
|
|
|
runningTaskNames: ['poststart ephemeral'],
|
|
|
|
|
activePhaseNames: ['Main'],
|
|
|
|
|
},
|
|
|
|
|
].forEach(async ({ testName, runningTaskNames, activePhaseNames }) => {
|
|
|
|
|
test(testName, async function(assert) {
|
2020-08-27 14:38:34 +00:00
|
|
|
|
this.set('taskStates', tasks.map(task => ({ task })));
|
2020-08-25 17:17:18 +00:00
|
|
|
|
|
|
|
|
|
await render(hbs`<LifecycleChart @taskStates={{taskStates}} />`);
|
|
|
|
|
|
|
|
|
|
runningTaskNames.forEach(taskName => {
|
|
|
|
|
const taskState = this.get('taskStates').find(taskState =>
|
|
|
|
|
taskState.task.name.includes(taskName)
|
|
|
|
|
);
|
|
|
|
|
set(taskState, 'state', 'running');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
Chart.phases.forEach(Phase => {
|
|
|
|
|
if (activePhaseNames.includes(Phase.name)) {
|
|
|
|
|
assert.ok(Phase.isActive, `expected ${Phase.name} not to be active`);
|
|
|
|
|
} else {
|
|
|
|
|
assert.notOk(Phase.isActive, `expected ${Phase.name} phase not to be active`);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-04-30 13:15:19 +00:00
|
|
|
|
});
|
|
|
|
|
});
|