Files
nomad/ui/tests/integration/components/lifecycle-chart-test.js
Buck Doyle 5eddb14a33 Add component accessibility auditing and fixes (#8679)
This continues #8455 by adding accessibility audits to component integration
tests and fixing associated errors. It adds audits to existing tests rather than
adding separate ones to facilitate auditing the various permutations a
component’s rendering can go through.

It also adds linting to ensure audits happen in component tests. This
necessitated consolidating test files that were scattered.
2020-08-25 10:56:02 -05:00

106 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
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',
name: 'main two',
},
{
lifecycleName: 'main',
name: 'main one',
},
{
lifecycleName: 'prestart',
name: 'prestart',
},
{
lifecycleName: 'sidecar',
name: 'sidecar',
},
];
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);
await render(hbs`<LifecycleChart @tasks={{tasks}} />`);
assert.ok(Chart.isPresent);
assert.equal(Chart.phases[0].name, 'Prestart');
assert.equal(Chart.phases[1].name, 'Main');
Chart.phases.forEach(phase => assert.notOk(phase.isActive));
assert.deepEqual(Chart.tasks.mapBy('name'), ['prestart', 'sidecar', 'main one', 'main two']);
assert.deepEqual(Chart.tasks.mapBy('lifecycle'), [
'Prestart Task',
'Sidecar Task',
'Main Task',
'Main Task',
]);
assert.ok(Chart.tasks[0].isPrestart);
assert.ok(Chart.tasks[1].isSidecar);
assert.ok(Chart.tasks[2].isMain);
Chart.tasks.forEach(task => {
assert.notOk(task.isActive);
assert.notOk(task.isFinished);
});
await componentA11yAudit(this.element, assert);
});
test('it doesnt render when theres only one phase', async function(assert) {
this.set('tasks', [
{
lifecycleName: 'main',
},
]);
await render(hbs`<LifecycleChart @tasks={{tasks}} />`);
assert.notOk(Chart.isPresent);
});
test('it reflects phase and task states when states are passed in', async function(assert) {
this.set(
'taskStates',
tasks.map(task => {
return { task };
})
);
await render(hbs`<LifecycleChart @taskStates={{taskStates}} />`);
assert.ok(Chart.isPresent);
Chart.phases.forEach(phase => assert.notOk(phase.isActive));
Chart.tasks.forEach(task => {
assert.notOk(task.isActive);
assert.notOk(task.isFinished);
});
this.set('taskStates.firstObject.state', 'running');
await settled();
assert.ok(Chart.phases[1].isActive);
assert.ok(Chart.tasks[3].isActive);
await componentA11yAudit(this.element, assert);
this.set('taskStates.firstObject.finishedAt', new Date());
await settled();
assert.ok(Chart.tasks[3].isFinished);
});
});