github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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      const plugin = this.server.create('csi-plugin', { id: 'plugin', controllerRequired: true });
    25      const storageController = plugin.controllers.models[0];
    26  
    27      const pluginRecord = await this.store.find('plugin', 'csi/plugin');
    28  
    29      this.setProperties({
    30        plugin: pluginRecord.get('controllers.firstObject'),
    31      });
    32  
    33      await render(hbs`
    34        <PluginAllocationRow @pluginAllocation={{plugin}} />
    35      `);
    36  
    37      await settled();
    38  
    39      const allocationRequest = this.server.pretender.handledRequests.find(req =>
    40        req.url.startsWith('/v1/allocation')
    41      );
    42      assert.equal(allocationRequest.url, `/v1/allocation/${storageController.allocID}`);
    43      await componentA11yAudit(this.element, assert);
    44    });
    45  
    46    test('After the plugin allocation row fetches the plugin allocation, allocation stats are fetched', async function(assert) {
    47      const plugin = this.server.create('csi-plugin', { id: 'plugin', controllerRequired: true });
    48      const storageController = plugin.controllers.models[0];
    49  
    50      const pluginRecord = await this.store.find('plugin', 'csi/plugin');
    51  
    52      this.setProperties({
    53        plugin: pluginRecord.get('controllers.firstObject'),
    54      });
    55  
    56      await render(hbs`
    57        <PluginAllocationRow @pluginAllocation={{plugin}} />
    58      `);
    59  
    60      await settled();
    61  
    62      const [statsRequest] = this.server.pretender.handledRequests.slice(-1);
    63  
    64      assert.equal(statsRequest.url, `/v1/client/allocation/${storageController.allocID}/stats`);
    65    });
    66  
    67    test('Setting a new plugin fetches the new plugin allocation', async function(assert) {
    68      const plugin = this.server.create('csi-plugin', {
    69        id: 'plugin',
    70        isMonolith: false,
    71        controllerRequired: true,
    72        controllersExpected: 2,
    73      });
    74      const storageController = plugin.controllers.models[0];
    75      const storageController2 = plugin.controllers.models[1];
    76  
    77      const pluginRecord = await this.store.find('plugin', 'csi/plugin');
    78  
    79      this.setProperties({
    80        plugin: pluginRecord.get('controllers.firstObject'),
    81      });
    82  
    83      await render(hbs`
    84        <PluginAllocationRow @pluginAllocation={{plugin}} />
    85      `);
    86  
    87      await settled();
    88  
    89      const allocationRequest = this.server.pretender.handledRequests.find(req =>
    90        req.url.startsWith('/v1/allocation')
    91      );
    92  
    93      assert.equal(allocationRequest.url, `/v1/allocation/${storageController.allocID}`);
    94  
    95      this.set('plugin', pluginRecord.get('controllers').toArray()[1]);
    96      await settled();
    97  
    98      const latestAllocationRequest = this.server.pretender.handledRequests
    99        .filter(req => req.url.startsWith('/v1/allocation'))
   100        .reverse()[0];
   101  
   102      assert.equal(latestAllocationRequest.url, `/v1/allocation/${storageController2.allocID}`);
   103    });
   104  });