This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/unit/services/document-title-test.js
Robin Ward 71d37953d5 REFACTOR: Import QUnit and related helpers rather than globals
We used many global functions to handle tests when they should be
imported like other libraries in our application. This also gets us
closer to the way Ember CLI prefers our tests to be laid out.
2020-10-07 11:50:49 -04:00

58 lines
2.2 KiB
JavaScript

import { test } from "qunit";
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
import { currentUser } from "discourse/tests/helpers/qunit-helpers";
discourseModule("service:document-title", {
beforeEach() {
this.documentTitle = this.container.lookup("service:document-title");
this.documentTitle.currentUser = null;
this.container.lookup("session:main").hasFocus = true;
},
afterEach() {
this.documentTitle.reset();
},
});
test("it updates the document title", function (assert) {
this.documentTitle.setTitle("Test Title");
assert.equal(document.title, "Test Title", "title is correct");
});
test("it doesn't display notification counts for anonymous users", function (assert) {
this.documentTitle.setTitle("test notifications");
this.documentTitle.updateNotificationCount(5);
assert.equal(document.title, "test notifications");
this.documentTitle.setFocus(false);
this.documentTitle.updateNotificationCount(6);
assert.equal(document.title, "test notifications");
});
test("it displays notification counts for logged in users", function (assert) {
this.documentTitle.currentUser = currentUser();
this.documentTitle.currentUser.dynamic_favicon = false;
this.documentTitle.setTitle("test notifications");
this.documentTitle.updateNotificationCount(5);
assert.equal(document.title, "test notifications");
this.documentTitle.setFocus(false);
this.documentTitle.updateNotificationCount(6);
assert.equal(document.title, "(6) test notifications");
this.documentTitle.setFocus(true);
assert.equal(document.title, "test notifications");
});
test("it doesn't increment background context counts when focused", function (assert) {
this.documentTitle.setTitle("background context");
this.documentTitle.setFocus(true);
this.documentTitle.incrementBackgroundContextCount();
assert.equal(document.title, "background context");
});
test("it increments background context counts when not focused", function (assert) {
this.documentTitle.setTitle("background context");
this.documentTitle.setFocus(false);
this.documentTitle.incrementBackgroundContextCount();
assert.equal(document.title, "(1) background context");
this.documentTitle.setFocus(true);
assert.equal(document.title, "background context");
});