DEV: Add tests for review-index route (#18415)
Add tests for review-index route
This commit is contained in:
parent
e3f1e0e9bc
commit
70258232f5
|
@ -0,0 +1,66 @@
|
|||
import User from "discourse/models/user";
|
||||
import { setupTest } from "ember-qunit";
|
||||
import { module, test } from "qunit";
|
||||
|
||||
module("Unit | Route | review-index", function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test("subscribes and unsubscribes /reviewable_counts MessageBus channel when user menu not enabled", function (assert) {
|
||||
const currentUser = User.create({ redesigned_user_menu_enabled: false });
|
||||
this.owner.unregister("service:current-user");
|
||||
this.owner.register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
this.owner.inject("route", "currentUser", "service:current-user");
|
||||
|
||||
const reviewIndexRoute = this.owner.lookup("route:review-index");
|
||||
const messageBus = this.owner.lookup("service:message-bus");
|
||||
|
||||
let channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.false(channels.includes("/reviewable_counts"));
|
||||
assert.false(channels.includes("/reviewable_claimed"));
|
||||
|
||||
reviewIndexRoute.activate();
|
||||
|
||||
channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.true(channels.includes("/reviewable_counts"));
|
||||
assert.true(channels.includes("/reviewable_claimed"));
|
||||
|
||||
reviewIndexRoute.deactivate();
|
||||
|
||||
channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.false(channels.includes("/reviewable_counts"));
|
||||
assert.false(channels.includes("/reviewable_claimed"));
|
||||
});
|
||||
|
||||
test("subscribes and unsubscribes /reviewable_counts(with id) when user menu enabled", function (assert) {
|
||||
const currentUser = User.create({
|
||||
redesigned_user_menu_enabled: true,
|
||||
id: "the-id",
|
||||
});
|
||||
this.owner.unregister("service:current-user");
|
||||
this.owner.register("service:current-user", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
this.owner.inject("route", "currentUser", "service:current-user");
|
||||
|
||||
const reviewIndexRoute = this.owner.lookup("route:review-index");
|
||||
const messageBus = this.owner.lookup("service:message-bus");
|
||||
|
||||
let channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.false(channels.includes("/reviewable_counts/the-id"));
|
||||
assert.false(channels.includes("/reviewable_claimed"));
|
||||
|
||||
reviewIndexRoute.activate();
|
||||
|
||||
channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.true(channels.includes("/reviewable_counts/the-id"));
|
||||
assert.true(channels.includes("/reviewable_claimed"));
|
||||
|
||||
reviewIndexRoute.deactivate();
|
||||
|
||||
channels = messageBus.callbacks.map((c) => c.channel);
|
||||
assert.false(channels.includes("/reviewable_counts/the-id"));
|
||||
assert.false(channels.includes("/reviewable_claimed"));
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue