Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add not-found route #787

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Router.map(function () {
this.route('payment-sent');
});

this.route('not-found', { path: '/*path' });
ijlee2 marked this conversation as resolved.
Show resolved Hide resolved

this.route('releases', function () {
this.route('beta');
this.route('canary');
Expand Down
14 changes: 14 additions & 0 deletions app/routes/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class NotFoundRoute extends Route {
@service fastboot;

beforeModel() {
if (!this.fastboot.isFastBoot) {
return;
}

this.fastboot.response.statusCode = 404;
}
}
6 changes: 6 additions & 0 deletions app/templates/not-found.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{page-title "Page Not Found"}}

<div class="container">
<h1>Page Not Found</h1>
<p>We couldn't find what you were looking for.</p>
</div>
32 changes: 32 additions & 0 deletions tests/acceptance/not-found-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { visit } from '@ember/test-helpers';
import percySnapshot from '@percy/ember';
import { a11yAudit } from 'ember-a11y-testing/test-support';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { setupApplicationTest } from 'ember-qunit';
import loadDefaultScenario from 'ember-website/mirage/scenarios/default';
import { setupPageTitleTest } from 'ember-website/tests/helpers/page-title';
import { module, test } from 'qunit';

module('Acceptance | not found', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
setupPageTitleTest(hooks);

hooks.beforeEach(function () {
loadDefaultScenario(this.server);
});

test('Percy snapshot', async function (assert) {
await visit('/foo-bar-baz');
await percySnapshot(assert);

assert.ok(true);
});

test('Accessibility audit', async function (assert) {
await visit('/foo-bar-baz');
await a11yAudit();

assert.hasPageTitle('Page Not Found - Ember.js');
});
});
ijlee2 marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions tests/unit/routes/not-found-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Unit | Route | not-found', function (hooks) {
setupTest(hooks);

test('it exists', function (assert) {
const route = this.owner.lookup('route:not-found');

assert.ok(route);
});
});