Skip to content

Commit

Permalink
Move job-page helpers and repeat stop tests on the service type
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed Apr 19, 2018
1 parent 91c9e09 commit 1d19d82
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 53 deletions.
51 changes: 51 additions & 0 deletions ui/tests/integration/job-page/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { click, find } from 'ember-native-dom-helpers';
import wait from 'ember-test-helpers/wait';

export function jobURL(job, path = '') {
const id = job.get('plainId');
const namespace = job.get('namespace.name') || 'default';
let expectedURL = `/v1/job/${id}${path}`;
if (namespace !== 'default') {
expectedURL += `?namespace=${namespace}`;
}
return expectedURL;
}

export function stopJob() {
click('[data-test-stop] [data-test-idle-button]');
return wait().then(() => {
click('[data-test-stop] [data-test-confirm-button]');
return wait();
});
}

export function expectStopError(assert) {
return () => {
assert.equal(
find('[data-test-job-error-title]').textContent,
'Could Not Stop Job',
'Appropriate error is shown'
);
assert.ok(
find('[data-test-job-error-body]').textContent.includes('ACL'),
'The error message mentions ACLs'
);

click('[data-test-job-error-close]');
assert.notOk(find('[data-test-job-error-title]'), 'Error message is dismissable');
return wait();
};
}

export function expectDeleteRequest(assert, server, job) {
const expectedURL = jobURL(job);

assert.ok(
server.pretender.handledRequests
.filterBy('method', 'DELETE')
.find(req => req.url === expectedURL),
'DELETE URL was made correctly'
);

return wait();
}
58 changes: 5 additions & 53 deletions ui/tests/integration/job-page/periodic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { click, find, findAll } from 'ember-native-dom-helpers';
import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { jobURL, stopJob, expectStopError, expectDeleteRequest } from './helpers';

moduleForComponent('job-page/periodic', 'Integration | Component | job-page/periodic', {
integration: true,
Expand Down Expand Up @@ -68,7 +69,7 @@ test('Clicking Force Launch launches a new periodic child job', function(assert)
const expectedURL = jobURL(job, '/periodic/force');

assert.ok(
server.pretender.handledRequests
this.server.pretender.handledRequests
.filterBy('method', 'POST')
.find(req => req.url === expectedURL),
'POST URL was correct'
Expand All @@ -81,7 +82,7 @@ test('Clicking Force Launch launches a new periodic child job', function(assert)
});

test('Clicking force launch without proper permissions shows an error message', function(assert) {
server.pretender.post('/v1/job/:id/periodic/force', () => [403, {}, null]);
this.server.pretender.post('/v1/job/:id/periodic/force', () => [403, {}, null]);

this.server.create('job', 'periodic', {
id: 'parent',
Expand Down Expand Up @@ -142,11 +143,11 @@ test('Stopping a job sends a delete request for the job', function(assert) {
return wait();
})
.then(stopJob)
.then(() => expectDeleteRequest(assert, job));
.then(() => expectDeleteRequest(assert, this.server, job));
});

test('Stopping a job without proper permissions shows an error message', function(assert) {
server.pretender.delete('/v1/job/:id', () => [403, {}, null]);
this.server.pretender.delete('/v1/job/:id', () => [403, {}, null]);

const mirageJob = this.server.create('job', 'periodic', {
childrenCount: 0,
Expand All @@ -168,52 +169,3 @@ test('Stopping a job without proper permissions shows an error message', functio
.then(stopJob)
.then(expectStopError(assert));
});

function expectDeleteRequest(assert, job) {
const expectedURL = jobURL(job);

assert.ok(
server.pretender.handledRequests
.filterBy('method', 'DELETE')
.find(req => req.url === expectedURL),
'DELETE URL was made correctly'
);

return wait();
}

function jobURL(job, path = '') {
const id = job.get('plainId');
const namespace = job.get('namespace.name') || 'default';
let expectedURL = `/v1/job/${id}${path}`;
if (namespace !== 'default') {
expectedURL += `?namespace=${namespace}`;
}
return expectedURL;
}

function stopJob() {
click('[data-test-stop] [data-test-idle-button]');
return wait().then(() => {
click('[data-test-stop] [data-test-confirm-button]');
return wait();
});
}

function expectStopError(assert) {
return () => {
assert.equal(
find('[data-test-job-error-title]').textContent,
'Could Not Stop Job',
'Appropriate error is shown'
);
assert.ok(
find('[data-test-job-error-body]').textContent.includes('ACL'),
'The error message mentions ACLs'
);

click('[data-test-job-error-close]');
assert.notOk(find('[data-test-job-error-title]'), 'Error message is dismissable');
return wait();
};
}
82 changes: 82 additions & 0 deletions ui/tests/integration/job-page/service-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { getOwner } from '@ember/application';
import { test, moduleForComponent } from 'ember-qunit';
import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { stopJob, expectStopError, expectDeleteRequest } from './helpers';

moduleForComponent('job-page/service', 'Integration | Component | job-page/service', {
integration: true,
beforeEach() {
window.localStorage.clear();
this.store = getOwner(this).lookup('service:store');
this.server = startMirage();
this.server.create('namespace');
},
afterEach() {
this.server.shutdown();
window.localStorage.clear();
},
});

const commonTemplate = hbs`
{{job-page/service
job=job
sortProperty=sortProperty
sortDescending=sortDescending
currentPage=currentPage
gotoJob=gotoJob}}
`;

const commonProperties = job => ({
job,
sortProperty: 'name',
sortDescending: true,
currentPage: 1,
gotoJob() {},
});

const makeMirageJob = server =>
server.create('job', {
type: 'service',
createAllocations: false,
status: 'running',
});

test('Stopping a job sends a delete request for the job', function(assert) {
let job;

const mirageJob = makeMirageJob(this.server);
this.store.findAll('job');

return wait()
.then(() => {
job = this.store.peekAll('job').findBy('plainId', mirageJob.id);

this.setProperties(commonProperties(job));
this.render(commonTemplate);

return wait();
})
.then(stopJob)
.then(() => expectDeleteRequest(assert, this.server, job));
});

test('Stopping a job without proper permissions shows an error message', function(assert) {
this.server.pretender.delete('/v1/job/:id', () => [403, {}, null]);

const mirageJob = makeMirageJob(this.server);
this.store.findAll('job');

return wait()
.then(() => {
const job = this.store.peekAll('job').findBy('plainId', mirageJob.id);

this.setProperties(commonProperties(job));
this.render(commonTemplate);

return wait();
})
.then(stopJob)
.then(expectStopError(assert));
});

0 comments on commit 1d19d82

Please sign in to comment.