github.com/aminovpavel/nomad@v0.11.8/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', controllerRequired: true }); 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', controllerRequired: true }); 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 controllerRequired: true, 70 controllersExpected: 2, 71 }); 72 const storageController = plugin.controllers.models[0]; 73 const storageController2 = plugin.controllers.models[1]; 74 75 const pluginRecord = await this.store.find('plugin', 'csi/plugin'); 76 77 this.setProperties({ 78 plugin: pluginRecord.get('controllers.firstObject'), 79 }); 80 81 await render(hbs` 82 {{plugin-allocation-row pluginAllocation=plugin}} 83 `); 84 85 await settled(); 86 87 const allocationRequest = this.server.pretender.handledRequests.find(req => 88 req.url.startsWith('/v1/allocation') 89 ); 90 91 assert.equal(allocationRequest.url, `/v1/allocation/${storageController.allocID}`); 92 93 this.set('plugin', pluginRecord.get('controllers').toArray()[1]); 94 await settled(); 95 96 const latestAllocationRequest = this.server.pretender.handledRequests 97 .filter(req => req.url.startsWith('/v1/allocation')) 98 .reverse()[0]; 99 100 assert.equal(latestAllocationRequest.url, `/v1/allocation/${storageController2.allocID}`); 101 }); 102 });