github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/acceptance/plugins-list-test.js (about)

     1  import { currentURL } from '@ember/test-helpers';
     2  import { module, test } from 'qunit';
     3  import { setupApplicationTest } from 'ember-qunit';
     4  import { setupMirage } from 'ember-cli-mirage/test-support';
     5  import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
     6  import pageSizeSelect from './behaviors/page-size-select';
     7  import PluginsList from 'nomad-ui/tests/pages/storage/plugins/list';
     8  
     9  module('Acceptance | plugins list', function(hooks) {
    10    setupApplicationTest(hooks);
    11    setupMirage(hooks);
    12  
    13    hooks.beforeEach(function() {
    14      server.create('node');
    15      window.localStorage.clear();
    16    });
    17  
    18    test('it passes an accessibility audit', async function(assert) {
    19      await PluginsList.visit();
    20      await a11yAudit(assert);
    21    });
    22  
    23    test('visiting /csi/plugins', async function(assert) {
    24      await PluginsList.visit();
    25  
    26      assert.equal(currentURL(), '/csi/plugins');
    27      assert.equal(document.title, 'CSI Plugins - Nomad');
    28    });
    29  
    30    test('/csi/plugins should list the first page of plugins sorted by id', async function(assert) {
    31      const pluginCount = PluginsList.pageSize + 1;
    32      server.createList('csi-plugin', pluginCount, { shallow: true });
    33  
    34      await PluginsList.visit();
    35  
    36      const sortedPlugins = server.db.csiPlugins.sortBy('id');
    37      assert.equal(PluginsList.plugins.length, PluginsList.pageSize);
    38      PluginsList.plugins.forEach((plugin, index) => {
    39        assert.equal(plugin.id, sortedPlugins[index].id, 'Plugins are ordered');
    40      });
    41    });
    42  
    43    test('each plugin row should contain information about the plugin', async function(assert) {
    44      const plugin = server.create('csi-plugin', { shallow: true, controllerRequired: true });
    45  
    46      await PluginsList.visit();
    47  
    48      const pluginRow = PluginsList.plugins.objectAt(0);
    49      const controllerHealthStr = plugin.controllersHealthy > 0 ? 'Healthy' : 'Unhealthy';
    50      const nodeHealthStr = plugin.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy';
    51  
    52      assert.equal(pluginRow.id, plugin.id);
    53      assert.equal(
    54        pluginRow.controllerHealth,
    55        `${controllerHealthStr} (${plugin.controllersHealthy}/${plugin.controllersExpected})`
    56      );
    57      assert.equal(
    58        pluginRow.nodeHealth,
    59        `${nodeHealthStr} (${plugin.nodesHealthy}/${plugin.nodesExpected})`
    60      );
    61      assert.equal(pluginRow.provider, plugin.provider);
    62    });
    63  
    64    test('node only plugins explain that there is no controller health for this plugin type', async function(assert) {
    65      const plugin = server.create('csi-plugin', { shallow: true, controllerRequired: false });
    66  
    67      await PluginsList.visit();
    68  
    69      const pluginRow = PluginsList.plugins.objectAt(0);
    70      const nodeHealthStr = plugin.nodesHealthy > 0 ? 'Healthy' : 'Unhealthy';
    71  
    72      assert.equal(pluginRow.id, plugin.id);
    73      assert.equal(pluginRow.controllerHealth, 'Node Only');
    74      assert.equal(
    75        pluginRow.nodeHealth,
    76        `${nodeHealthStr} (${plugin.nodesHealthy}/${plugin.nodesExpected})`
    77      );
    78      assert.equal(pluginRow.provider, plugin.provider);
    79    });
    80  
    81    test('each plugin row should link to the corresponding plugin', async function(assert) {
    82      const plugin = server.create('csi-plugin', { shallow: true });
    83  
    84      await PluginsList.visit();
    85  
    86      await PluginsList.plugins.objectAt(0).clickName();
    87      assert.equal(currentURL(), `/csi/plugins/${plugin.id}`);
    88  
    89      await PluginsList.visit();
    90      assert.equal(currentURL(), '/csi/plugins');
    91  
    92      await PluginsList.plugins.objectAt(0).clickRow();
    93      assert.equal(currentURL(), `/csi/plugins/${plugin.id}`);
    94    });
    95  
    96    test('when there are no plugins, there is an empty message', async function(assert) {
    97      await PluginsList.visit();
    98  
    99      assert.ok(PluginsList.isEmpty);
   100      assert.equal(PluginsList.emptyState.headline, 'No Plugins');
   101    });
   102  
   103    test('when there are plugins, but no matches for a search, there is an empty message', async function(assert) {
   104      server.create('csi-plugin', { id: 'cat 1', shallow: true });
   105      server.create('csi-plugin', { id: 'cat 2', shallow: true });
   106  
   107      await PluginsList.visit();
   108  
   109      await PluginsList.search('dog');
   110      assert.ok(PluginsList.isEmpty);
   111      assert.equal(PluginsList.emptyState.headline, 'No Matches');
   112    });
   113  
   114    test('search resets the current page', async function(assert) {
   115      server.createList('csi-plugin', PluginsList.pageSize + 1, { shallow: true });
   116  
   117      await PluginsList.visit();
   118      await PluginsList.nextPage();
   119  
   120      assert.equal(currentURL(), '/csi/plugins?page=2');
   121  
   122      await PluginsList.search('foobar');
   123  
   124      assert.equal(currentURL(), '/csi/plugins?search=foobar');
   125    });
   126  
   127    test('when accessing plugins is forbidden, a message is shown with a link to the tokens page', async function(assert) {
   128      server.pretender.get('/v1/plugins', () => [403, {}, null]);
   129  
   130      await PluginsList.visit();
   131      assert.equal(PluginsList.error.title, 'Not Authorized');
   132  
   133      await PluginsList.error.seekHelp();
   134      assert.equal(currentURL(), '/settings/tokens');
   135    });
   136  
   137    pageSizeSelect({
   138      resourceName: 'plugin',
   139      pageObject: PluginsList,
   140      pageObjectList: PluginsList.plugins,
   141      async setup() {
   142        server.createList('csi-plugin', PluginsList.pageSize, { shallow: true });
   143        await PluginsList.visit();
   144      },
   145    });
   146  });