Skip to content

A platform for community discussion. Free, open, simple.

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

David Taylor75488257c51e
diff --git a/app/assets/javascripts/discourse/routes/discovery.js.es6 b/app/assets/javascripts/discourse/routes/discovery.js.es6
index 8b7d6c7fb5f..e7ff98a5914 100644
--- a/app/assets/javascripts/discourse/routes/discovery.js.es6
+++ b/app/assets/javascripts/discourse/routes/discovery.js.es6
@@ -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")
diff --git a/test/javascripts/acceptance/redirect-to-top-test.js.es6 b/test/javascripts/acceptance/redirect-to-top-test.js.es6
new file mode 100644
index 00000000000..2be06cacf1b
--- /dev/null
+++ b/test/javascripts/acceptance/redirect-to-top-test.js.es6
@@ -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");
+});
diff --git a/test/javascripts/fixtures/site-fixtures.js.es6 b/test/javascripts/fixtures/site-fixtures.js.es6
index f26eaba73ff..069cdd8f745 100644
--- a/test/javascripts/fixtures/site-fixtures.js.es6
+++ b/test/javascripts/fixtures/site-fixtures.js.es6
@@ -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",
diff --git a/test/javascripts/helpers/site.js.es6 b/test/javascripts/helpers/site.js.es6
index 98dacfcd357..b8b713e979d 100644
--- a/test/javascripts/helpers/site.js.es6
+++ b/test/javascripts/helpers/site.js.es6
@@ -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",