Test coverage for the Start Job behavior

This commit is contained in:
Michael Lange 2018-08-24 13:18:10 -07:00
parent a4d951a757
commit 18d5efce1e
3 changed files with 117 additions and 6 deletions

View file

@ -19,11 +19,31 @@ export function stopJob() {
}); });
} }
export function expectStopError(assert) { export function startJob() {
click('[data-test-start] [data-test-idle-button]');
return wait().then(() => {
click('[data-test-start] [data-test-confirm-button]');
return wait();
});
}
export function expectStartRequest(assert, server, job) {
const expectedURL = jobURL(job);
const request = server.pretender.handledRequests
.filterBy('method', 'POST')
.find(req => req.url === expectedURL);
const requestPayload = JSON.parse(request.requestBody).Job;
assert.ok(request, 'POST URL was made correctly');
assert.ok(requestPayload.Stop == null, 'The Stop signal is not sent in the POST request');
}
export function expectError(assert, title) {
return () => { return () => {
assert.equal( assert.equal(
find('[data-test-job-error-title]').textContent, find('[data-test-job-error-title]').textContent,
'Could Not Stop Job', title,
'Appropriate error is shown' 'Appropriate error is shown'
); );
assert.ok( assert.ok(

View file

@ -4,7 +4,14 @@ import { click, find, findAll } from 'ember-native-dom-helpers';
import wait from 'ember-test-helpers/wait'; import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile'; import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { jobURL, stopJob, expectStopError, expectDeleteRequest } from './helpers'; import {
jobURL,
stopJob,
startJob,
expectError,
expectDeleteRequest,
expectStartRequest,
} from './helpers';
moduleForComponent('job-page/periodic', 'Integration | Component | job-page/periodic', { moduleForComponent('job-page/periodic', 'Integration | Component | job-page/periodic', {
integration: true, integration: true,
@ -167,5 +174,51 @@ test('Stopping a job without proper permissions shows an error message', functio
return wait(); return wait();
}) })
.then(stopJob) .then(stopJob)
.then(expectStopError(assert)); .then(expectError(assert, 'Could Not Stop Job'));
});
test('Starting a job sends a post request for the job using the current definition', function(assert) {
let job;
const mirageJob = this.server.create('job', 'periodic', {
childrenCount: 0,
createAllocations: false,
status: 'dead',
});
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(startJob)
.then(() => expectStartRequest(assert, this.server, job));
});
test('Starting a job without proper permissions shows an error message', function(assert) {
this.server.pretender.post('/v1/job/:id', () => [403, {}, null]);
const mirageJob = this.server.create('job', 'periodic', {
childrenCount: 0,
createAllocations: false,
status: 'dead',
});
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(startJob)
.then(expectError(assert, 'Could Not Start Job'));
}); });

View file

@ -4,7 +4,7 @@ import { test, moduleForComponent } from 'ember-qunit';
import wait from 'ember-test-helpers/wait'; import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile'; import hbs from 'htmlbars-inline-precompile';
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage';
import { stopJob, expectStopError, expectDeleteRequest } from './helpers'; import { startJob, stopJob, expectError, expectDeleteRequest, expectStartRequest } from './helpers';
import Job from 'nomad-ui/tests/pages/jobs/detail'; import Job from 'nomad-ui/tests/pages/jobs/detail';
moduleForComponent('job-page/service', 'Integration | Component | job-page/service', { moduleForComponent('job-page/service', 'Integration | Component | job-page/service', {
@ -88,7 +88,45 @@ test('Stopping a job without proper permissions shows an error message', functio
return wait(); return wait();
}) })
.then(stopJob) .then(stopJob)
.then(expectStopError(assert)); .then(expectError(assert, 'Could Not Stop Job'));
});
test('Starting a job sends a post request for the job using the current definition', function(assert) {
let job;
const mirageJob = makeMirageJob(this.server, { status: 'dead' });
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(startJob)
.then(() => expectStartRequest(assert, this.server, job));
});
test('Starting a job without proper permissions shows an error message', function(assert) {
this.server.pretender.post('/v1/job/:id', () => [403, {}, null]);
const mirageJob = makeMirageJob(this.server, { status: 'dead' });
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(startJob)
.then(expectError(assert, 'Could Not Start Job'));
}); });
test('Recent allocations shows allocations in the job context', function(assert) { test('Recent allocations shows allocations in the job context', function(assert) {