mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 14:55:15 +08:00
Follow-up to https://github.com/discourse/discourse/pull/36652 The linked PR adds logic to show a counter in the document title when chat messages arrive to a channel that's left open in a background tab. This behavior is consistent with the topic page where the document title also shows a counter when posts are made. We do have an existing user preference (Preferences > Interface > Background page title displays count of:) to disable the document title counter for topics, however, chat currently shows counter in the document title regardless of that user preference. This PR makes chat respect the user preference.
56 lines
1.8 KiB
JavaScript
Vendored
56 lines
1.8 KiB
JavaScript
Vendored
import { test } from "qunit";
|
|
import sinon from "sinon";
|
|
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
acceptance("Discourse Chat | Unit | Service | chat", function (needs) {
|
|
needs.user();
|
|
|
|
needs.hooks.beforeEach(function () {
|
|
Object.defineProperty(this, "currentUser", {
|
|
get: () => this.container.lookup("service:current-user"),
|
|
});
|
|
Object.defineProperty(this, "chat", {
|
|
get: () => this.container.lookup("service:chat"),
|
|
});
|
|
this.chatTrackingStateManager = this.container.lookup(
|
|
"service:chat-tracking-state-manager"
|
|
);
|
|
this.chatPanePendingManager = this.container.lookup(
|
|
"service:chat-pane-pending-manager"
|
|
);
|
|
sinon
|
|
.stub(this.chatTrackingStateManager, "allChannelUrgentCount")
|
|
.get(() => 5);
|
|
sinon
|
|
.stub(this.chatPanePendingManager, "totalPendingMessageCount")
|
|
.get(() => 10);
|
|
});
|
|
|
|
test("getDocumentTitleCount returns urget count when title_count_mode is 'notifications'", function (assert) {
|
|
this.currentUser.user_option.title_count_mode = "notifications";
|
|
|
|
const count = this.chat.getDocumentTitleCount();
|
|
|
|
assert.strictEqual(
|
|
count,
|
|
5,
|
|
"returns only urgent count (mentions, DMs, watched threads)"
|
|
);
|
|
});
|
|
|
|
test("getDocumentTitleCount returns pending count when title_count_mode is 'contextual'", function (assert) {
|
|
this.currentUser.user_option.title_count_mode = "contextual";
|
|
|
|
const count = this.chat.getDocumentTitleCount();
|
|
|
|
assert.strictEqual(count, 10, "returns pending count");
|
|
});
|
|
|
|
test("getDocumentTitleCount returns pending count when user_option is null", function (assert) {
|
|
this.currentUser.user_option = null;
|
|
|
|
const count = this.chat.getDocumentTitleCount();
|
|
|
|
assert.strictEqual(count, 10, "returns pending count");
|
|
});
|
|
});
|