FIX: Redirect users to top when `latest` is the homepage

This commit is contained in:
David Taylor 2018-10-05 12:04:48 +01:00
parent 9bf522f227
commit 75488257c5
4 changed files with 42 additions and 2 deletions

View File

@ -13,6 +13,7 @@ export default Discourse.Route.extend(OpenComposer, {
beforeModel(transition) {
if (
(transition.intent.url === "/" ||
transition.intent.url === "/latest" ||
transition.intent.url === "/categories") &&
transition.targetName.indexOf("discovery.top") === -1 &&
Discourse.User.currentProp("should_be_redirected_to_top")

View File

@ -0,0 +1,39 @@
import { acceptance, logIn, replaceCurrentUser } from "helpers/qunit-helpers";
import DiscoveryFixtures from "fixtures/discovery_fixtures";
acceptance("Redirect to Top", {
pretend(server, helper) {
server.get("/top/all.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
}
});
function setupUser() {
logIn();
replaceCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
period: null,
reason: "Welcome back!"
}
});
}
QUnit.test("redirects categories to top", async assert => {
setupUser();
await visit("/categories");
assert.equal(currentPath(), "discovery.topAll", "it works for categories");
});
QUnit.test("redirects latest to top", async assert => {
setupUser();
await visit("/latest");
assert.equal(currentPath(), "discovery.topAll", "it works for latest");
});
QUnit.test("redirects root to top", async assert => {
setupUser();
await visit("/");
assert.equal(currentPath(), "discovery.topAll", "it works for root");
});

View File

@ -51,7 +51,7 @@ export default {
"posted",
"search"
],
periods: ["yearly", "quarterly", "monthly", "weekly", "daily"],
periods: ["all", "yearly", "quarterly", "monthly", "weekly", "daily"],
top_menu_items: [
"latest",
"unread",

View File

@ -30,7 +30,7 @@ PreloadStore.store("site", {
{ id: 21, name: "test" }
],
filters: ["latest", "unread", "new", "starred", "read", "posted"],
periods: ["yearly", "monthly", "weekly", "daily"],
periods: ["all", "yearly", "monthly", "weekly", "daily"],
top_menu_items: [
"latest",
"unread",