mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 14:18:55 +08:00
FIX: Redirect users to top when latest
is the homepage
This commit is contained in:
parent
9bf522f227
commit
75488257c5
@ -13,6 +13,7 @@ export default Discourse.Route.extend(OpenComposer, {
|
|||||||
beforeModel(transition) {
|
beforeModel(transition) {
|
||||||
if (
|
if (
|
||||||
(transition.intent.url === "/" ||
|
(transition.intent.url === "/" ||
|
||||||
|
transition.intent.url === "/latest" ||
|
||||||
transition.intent.url === "/categories") &&
|
transition.intent.url === "/categories") &&
|
||||||
transition.targetName.indexOf("discovery.top") === -1 &&
|
transition.targetName.indexOf("discovery.top") === -1 &&
|
||||||
Discourse.User.currentProp("should_be_redirected_to_top")
|
Discourse.User.currentProp("should_be_redirected_to_top")
|
||||||
|
39
test/javascripts/acceptance/redirect-to-top-test.js.es6
Normal file
39
test/javascripts/acceptance/redirect-to-top-test.js.es6
Normal 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");
|
||||||
|
});
|
@ -51,7 +51,7 @@ export default {
|
|||||||
"posted",
|
"posted",
|
||||||
"search"
|
"search"
|
||||||
],
|
],
|
||||||
periods: ["yearly", "quarterly", "monthly", "weekly", "daily"],
|
periods: ["all", "yearly", "quarterly", "monthly", "weekly", "daily"],
|
||||||
top_menu_items: [
|
top_menu_items: [
|
||||||
"latest",
|
"latest",
|
||||||
"unread",
|
"unread",
|
||||||
|
@ -30,7 +30,7 @@ PreloadStore.store("site", {
|
|||||||
{ id: 21, name: "test" }
|
{ id: 21, name: "test" }
|
||||||
],
|
],
|
||||||
filters: ["latest", "unread", "new", "starred", "read", "posted"],
|
filters: ["latest", "unread", "new", "starred", "read", "posted"],
|
||||||
periods: ["yearly", "monthly", "weekly", "daily"],
|
periods: ["all", "yearly", "monthly", "weekly", "daily"],
|
||||||
top_menu_items: [
|
top_menu_items: [
|
||||||
"latest",
|
"latest",
|
||||||
"unread",
|
"unread",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user