Handle the job 404 error case in versions

This commit is contained in:
Michael Lange
2018-11-05 15:42:04 -08:00
parent 1226a079f9
commit cb5bd66dd6
6 changed files with 30 additions and 21 deletions

View File

@@ -25,13 +25,9 @@ export default Route.extend(WithWatchers, {
model({ name }) {
const job = this.modelFor('jobs.job');
// If there is no job, then there is no task group, so handle this as a 404
if (!job) {
const err = new EmberError(`Job for task group ${name} not found`);
err.code = '404';
this.controllerFor('application').set('error', err);
return;
}
// If there is no job, then there is no task group.
// Let the job route handle the 404.
if (!job) return;
// If the job is a partial (from the list request) it won't have task
// groups. Reload the job to ensure task groups are present.

View File

@@ -6,11 +6,13 @@ import WithWatchers from 'nomad-ui/mixins/with-watchers';
export default Route.extend(WithWatchers, {
model() {
const job = this.modelFor('jobs.job');
return job.get('versions').then(() => job);
return job && job.get('versions').then(() => job);
},
startWatchers(controller, model) {
controller.set('watcher', this.get('watchVersions').perform(model));
if (model) {
controller.set('watcher', this.get('watchVersions').perform(model));
}
},
watchVersions: watchRelationship('versions'),

View File

@@ -28,3 +28,18 @@ test('each version mentions the version number, the stability, and the submitted
assert.equal(versionRow.stability, version.stable.toString(), 'Stability');
assert.equal(versionRow.submitTime, formattedSubmitTime, 'Submit time');
});
test('when the job for the definition is not found, an error message is shown, but the URL persists', function(assert) {
Versions.visit({ id: 'not-a-real-job' });
andThen(() => {
assert.equal(
server.pretender.handledRequests.findBy('status', 404).url,
'/v1/job/not-a-real-job',
'A request to the nonexistent job is made'
);
assert.equal(currentURL(), '/jobs/not-a-real-job/versions', 'The URL persists');
assert.ok(Versions.error.isPresent, 'Error message is shown');
assert.equal(Versions.error.title, 'Not Found', 'Error message is for 404');
});
});

View File

@@ -1,6 +1,7 @@
import { create, isPresent, visitable, clickable, text } from 'ember-cli-page-object';
import jobEditor from 'nomad-ui/tests/pages/components/job-editor';
import error from 'nomad-ui/tests/pages/components/error';
export default create({
visit: visitable('/jobs/:id/definition'),
@@ -10,10 +11,5 @@ export default create({
edit: clickable('[data-test-edit-job]'),
error: {
isPresent: isPresent('[data-test-error]'),
title: text('[data-test-error-title]'),
message: text('[data-test-error-message]'),
seekHelp: clickable('[data-test-error-message] a'),
},
error: error(),
});

View File

@@ -10,6 +10,7 @@ import {
} from 'ember-cli-page-object';
import allocations from 'nomad-ui/tests/pages/components/allocations';
import error from 'nomad-ui/tests/pages/components/error';
export default create({
pageSize: 10,
@@ -37,12 +38,7 @@ export default create({
isEmpty: isPresent('[data-test-empty-allocations-list]'),
error: {
isPresent: isPresent('[data-test-error]'),
title: text('[data-test-error-title]'),
message: text('[data-test-error-message]'),
seekHelp: clickable('[data-test-error-message] a'),
},
error: error(),
emptyState: {
headline: text('[data-test-empty-allocations-list-headline]'),

View File

@@ -1,5 +1,7 @@
import { create, collection, text, visitable } from 'ember-cli-page-object';
import error from 'nomad-ui/tests/pages/components/error';
export default create({
visit: visitable('/jobs/:id/versions'),
@@ -8,4 +10,6 @@ export default create({
stability: text('[data-test-version-stability]'),
submitTime: text('[data-test-version-submit-time]'),
}),
error: error(),
});