FEATURE: Display notification count in title for logged in users (#7184)

This replaces the 'contextual' counters for logged in users. We will still use the old method for anon users
This commit is contained in:
David Taylor
2019-03-18 12:59:47 +00:00
committed by GitHub
parent 0c01cb2cf3
commit 4e8c174ee5
6 changed files with 114 additions and 16 deletions

View File

@ -1,3 +1,5 @@
import { logIn, replaceCurrentUser } from "helpers/qunit-helpers";
QUnit.module("lib:discourse");
QUnit.test("getURL on subfolder install", assert => {
@ -24,3 +26,64 @@ QUnit.test("getURLWithCDN on subfolder install with S3", assert => {
Discourse.S3CDN = null;
Discourse.S3BaseUrl = null;
});
QUnit.test("title counts are updated correctly", assert => {
Discourse.set("hasFocus", true);
Discourse.set("contextCount", 0);
Discourse.set("notificationCount", 0);
Discourse.set("_docTitle", "Test Title");
assert.equal(document.title, "Test Title", "title is correct");
Discourse.updateNotificationCount(5);
assert.equal(document.title, "Test Title", "title doesn't change with focus");
Discourse.incrementBackgroundContextCount();
assert.equal(document.title, "Test Title", "title doesn't change with focus");
Discourse.set("hasFocus", false);
Discourse.updateNotificationCount(5);
assert.equal(
document.title,
"Test Title",
"notification count ignored for anon"
);
Discourse.incrementBackgroundContextCount();
assert.equal(
document.title,
"(1) Test Title",
"title changes when incremented for anon"
);
logIn();
replaceCurrentUser({ dynamic_favicon: false });
Discourse.set("hasFocus", true);
Discourse.set("hasFocus", false);
Discourse.incrementBackgroundContextCount();
assert.equal(
document.title,
"Test Title",
"title doesn't change when incremented for logged in"
);
Discourse.updateNotificationCount(3);
assert.equal(
document.title,
"(3) Test Title",
"title includes notification count for logged in user"
);
Discourse.set("hasFocus", false);
Discourse.set("hasFocus", true);
assert.equal(
document.title,
"Test Title",
"counter dissappears after focus, and doesn't reappear until another notification arrives"
);
});