github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/tests/unit/utils/generate-exec-url-test.js (about)

     1  import generateExecUrl from 'nomad-ui/utils/generate-exec-url';
     2  import { module, test } from 'qunit';
     3  import sinon from 'sinon';
     4  
     5  const emptyOptions = { queryParams: {} };
     6  
     7  module('Unit | Utility | generate-exec-url', function(hooks) {
     8    hooks.beforeEach(function() {
     9      this.urlForSpy = sinon.spy();
    10      this.router = { urlFor: this.urlForSpy, currentRoute: { queryParams: {} } };
    11    });
    12  
    13    test('it generates an exec job URL', function(assert) {
    14      generateExecUrl(this.router, { job: { plainId: 'job-name' } });
    15  
    16      assert.ok(this.urlForSpy.calledWith('exec', 'job-name', emptyOptions));
    17    });
    18  
    19    test('it generates an exec job URL with an allocation', function(assert) {
    20      generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'allocation-short-id' } });
    21  
    22      assert.ok(
    23        this.urlForSpy.calledWith('exec', 'job-name', {
    24          queryParams: { allocation: 'allocation-short-id' },
    25        })
    26      );
    27    });
    28  
    29    test('it generates an exec task group URL', function(assert) {
    30      generateExecUrl(this.router, { job: { plainId: 'job-name' }, taskGroup: { name: 'task-group-name' } });
    31  
    32      assert.ok(
    33        this.urlForSpy.calledWith('exec.task-group', 'job-name', 'task-group-name', emptyOptions)
    34      );
    35    });
    36  
    37    test('it generates an exec task URL', function(assert) {
    38      generateExecUrl(this.router, {
    39        allocation: { shortId: 'allocation-short-id' },
    40        job: { plainId: 'job-name' },
    41        taskGroup: { name: 'task-group-name' },
    42        task: { name: 'task-name' },
    43      });
    44  
    45      assert.ok(
    46        this.urlForSpy.calledWith(
    47          'exec.task-group.task',
    48          'job-name',
    49          'task-group-name',
    50          'task-name',
    51          { queryParams: { allocation: 'allocation-short-id' } }
    52        )
    53      );
    54    });
    55  
    56    test('it includes query parameters from the current route', function(assert) {
    57      this.router.currentRoute.queryParams = {
    58        namespace: 'a-namespace',
    59        region: 'a-region',
    60      };
    61  
    62      generateExecUrl(this.router, { job: { plainId: 'job-name' }, allocation: { shortId: 'id' } });
    63  
    64      assert.ok(
    65        this.urlForSpy.calledWith('exec', 'job-name', {
    66          queryParams: { allocation: 'id', namespace: 'a-namespace', region: 'a-region' },
    67        })
    68      );
    69    });
    70  });