github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/tests/acceptance/jobs-list-test.js (about)

     1  import { currentURL } from 'ember-native-dom-helpers';
     2  import { test } from 'qunit';
     3  import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
     4  import JobsList from 'nomad-ui/tests/pages/jobs/list';
     5  
     6  moduleForAcceptance('Acceptance | jobs list', {
     7    beforeEach() {
     8      // Required for placing allocations (a result of creating jobs)
     9      server.create('node');
    10    },
    11  });
    12  
    13  test('visiting /jobs', function(assert) {
    14    JobsList.visit();
    15  
    16    andThen(() => {
    17      assert.equal(currentURL(), '/jobs');
    18    });
    19  });
    20  
    21  test('/jobs should list the first page of jobs sorted by modify index', function(assert) {
    22    const jobsCount = JobsList.pageSize + 1;
    23    server.createList('job', jobsCount, { createAllocations: false });
    24  
    25    JobsList.visit();
    26  
    27    andThen(() => {
    28      const sortedJobs = server.db.jobs.sortBy('modifyIndex').reverse();
    29      assert.equal(JobsList.jobs.length, JobsList.pageSize);
    30      JobsList.jobs.forEach((job, index) => {
    31        assert.equal(job.name, sortedJobs[index].name, 'Jobs are ordered');
    32      });
    33    });
    34  });
    35  
    36  test('each job row should contain information about the job', function(assert) {
    37    server.createList('job', 2);
    38    const job = server.db.jobs.sortBy('modifyIndex').reverse()[0];
    39    const taskGroups = server.db.taskGroups.where({ jobId: job.id });
    40  
    41    JobsList.visit();
    42  
    43    andThen(() => {
    44      const jobRow = JobsList.jobs.objectAt(0);
    45  
    46      assert.equal(jobRow.name, job.name, 'Name');
    47      assert.equal(jobRow.link, `/ui/jobs/${job.id}`, 'Detail Link');
    48      assert.equal(jobRow.status, job.status, 'Status');
    49      assert.equal(jobRow.type, typeForJob(job), 'Type');
    50      assert.equal(jobRow.priority, job.priority, 'Priority');
    51      andThen(() => {
    52        assert.equal(jobRow.taskGroups, taskGroups.length, '# Groups');
    53      });
    54    });
    55  });
    56  
    57  test('each job row should link to the corresponding job', function(assert) {
    58    server.create('job');
    59    const job = server.db.jobs[0];
    60  
    61    JobsList.visit();
    62  
    63    andThen(() => {
    64      JobsList.jobs.objectAt(0).clickName();
    65    });
    66  
    67    andThen(() => {
    68      assert.equal(currentURL(), `/jobs/${job.id}`);
    69    });
    70  });
    71  
    72  test('the new job button transitions to the new job page', function(assert) {
    73    JobsList.visit();
    74  
    75    andThen(() => {
    76      JobsList.runJob();
    77    });
    78  
    79    andThen(() => {
    80      assert.equal(currentURL(), '/jobs/run');
    81    });
    82  });
    83  
    84  test('when there are no jobs, there is an empty message', function(assert) {
    85    JobsList.visit();
    86  
    87    andThen(() => {
    88      assert.ok(JobsList.isEmpty, 'There is an empty message');
    89      assert.equal(JobsList.emptyState.headline, 'No Jobs', 'The message is appropriate');
    90    });
    91  });
    92  
    93  test('when there are jobs, but no matches for a search result, there is an empty message', function(assert) {
    94    server.create('job', { name: 'cat 1' });
    95    server.create('job', { name: 'cat 2' });
    96  
    97    JobsList.visit();
    98  
    99    andThen(() => {
   100      JobsList.search('dog');
   101    });
   102  
   103    andThen(() => {
   104      assert.ok(JobsList.isEmpty, 'The empty message is shown');
   105      assert.equal(JobsList.emptyState.headline, 'No Matches', 'The message is appropriate');
   106    });
   107  });
   108  
   109  test('when the namespace query param is set, only matching jobs are shown and the namespace value is forwarded to app state', function(assert) {
   110    server.createList('namespace', 2);
   111    const job1 = server.create('job', { namespaceId: server.db.namespaces[0].id });
   112    const job2 = server.create('job', { namespaceId: server.db.namespaces[1].id });
   113  
   114    JobsList.visit();
   115  
   116    andThen(() => {
   117      assert.equal(JobsList.jobs.length, 1, 'One job in the default namespace');
   118      assert.equal(JobsList.jobs.objectAt(0).name, job1.name, 'The correct job is shown');
   119    });
   120  
   121    const secondNamespace = server.db.namespaces[1];
   122    JobsList.visit({ namespace: secondNamespace.id });
   123  
   124    andThen(() => {
   125      assert.equal(JobsList.jobs.length, 1, `One job in the ${secondNamespace.name} namespace`);
   126      assert.equal(JobsList.jobs.objectAt(0).name, job2.name, 'The correct job is shown');
   127    });
   128  });
   129  
   130  test('when accessing jobs is forbidden, show a message with a link to the tokens page', function(assert) {
   131    server.pretender.get('/v1/jobs', () => [403, {}, null]);
   132  
   133    JobsList.visit();
   134  
   135    andThen(() => {
   136      assert.equal(JobsList.error.title, 'Not Authorized');
   137    });
   138  
   139    andThen(() => {
   140      JobsList.error.seekHelp();
   141    });
   142  
   143    andThen(() => {
   144      assert.equal(currentURL(), '/settings/tokens');
   145    });
   146  });
   147  
   148  function typeForJob(job) {
   149    return job.periodic ? 'periodic' : job.parameterized ? 'parameterized' : job.type;
   150  }