FIX: replace fullPath while rewriting the /my/ URLs.

And added the tests. Follow-up to cdca5a2ee4
This commit is contained in:
Vinoth Kannan 2020-08-05 23:22:15 +05:30
parent 0c8365a1a2
commit aa017f276f
2 changed files with 16 additions and 1 deletions

View File

@ -247,7 +247,7 @@ const DiscourseURL = EmberObject.extend({
if (fullPath.indexOf(myPath) === 0) {
const currentUser = User.current();
if (currentUser) {
path = path.replace(
path = fullPath.replace(
myPath,
userPath(currentUser.get("username_lower"))
);

View File

@ -1,5 +1,7 @@
import DiscourseURL, { userPath } from "discourse/lib/url";
import { setPrefix } from "discourse-common/lib/get-url";
import { logIn } from "helpers/qunit-helpers";
import User from "discourse/models/user";
QUnit.module("lib:url");
@ -66,3 +68,16 @@ QUnit.test("userPath with prefix", assert => {
assert.equal(userPath("eviltrout"), "/forum/u/eviltrout");
assert.equal(userPath("hp.json"), "/forum/u/hp.json");
});
QUnit.test("routeTo with prefix", async assert => {
setPrefix("/forum");
logIn();
const user = User.current();
sandbox.stub(DiscourseURL, "handleURL");
DiscourseURL.routeTo("/my/messages");
assert.ok(
DiscourseURL.handleURL.calledWith(`/u/${user.username}/messages`),
"it should navigate to the messages page"
);
});