Skip to content

Commit

Permalink
feat(ember): added 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Oct 23, 2023
1 parent 6f91e35 commit 32c2a9e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ember/app/components/top-nav/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class='uk-navbar-right'>
<ul class='button-nav'>
<li>
<LinkTo @route="projects.index" @current-when="projects.index projects.detailed">Overview</LinkTo>
<LinkTo @route="projects.index" @current-when="projects.index projects.detailed not-found">Overview</LinkTo>
</li>
<li>
<LinkTo @route="projects.add">Add</LinkTo>
Expand Down
7 changes: 5 additions & 2 deletions ember/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ export default class Router extends EmberRouter {
rootURL = config.rootURL;
}

const resetNamespace = true;

// eslint-disable-next-line array-callback-return
Router.map(function () {
this.route('login');
this.route('protected', { path: '/' }, function () {
this.route('index', { resetNamespace: true, path: '/' }, function () {
this.route('projects', { resetNamespace: true, path: '/' }, function () {
this.route('index', { resetNamespace, path: '/' }, function () {
this.route('projects', { resetNamespace, path: '/' }, function () {
this.route('detailed', { path: 'projects/:project_id' }, function () {
this.route('edit');
});
this.route('add', { path: 'projects/add' });
});
});
this.route('not-found', { resetNamespace, path: '/*path' });
});
});
4 changes: 4 additions & 0 deletions ember/app/templates/not-found.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="uk-text-center" data-test-not-found>
<h1 class="uk-heading-2xlarge">404</h1>
<p>The site you requested does not exist</p>
</div>
17 changes: 17 additions & 0 deletions ember/tests/acceptance/not-found-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { visit } from '@ember/test-helpers';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { module, test } from 'qunit';

import { setupApplicationTest } from 'outdated/tests/helpers';

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

test('Displays a 404 page for undefined routes if logged in', async function (assert) {
await authenticateSession();
await visit('/an-invalid-url');
assert.dom('[data-test-not-found]').exists({ count: 1 });
});
});

0 comments on commit 32c2a9e

Please sign in to comment.