github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/tests/integration/components/plugin-allocation-row-test.js (about) 1 import { module, test } from 'qunit'; 2 import { setupRenderingTest } from 'ember-qunit'; 3 import hbs from 'htmlbars-inline-precompile'; 4 import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; 5 import { render, settled } from '@ember/test-helpers'; 6 import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; 7 import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit'; 8 9 module('Integration | Component | plugin allocation row', function (hooks) { 10 setupRenderingTest(hooks); 11 12 hooks.beforeEach(function () { 13 fragmentSerializerInitializer(this.owner); 14 this.store = this.owner.lookup('service:store'); 15 this.server = startMirage(); 16 this.server.create('node'); 17 }); 18 19 hooks.afterEach(function () { 20 this.server.shutdown(); 21 }); 22 23 test('Plugin allocation row immediately fetches the plugin allocation', async function (assert) { 24 assert.expect(2); 25 26 const plugin = this.server.create('csi-plugin', { 27 id: 'plugin', 28 controllerRequired: true, 29 }); 30 const storageController = plugin.controllers.models[0]; 31 32 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 33 34 this.setProperties({ 35 plugin: pluginRecord.get('controllers.firstObject'), 36 }); 37 38 await render(hbs` 39 <PluginAllocationRow @pluginAllocation={{plugin}} /> 40 `); 41 42 const allocationRequest = this.server.pretender.handledRequests.find( 43 (req) => req.url.startsWith('/v1/allocation') 44 ); 45 assert.equal( 46 allocationRequest.url, 47 `/v1/allocation/${storageController.allocID}` 48 ); 49 await componentA11yAudit(this.element, assert); 50 }); 51 52 test('After the plugin allocation row fetches the plugin allocation, allocation stats are fetched', async function (assert) { 53 const plugin = this.server.create('csi-plugin', { 54 id: 'plugin', 55 controllerRequired: true, 56 }); 57 const storageController = plugin.controllers.models[0]; 58 59 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 60 61 this.setProperties({ 62 plugin: pluginRecord.get('controllers.firstObject'), 63 }); 64 65 await render(hbs` 66 <PluginAllocationRow @pluginAllocation={{plugin}} /> 67 `); 68 69 const [statsRequest] = this.server.pretender.handledRequests.slice(-1); 70 71 assert.equal( 72 statsRequest.url, 73 `/v1/client/allocation/${storageController.allocID}/stats` 74 ); 75 }); 76 77 test('Setting a new plugin fetches the new plugin allocation', async function (assert) { 78 const plugin = this.server.create('csi-plugin', { 79 id: 'plugin', 80 isMonolith: false, 81 controllerRequired: true, 82 controllersExpected: 2, 83 }); 84 const storageController = plugin.controllers.models[0]; 85 const storageController2 = plugin.controllers.models[1]; 86 87 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 88 89 this.setProperties({ 90 plugin: pluginRecord.get('controllers.firstObject'), 91 }); 92 93 await render(hbs` 94 <PluginAllocationRow @pluginAllocation={{plugin}} /> 95 `); 96 97 const allocationRequest = this.server.pretender.handledRequests.find( 98 (req) => req.url.startsWith('/v1/allocation') 99 ); 100 101 assert.equal( 102 allocationRequest.url, 103 `/v1/allocation/${storageController.allocID}` 104 ); 105 106 this.set('plugin', pluginRecord.get('controllers').toArray()[1]); 107 await settled(); 108 109 const latestAllocationRequest = this.server.pretender.handledRequests 110 .filter((req) => req.url.startsWith('/v1/allocation')) 111 .reverse()[0]; 112 113 assert.equal( 114 latestAllocationRequest.url, 115 `/v1/allocation/${storageController2.allocID}` 116 ); 117 }); 118 });