github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/tests/acceptance/namespaces-test.js (about)

     1  import { visit, find, findAll, click } from 'ember-native-dom-helpers';
     2  import { test } from 'qunit';
     3  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     4  
     5  moduleForAcceptance('Acceptance | namespaces (disabled)', {
     6    beforeEach() {
     7      server.create('agent');
     8      server.create('node');
     9      server.createList('job', 5);
    10    },
    11  });
    12  
    13  test('the namespace switcher is not in the gutter menu', function(assert) {
    14    visit('/jobs');
    15  
    16    andThen(() => {
    17      assert.notOk(find('.gutter .menu .namespace-switcher'), 'No namespace switcher found');
    18    });
    19  });
    20  
    21  test('the jobs request is made with no query params', function(assert) {
    22    visit('/jobs');
    23  
    24    andThen(() => {
    25      const request = server.pretender.handledRequests.findBy('url', '/v1/jobs');
    26      assert.equal(request.queryParams.namespace, undefined, 'No namespace query param');
    27    });
    28  });
    29  
    30  moduleForAcceptance('Acceptance | namespaces (enabled)', {
    31    beforeEach() {
    32      server.createList('namespace', 3);
    33      server.create('agent');
    34      server.create('node');
    35      server.createList('job', 5);
    36    },
    37  });
    38  
    39  test('the namespace switcher lists all namespaces', function(assert) {
    40    const namespaces = server.db.namespaces;
    41  
    42    visit('/jobs');
    43  
    44    andThen(() => {
    45      assert.ok(find('.gutter .menu .namespace-switcher'), 'Namespace switcher found');
    46    });
    47  
    48    andThen(() => {
    49      click('.gutter .menu .namespace-switcher .ember-power-select-trigger');
    50    });
    51  
    52    andThen(() => {
    53      // TODO this selector should be scoped to only the namespace switcher options,
    54      // but ember-wormhole makes that difficult.
    55      assert.equal(
    56        findAll('.ember-power-select-option').length,
    57        namespaces.length,
    58        'All namespaces are in the switcher'
    59      );
    60      assert.equal(
    61        find('.ember-power-select-option').textContent.trim(),
    62        'Default Namespace',
    63        'The first namespace is always the default one'
    64      );
    65  
    66      namespaces
    67        .slice(1)
    68        .sortBy('name')
    69        .forEach((namespace, index) => {
    70          assert.equal(
    71            findAll('.ember-power-select-option')[index + 1].textContent.trim(),
    72            namespace.name,
    73            `index ${index + 1}: ${namespace.name}`
    74          );
    75        });
    76    });
    77  });
    78  
    79  test('changing the namespace sets the namespace in localStorage', function(assert) {
    80    const namespace = server.db.namespaces[1];
    81  
    82    visit('/jobs');
    83  
    84    selectChoose('.namespace-switcher', namespace.name);
    85    andThen(() => {
    86      assert.equal(
    87        window.localStorage.nomadActiveNamespace,
    88        namespace.id,
    89        'Active namespace was set'
    90      );
    91    });
    92  });
    93  
    94  test('changing the namespace refreshes the jobs list when on the jobs page', function(assert) {
    95    const namespace = server.db.namespaces[1];
    96  
    97    visit('/jobs');
    98  
    99    andThen(() => {
   100      const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
   101      assert.equal(requests.length, 1, 'First request to jobs');
   102      assert.equal(
   103        requests[0].queryParams.namespace,
   104        undefined,
   105        'Namespace query param is defaulted to "default"/undefined'
   106      );
   107    });
   108  
   109    selectChoose('.namespace-switcher', namespace.name);
   110  
   111    andThen(() => {
   112      const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
   113      assert.equal(requests.length, 2, 'Second request to jobs');
   114      assert.equal(
   115        requests[1].queryParams.namespace,
   116        namespace.name,
   117        'Namespace query param on second request'
   118      );
   119    });
   120  });