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

Improve error redirect on Document route #427

Merged
merged 2 commits into from
Nov 15, 2023
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
8 changes: 6 additions & 2 deletions web/app/routes/authenticated/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export default class AuthenticatedDocumentRoute extends Route {
const typedError = err as Error;
this.showErrorMessage(typedError);

// Transition to dashboard
this.router.transitionTo("authenticated.dashboard");
if (transition.from && transition.from.name !== transition.to.name) {
this.router.transitionTo(transition.from.name);
} else {
this.router.transitionTo("authenticated.dashboard");
}

throw new Error(typedError.message);
}
}
Expand Down
17 changes: 17 additions & 0 deletions web/tests/acceptance/authenticated/document-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
click,
currentURL,
fillIn,
find,
findAll,
triggerEvent,
triggerKeyEvent,
visit,
waitFor,
waitUntil,
} from "@ember/test-helpers";
import { setupApplicationTest } from "ember-qunit";
import { module, test } from "qunit";
Expand All @@ -21,6 +23,8 @@ import {
import { capitalize } from "@ember/string";
import window from "ember-window-mock";
import { TEST_SHORT_LINK_BASE_URL } from "hermes/utils/hermes-urls";
import RouterService from "@ember/routing/router-service";
import { wait } from "ember-animated/.";

const ADD_RELATED_RESOURCE_BUTTON_SELECTOR =
"[data-test-section-header-button-for='Related resources']";
Expand Down Expand Up @@ -94,6 +98,19 @@ module("Acceptance | authenticated/document", function (hooks) {
await authenticateSession({});
});

test("it redirects to the dashboard by default if the document doesn't exist", async function (this: AuthenticatedDocumentRouteTestContext, assert) {
await visit("/document/1");
assert.equal(currentURL(), "/dashboard");
});

test("it redirects to the previous page if the document doesn't exist", async function (this: AuthenticatedDocumentRouteTestContext, assert) {
await visit("/documents");
assert.equal(currentURL(), "/documents");

await visit("/document/1");
assert.equal(currentURL(), "/documents");
});

test("the page title is correct (published doc)", async function (this: AuthenticatedDocumentRouteTestContext, assert) {
this.server.create("document", { objectID: 1, title: "Test Document" });
await visit("/document/1");
Expand Down