mirror of
https://github.com/discourse/discourse.git
synced 2024-12-04 05:23:39 +08:00
DEV: Make the logIn
helper replace current-user service (#30010)
This commit is contained in:
parent
dfb74d90c3
commit
1396aef99f
|
@ -129,8 +129,15 @@ export function updateCurrentUser(properties) {
|
|||
}
|
||||
|
||||
// Note: do not use this in acceptance tests. Use `loggedIn: true` instead
|
||||
export function logIn() {
|
||||
return User.resetCurrent(currentUser());
|
||||
export function logIn(owner) {
|
||||
const user = User.resetCurrent(currentUser());
|
||||
|
||||
owner?.unregister("service:current-user");
|
||||
owner?.register("service:current-user", user, {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
// Note: Only use if `loggedIn: true` has been used in an acceptance test
|
||||
|
|
|
@ -155,7 +155,7 @@ module("Unit | Utility | url", function (hooks) {
|
|||
});
|
||||
|
||||
test("routeTo does not rewrite routes started with /my", async function (assert) {
|
||||
logIn();
|
||||
logIn(this.owner);
|
||||
sinon.stub(DiscourseURL, "router").get(() => {
|
||||
return { currentURL: "/" };
|
||||
});
|
||||
|
|
|
@ -28,13 +28,9 @@ module("Unit | Service | document-title", function (hooks) {
|
|||
});
|
||||
|
||||
test("it displays notification counts for logged in users", function (assert) {
|
||||
const currentUser = logIn();
|
||||
this.owner.unregister("service:current-user");
|
||||
this.owner.register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
const currentUser = logIn(this.owner);
|
||||
currentUser.user_option.dynamic_favicon = false;
|
||||
|
||||
this.documentTitle.setTitle("test notifications");
|
||||
this.documentTitle.updateNotificationCount(5);
|
||||
assert.strictEqual(document.title, "test notifications");
|
||||
|
@ -46,11 +42,7 @@ module("Unit | Service | document-title", function (hooks) {
|
|||
});
|
||||
|
||||
test("it doesn't display notification counts for users in do not disturb", function (assert) {
|
||||
const currentUser = logIn();
|
||||
this.owner.unregister("service:current-user");
|
||||
this.owner.register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
const currentUser = logIn(this.owner);
|
||||
|
||||
const date = new Date();
|
||||
date.setHours(date.getHours() + 1);
|
||||
|
|
|
@ -8,11 +8,7 @@ module("Unit | Service | user-tips", function (hooks) {
|
|||
setupTest(hooks);
|
||||
|
||||
test("hideUserTipForever() makes a single request", async function (assert) {
|
||||
const currentUser = logIn();
|
||||
this.owner.unregister("service:current-user");
|
||||
this.owner.register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
logIn(this.owner);
|
||||
|
||||
const site = getOwner(this).lookup("service:site");
|
||||
site.set("user_tips", { first_notification: 1 });
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { getOwner } from "@ember/owner";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import User from "discourse/models/user";
|
||||
import pretender from "discourse/tests/helpers/create-pretender";
|
||||
import { logIn } from "discourse/tests/helpers/qunit-helpers";
|
||||
import ChatMessageInteractor, {
|
||||
|
@ -36,21 +34,12 @@ module("Chat | Unit | Utility | plugin-api", function (hooks) {
|
|||
"function"
|
||||
);
|
||||
|
||||
logIn();
|
||||
const currentUser = User.current();
|
||||
getOwner(this).unregister("service:current-user");
|
||||
getOwner(this).register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
|
||||
const message = new ChatFabricators(getOwner(this)).message({
|
||||
user: currentUser,
|
||||
});
|
||||
const context = "channel";
|
||||
const user = logIn(this.owner);
|
||||
const message = new ChatFabricators(this.owner).message({ user });
|
||||
const interactor = new ChatMessageInteractor(
|
||||
getOwner(this),
|
||||
this.owner,
|
||||
message,
|
||||
context
|
||||
"channel"
|
||||
);
|
||||
|
||||
// assert that the initial secondary actions are present
|
||||
|
|
Loading…
Reference in New Issue
Block a user