open-nomad/ui/tests/integration/components/primary-metric/node-test.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2021-03-22 06:01:22 +00:00
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { find, render } from '@ember/test-helpers';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
import hbs from 'htmlbars-inline-precompile';
import { setupPrimaryMetricMocks, primaryMetric } from './primary-metric';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { formatScheduledHertz } from 'nomad-ui/utils/units';
2021-03-22 06:01:22 +00:00
2021-12-28 14:45:20 +00:00
module('Integration | Component | PrimaryMetric::Node', function (hooks) {
2021-03-22 06:01:22 +00:00
setupRenderingTest(hooks);
setupPrimaryMetricMocks(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
2021-03-22 06:01:22 +00:00
fragmentSerializerInitializer(this.owner);
this.store = this.owner.lookup('service:store');
this.server = startMirage();
this.server.create('namespace');
this.server.create('node');
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
2021-03-22 06:01:22 +00:00
this.server.shutdown();
});
const template = hbs`
<PrimaryMetric::Node
@node={{this.resource}}
@metric={{this.metric}} />
`;
2021-12-28 14:45:20 +00:00
const preload = async (store) => {
2021-03-22 06:01:22 +00:00
await store.findAll('node');
};
2021-12-28 14:45:20 +00:00
const findResource = (store) => store.peekAll('node').get('firstObject');
2021-03-22 06:01:22 +00:00
2021-12-28 14:45:20 +00:00
test('Must pass an accessibility audit', async function (assert) {
2021-03-22 06:01:22 +00:00
await preload(this.store);
const resource = findResource(this.store);
this.setProperties({ resource, metric: 'cpu' });
await render(template);
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('When the node has a reserved amount for the metric, a horizontal annotation is shown', async function (assert) {
2021-03-22 06:01:22 +00:00
this.server.create('node', 'reserved', { id: 'withAnnotation' });
await preload(this.store);
const resource = this.store.peekRecord('node', 'withAnnotation');
this.setProperties({ resource, metric: 'cpu' });
await render(template);
assert.ok(find('[data-test-annotation]'));
assert.equal(
find('[data-test-annotation]').textContent.trim(),
`${formatScheduledHertz(resource.reserved.cpu, 'MHz')} reserved`
2021-03-22 06:01:22 +00:00
);
});
primaryMetric({
template,
preload,
findResource,
});
});