2020-05-13 04:29:27 +00:00
|
|
|
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';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-05-13 04:29:27 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Integration | Component | plugin allocation row', function (hooks) {
|
2020-05-13 04:29:27 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-05-13 04:29:27 +00:00
|
|
|
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 () {
|
2020-05-13 04:29:27 +00:00
|
|
|
this.server.shutdown();
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('Plugin allocation row immediately fetches the plugin allocation', async function (assert) {
|
2021-12-28 19:30:38 +00:00
|
|
|
assert.expect(2);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const plugin = this.server.create('csi-plugin', {
|
|
|
|
id: 'plugin',
|
|
|
|
controllerRequired: true,
|
|
|
|
});
|
2020-05-13 04:29:27 +00:00
|
|
|
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`
|
2020-06-01 19:03:56 +00:00
|
|
|
<PluginAllocationRow @pluginAllocation={{plugin}} />
|
2020-05-13 04:29:27 +00:00
|
|
|
`);
|
|
|
|
|
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}`
|
2020-05-13 04:29:27 +00:00
|
|
|
);
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
2020-05-13 04:29:27 +00:00
|
|
|
});
|
|
|
|
|
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,
|
|
|
|
});
|
2020-05-13 04:29:27 +00:00
|
|
|
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`
|
2020-06-01 19:03:56 +00:00
|
|
|
<PluginAllocationRow @pluginAllocation={{plugin}} />
|
2020-05-13 04:29:27 +00:00
|
|
|
`);
|
|
|
|
|
|
|
|
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`
|
|
|
|
);
|
2020-05-13 04:29:27 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('Setting a new plugin fetches the new plugin allocation', async function (assert) {
|
2020-05-13 04:29:27 +00:00
|
|
|
const plugin = this.server.create('csi-plugin', {
|
|
|
|
id: 'plugin',
|
|
|
|
isMonolith: false,
|
2020-05-18 22:28:41 +00:00
|
|
|
controllerRequired: true,
|
2020-05-13 04:29:27 +00:00
|
|
|
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`
|
2020-06-01 19:03:56 +00:00
|
|
|
<PluginAllocationRow @pluginAllocation={{plugin}} />
|
2020-05-13 04:29:27 +00:00
|
|
|
`);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
const allocationRequest = this.server.pretender.handledRequests.find(
|
|
|
|
(req) => req.url.startsWith('/v1/allocation')
|
2020-05-13 04:29:27 +00:00
|
|
|
);
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRequest.url,
|
|
|
|
`/v1/allocation/${storageController.allocID}`
|
|
|
|
);
|
2020-05-13 04:29:27 +00:00
|
|
|
|
|
|
|
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'))
|
2020-05-13 04:29:27 +00:00
|
|
|
.reverse()[0];
|
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
latestAllocationRequest.url,
|
|
|
|
`/v1/allocation/${storageController2.allocID}`
|
|
|
|
);
|
2020-05-13 04:29:27 +00:00
|
|
|
});
|
|
|
|
});
|