2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2022-11-11 13:39:15 +08:00
|
|
|
import { setupTest } from "ember-qunit";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { module, test } from "qunit";
|
2022-11-11 13:39:15 +08:00
|
|
|
import sinon from "sinon";
|
2023-10-11 02:38:59 +08:00
|
|
|
import Site from "discourse/models/site";
|
2023-03-11 01:49:59 +08:00
|
|
|
import {
|
|
|
|
addChatDrawerStateCallback,
|
|
|
|
resetChatDrawerStateCallbacks,
|
|
|
|
} from "discourse/plugins/chat/discourse/services/chat-state-manager";
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Unit | Service | chat-state-manager",
|
|
|
|
function (hooks) {
|
|
|
|
setupTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function () {
|
2023-03-11 01:49:59 +08:00
|
|
|
this.subject = getOwner(this).lookup("service:chat-state-manager");
|
2022-11-11 13:39:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
hooks.afterEach(function () {
|
|
|
|
this.subject.reset();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("isFullPagePreferred", function (assert) {
|
2024-11-04 17:27:30 +08:00
|
|
|
assert.false(this.subject.isFullPagePreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
this.subject.prefersFullPage();
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.subject.isFullPagePreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
this.subject.prefersDrawer();
|
|
|
|
|
2024-11-04 17:27:30 +08:00
|
|
|
assert.false(this.subject.isFullPagePreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
this.subject.prefersDrawer();
|
|
|
|
Site.currentProp("mobileView", true);
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.subject.isFullPagePreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("isDrawerPreferred", function (assert) {
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.subject.isDrawerPreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
this.subject.prefersFullPage();
|
|
|
|
|
2024-11-04 17:27:30 +08:00
|
|
|
assert.false(this.subject.isDrawerPreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
this.subject.prefersDrawer();
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.subject.isDrawerPreferred);
|
2022-11-11 13:39:15 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("lastKnownChatURL", function (assert) {
|
|
|
|
assert.strictEqual(this.subject.lastKnownChatURL, "/chat");
|
|
|
|
|
|
|
|
this.subject.storeChatURL("/bar");
|
|
|
|
|
|
|
|
assert.strictEqual(this.subject.lastKnownChatURL, "/bar");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("lastKnownAppURL", function (assert) {
|
|
|
|
assert.strictEqual(this.subject.lastKnownAppURL, "/latest");
|
|
|
|
|
|
|
|
sinon.stub(this.subject.router, "currentURL").value("/foo");
|
|
|
|
this.subject.storeAppURL();
|
|
|
|
|
|
|
|
assert.strictEqual(this.subject.lastKnownAppURL, "/foo");
|
|
|
|
|
|
|
|
this.subject.storeAppURL("/bar");
|
|
|
|
|
|
|
|
assert.strictEqual(this.subject.lastKnownAppURL, "/bar");
|
|
|
|
});
|
|
|
|
|
2022-11-25 21:15:38 +08:00
|
|
|
test("isFullPageActive", function (assert) {
|
2022-11-11 13:39:15 +08:00
|
|
|
sinon.stub(this.subject.router, "currentRouteName").value("foo");
|
2024-11-04 17:27:30 +08:00
|
|
|
assert.false(this.subject.isFullPageActive);
|
2022-11-11 13:39:15 +08:00
|
|
|
|
|
|
|
sinon.stub(this.subject.router, "currentRouteName").value("chat");
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.subject.isFullPageActive);
|
2022-11-25 21:15:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("didCollapseDrawer", function (assert) {
|
|
|
|
this.subject.didCollapseDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.false(this.subject.isDrawerExpanded);
|
|
|
|
assert.true(this.subject.isDrawerActive);
|
2022-11-25 21:15:38 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("didExpandDrawer", function (assert) {
|
|
|
|
const stub = sinon.stub(
|
|
|
|
this.owner.lookup("service:chat"),
|
|
|
|
"updatePresence"
|
|
|
|
);
|
|
|
|
|
|
|
|
this.subject.didExpandDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.true(this.subject.isDrawerExpanded);
|
|
|
|
assert.true(this.subject.isDrawerActive);
|
2022-11-25 21:15:38 +08:00
|
|
|
sinon.assert.calledOnce(stub);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("didCloseDrawer", function (assert) {
|
|
|
|
const stub = sinon.stub(
|
|
|
|
this.owner.lookup("service:chat"),
|
|
|
|
"updatePresence"
|
|
|
|
);
|
|
|
|
|
|
|
|
this.subject.didCloseDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.false(this.subject.isDrawerExpanded);
|
|
|
|
assert.false(this.subject.isDrawerActive);
|
2022-11-25 21:15:38 +08:00
|
|
|
sinon.assert.calledOnce(stub);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("didOpenDrawer", function (assert) {
|
|
|
|
const stub = sinon.stub(
|
|
|
|
this.owner.lookup("service:chat"),
|
|
|
|
"updatePresence"
|
|
|
|
);
|
|
|
|
|
|
|
|
this.subject.didOpenDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.true(this.subject.isDrawerExpanded);
|
|
|
|
assert.true(this.subject.isDrawerActive);
|
2022-11-25 21:15:38 +08:00
|
|
|
assert.strictEqual(this.subject.lastKnownChatURL, "/chat");
|
|
|
|
|
|
|
|
this.subject.didOpenDrawer("/foo");
|
|
|
|
|
|
|
|
assert.strictEqual(this.subject.lastKnownChatURL, "/foo");
|
|
|
|
sinon.assert.calledTwice(stub);
|
2022-11-11 13:39:15 +08:00
|
|
|
});
|
2023-03-11 01:49:59 +08:00
|
|
|
|
|
|
|
test("callbacks", function (assert) {
|
|
|
|
this.state = null;
|
|
|
|
addChatDrawerStateCallback((state) => {
|
|
|
|
this.state = state;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.subject.didOpenDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.true(this.state.isDrawerActive);
|
|
|
|
assert.true(this.state.isDrawerExpanded);
|
2023-03-11 01:49:59 +08:00
|
|
|
|
|
|
|
this.subject.didCloseDrawer();
|
|
|
|
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.false(this.state.isDrawerActive);
|
|
|
|
assert.false(this.state.isDrawerExpanded);
|
2023-03-11 01:49:59 +08:00
|
|
|
|
|
|
|
resetChatDrawerStateCallbacks();
|
|
|
|
});
|
2022-11-11 13:39:15 +08:00
|
|
|
}
|
|
|
|
);
|