open-nomad/ui/tests/integration/components/plugin-allocation-row-test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.6 KiB
JavaScript
Raw Normal View History

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { render, settled } from '@ember/test-helpers';
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer';
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
2021-12-28 14:45:20 +00:00
module('Integration | Component | plugin allocation row', function (hooks) {
setupRenderingTest(hooks);
2021-12-28 14:45:20 +00:00
hooks.beforeEach(function () {
fragmentSerializerInitializer(this.owner);
this.store = this.owner.lookup('service:store');
this.server = startMirage();
this.server.create('node');
});
2021-12-28 14:45:20 +00:00
hooks.afterEach(function () {
this.server.shutdown();
});
2021-12-28 14:45:20 +00:00
test('Plugin allocation row immediately fetches the plugin allocation', async function (assert) {
assert.expect(2);
2021-12-28 16:08:12 +00:00
const plugin = this.server.create('csi-plugin', {
id: 'plugin',
controllerRequired: true,
});
const storageController = plugin.controllers.models[0];
const pluginRecord = await this.store.find('plugin', 'csi/plugin');
this.setProperties({
plugin: pluginRecord.get('controllers.firstObject'),
});
await render(hbs`
<PluginAllocationRow @pluginAllocation={{plugin}} />
`);
2021-12-28 16:08:12 +00:00
const allocationRequest = this.server.pretender.handledRequests.find(
(req) => req.url.startsWith('/v1/allocation')
);
assert.equal(
allocationRequest.url,
`/v1/allocation/${storageController.allocID}`
);
await componentA11yAudit(this.element, assert);
});
2021-12-28 14:45:20 +00:00
test('After the plugin allocation row fetches the plugin allocation, allocation stats are fetched', async function (assert) {
2021-12-28 16:08:12 +00:00
const plugin = this.server.create('csi-plugin', {
id: 'plugin',
controllerRequired: true,
});
const storageController = plugin.controllers.models[0];
const pluginRecord = await this.store.find('plugin', 'csi/plugin');
this.setProperties({
plugin: pluginRecord.get('controllers.firstObject'),
});
await render(hbs`
<PluginAllocationRow @pluginAllocation={{plugin}} />
`);
const [statsRequest] = this.server.pretender.handledRequests.slice(-1);
2021-12-28 16:08:12 +00:00
assert.equal(
statsRequest.url,
`/v1/client/allocation/${storageController.allocID}/stats`
);
});
2021-12-28 14:45:20 +00:00
test('Setting a new plugin fetches the new plugin allocation', async function (assert) {
const plugin = this.server.create('csi-plugin', {
id: 'plugin',
isMonolith: false,
controllerRequired: true,
controllersExpected: 2,
});
const storageController = plugin.controllers.models[0];
const storageController2 = plugin.controllers.models[1];
const pluginRecord = await this.store.find('plugin', 'csi/plugin');
this.setProperties({
plugin: pluginRecord.get('controllers.firstObject'),
});
await render(hbs`
<PluginAllocationRow @pluginAllocation={{plugin}} />
`);
2021-12-28 16:08:12 +00:00
const allocationRequest = this.server.pretender.handledRequests.find(
(req) => req.url.startsWith('/v1/allocation')
);
2021-12-28 16:08:12 +00:00
assert.equal(
allocationRequest.url,
`/v1/allocation/${storageController.allocID}`
);
this.set('plugin', pluginRecord.get('controllers').toArray()[1]);
await settled();
const latestAllocationRequest = this.server.pretender.handledRequests
2021-12-28 14:45:20 +00:00
.filter((req) => req.url.startsWith('/v1/allocation'))
.reverse()[0];
2021-12-28 16:08:12 +00:00
assert.equal(
latestAllocationRequest.url,
`/v1/allocation/${storageController2.allocID}`
);
});
});