2019-06-14 20:54:20 +08:00
|
|
|
import { logIn, updateCurrentUser } from "helpers/qunit-helpers";
|
2019-03-18 20:59:47 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("lib:discourse");
|
2015-10-22 01:13:19 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("getURL on subfolder install", assert => {
|
2015-10-22 01:13:19 +08:00
|
|
|
Discourse.BaseUri = "/forum";
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.equal(Discourse.getURL("/"), "/forum/", "root url has subfolder");
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.equal(
|
|
|
|
Discourse.getURL("/u/neil"),
|
|
|
|
"/forum/u/neil",
|
|
|
|
"relative url has subfolder"
|
|
|
|
);
|
2020-01-28 01:51:46 +08:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
Discourse.getURL("/svg-sprite/forum.example.com/svg-sprite.js"),
|
|
|
|
"/forum/svg-sprite/forum.example.com/svg-sprite.js",
|
|
|
|
"works when the url has the prefix in the middle"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
Discourse.getURL("/forum/t/123"),
|
|
|
|
"/forum/t/123",
|
|
|
|
"does not prefix if the URL is already prefixed"
|
|
|
|
);
|
2018-06-15 23:03:24 +08:00
|
|
|
});
|
2018-08-22 10:31:13 +08:00
|
|
|
|
|
|
|
QUnit.test("getURLWithCDN on subfolder install with S3", assert => {
|
|
|
|
Discourse.BaseUri = "/forum";
|
|
|
|
|
|
|
|
Discourse.S3CDN = "https://awesome.cdn/site";
|
|
|
|
Discourse.S3BaseUrl = "//test.s3-us-west-1.amazonaws.com/site";
|
|
|
|
|
|
|
|
let url = "//test.s3-us-west-1.amazonaws.com/site/forum/awesome.png";
|
|
|
|
let expected = "https://awesome.cdn/site/forum/awesome.png";
|
|
|
|
|
|
|
|
assert.equal(Discourse.getURLWithCDN(url), expected, "at correct path");
|
|
|
|
|
|
|
|
Discourse.S3CDN = null;
|
|
|
|
Discourse.S3BaseUrl = null;
|
|
|
|
});
|
2019-03-18 20:59:47 +08:00
|
|
|
|
|
|
|
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();
|
2019-06-14 20:54:20 +08:00
|
|
|
updateCurrentUser({ dynamic_favicon: false });
|
2019-03-18 20:59:47 +08:00
|
|
|
|
|
|
|
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"
|
|
|
|
);
|
|
|
|
});
|