github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/namespaces-test.js (about)

     1  import { test } from 'qunit';
     2  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     3  import JobsList from 'nomad-ui/tests/pages/jobs/list';
     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    JobsList.visit();
    15  
    16    andThen(() => {
    17      assert.notOk(JobsList.namespaceSwitcher.isPresent, 'No namespace switcher found');
    18    });
    19  });
    20  
    21  test('the jobs request is made with no query params', function(assert) {
    22    JobsList.visit();
    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    JobsList.visit();
    43  
    44    andThen(() => {
    45      assert.ok(JobsList.namespaceSwitcher.isPresent, 'Namespace switcher found');
    46    });
    47  
    48    andThen(() => {
    49      JobsList.namespaceSwitcher.open();
    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        JobsList.namespaceSwitcher.options.length,
    57        namespaces.length,
    58        'All namespaces are in the switcher'
    59      );
    60      assert.equal(
    61        JobsList.namespaceSwitcher.options.objectAt(0).label,
    62        'Default Namespace',
    63        'The first namespace is always the default one'
    64      );
    65  
    66      const sortedNamespaces = namespaces.slice(1).sortBy('name');
    67      JobsList.namespaceSwitcher.options.forEach((option, index) => {
    68        // Default Namespace handled separately
    69        if (index === 0) return;
    70  
    71        const namespace = sortedNamespaces[index - 1];
    72        assert.equal(option.label, namespace.name, `index ${index}: ${namespace.name}`);
    73      });
    74    });
    75  });
    76  
    77  test('changing the namespace sets the namespace in localStorage', function(assert) {
    78    const namespace = server.db.namespaces[1];
    79  
    80    JobsList.visit();
    81  
    82    selectChoose('[data-test-namespace-switcher]', namespace.name);
    83    andThen(() => {
    84      assert.equal(
    85        window.localStorage.nomadActiveNamespace,
    86        namespace.id,
    87        'Active namespace was set'
    88      );
    89    });
    90  });
    91  
    92  test('changing the namespace refreshes the jobs list when on the jobs page', function(assert) {
    93    const namespace = server.db.namespaces[1];
    94  
    95    JobsList.visit();
    96  
    97    andThen(() => {
    98      const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
    99      assert.equal(requests.length, 1, 'First request to jobs');
   100      assert.equal(
   101        requests[0].queryParams.namespace,
   102        undefined,
   103        'Namespace query param is defaulted to "default"/undefined'
   104      );
   105    });
   106  
   107    // TODO: handle this with Page Objects
   108    selectChoose('[data-test-namespace-switcher]', namespace.name);
   109  
   110    andThen(() => {
   111      const requests = server.pretender.handledRequests.filter(req => req.url.startsWith('/v1/jobs'));
   112      assert.equal(requests.length, 2, 'Second request to jobs');
   113      assert.equal(
   114        requests[1].queryParams.namespace,
   115        namespace.name,
   116        'Namespace query param on second request'
   117      );
   118    });
   119  });