discourse/test/javascripts/acceptance/redirect-to-top-test.js.es6
Robin Ward a8793d0d9a REFACTOR: Test Memory Usage Fixes (#7769)
* Calling `Discourse.reset()` creates a new container
We should run our de-initializers only after acceptance tests,
since initializers are not run outside of acceptance tests anyway,
and the container at this point can be passed properly to the
`teardown()` method.

* Remove `Discourse.reset` from tests
This would cause a new container to be created which leaks many objects.

* `updateCurrentUser` is more accurate than `replaceCurrentUser`
2019-06-14 14:54:20 +02:00

57 lines
1.5 KiB
JavaScript

import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
import DiscoveryFixtures from "fixtures/discovery_fixtures";
acceptance("Redirect to Top", {
pretend(server, helper) {
server.get("/top/weekly.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
server.get("/top/monthly.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
server.get("/top/all.json", () => {
return helper.response(DiscoveryFixtures["/latest.json"]);
});
},
loggedIn: true
});
QUnit.test("redirects categories to weekly top", async assert => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
period: "weekly",
reason: "Welcome back!"
}
});
await visit("/categories");
assert.equal(currentPath(), "discovery.topWeekly", "it works for categories");
});
QUnit.test("redirects latest to monthly top", async assert => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
period: "monthly",
reason: "Welcome back!"
}
});
await visit("/latest");
assert.equal(currentPath(), "discovery.topMonthly", "it works for latest");
});
QUnit.test("redirects root to All top", async assert => {
updateCurrentUser({
should_be_redirected_to_top: true,
redirected_to_top: {
period: null,
reason: "Welcome back!"
}
});
await visit("/");
assert.equal(currentPath(), "discovery.topAll", "it works for root");
});