github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/integration/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 8 module('Integration | Component | plugin allocation row', function(hooks) { 9 setupRenderingTest(hooks); 10 11 hooks.beforeEach(function() { 12 fragmentSerializerInitializer(this.owner); 13 this.store = this.owner.lookup('service:store'); 14 this.server = startMirage(); 15 this.server.create('node'); 16 }); 17 18 hooks.afterEach(function() { 19 this.server.shutdown(); 20 }); 21 22 test('Plugin allocation row immediately fetches the plugin allocation', async function(assert) { 23 const plugin = this.server.create('csi-plugin', { id: 'plugin' }); 24 const storageController = plugin.controllers.models[0]; 25 26 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 27 28 this.setProperties({ 29 plugin: pluginRecord.get('controllers.firstObject'), 30 }); 31 32 await render(hbs` 33 {{plugin-allocation-row pluginAllocation=plugin}} 34 `); 35 36 await settled(); 37 38 const allocationRequest = this.server.pretender.handledRequests.find(req => 39 req.url.startsWith('/v1/allocation') 40 ); 41 assert.equal(allocationRequest.url, `/v1/allocation/${storageController.allocID}`); 42 }); 43 44 test('After the plugin allocation row fetches the plugin allocation, allocation stats are fetched', async function(assert) { 45 const plugin = this.server.create('csi-plugin', { id: 'plugin' }); 46 const storageController = plugin.controllers.models[0]; 47 48 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 49 50 this.setProperties({ 51 plugin: pluginRecord.get('controllers.firstObject'), 52 }); 53 54 await render(hbs` 55 {{plugin-allocation-row pluginAllocation=plugin}} 56 `); 57 58 await settled(); 59 60 const [statsRequest] = this.server.pretender.handledRequests.slice(-1); 61 62 assert.equal(statsRequest.url, `/v1/client/allocation/${storageController.allocID}/stats`); 63 }); 64 65 test('Setting a new plugin fetches the new plugin allocation', async function(assert) { 66 const plugin = this.server.create('csi-plugin', { 67 id: 'plugin', 68 isMonolith: false, 69 controllersExpected: 2, 70 }); 71 const storageController = plugin.controllers.models[0]; 72 const storageController2 = plugin.controllers.models[1]; 73 74 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 75 76 this.setProperties({ 77 plugin: pluginRecord.get('controllers.firstObject'), 78 }); 79 80 await render(hbs` 81 {{plugin-allocation-row pluginAllocation=plugin}} 82 `); 83 84 await settled(); 85 86 const allocationRequest = this.server.pretender.handledRequests.find(req => 87 req.url.startsWith('/v1/allocation') 88 ); 89 90 assert.equal(allocationRequest.url, `/v1/allocation/${storageController.allocID}`); 91 92 this.set('plugin', pluginRecord.get('controllers').toArray()[1]); 93 await settled(); 94 95 const latestAllocationRequest = this.server.pretender.handledRequests 96 .filter(req => req.url.startsWith('/v1/allocation')) 97 .reverse()[0]; 98 99 assert.equal(latestAllocationRequest.url, `/v1/allocation/${storageController2.allocID}`); 100 }); 101 });