Some of the changes in this commit are extracted from https://github.com/discourse/discourse/pull/17379. The bookmarks tab in the new user menu is different from the other tabs in that it can display a mixture of notifications and bookmarks. When there are unread bookmark reminder notifications, the tab displays all of these notifications at the top and fills the remaining space in the menu with the rest of the bookmarks. The bubble/badge count on the bookmarks tab indicates how many unread bookmark reminder notifications there are. On the technical aspect, since this commit introduces a new `bookmark-item` component, we've done some refactoring so that all 3 "item" components (`notification-item`, `reviewable-item` and the new `bookmark-item`) inherit from a base component and get identical HTML structure so they all look consistent. Internal tickets: t70584 and t65045.
90 lines
2.8 KiB
JavaScript
90 lines
2.8 KiB
JavaScript
import { discourseModule } from "discourse/tests/helpers/qunit-helpers";
|
|
import { test } from "qunit";
|
|
import * as showModal from "discourse/lib/show-modal";
|
|
import sinon from "sinon";
|
|
import EmberObject from "@ember/object";
|
|
import User from "discourse/models/user";
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
|
import I18n from "I18n";
|
|
|
|
discourseModule("Unit | Controller | user-notifications", function () {
|
|
test("Mark read marks all models read when response is 200", async function (assert) {
|
|
const model = [
|
|
EmberObject.create({ read: false }),
|
|
EmberObject.create({ read: false }),
|
|
];
|
|
const controller = this.getController("user-notifications", {
|
|
model,
|
|
});
|
|
pretender.put("/notifications/mark-read", () => {
|
|
return [200];
|
|
});
|
|
|
|
await controller.markRead();
|
|
|
|
assert.strictEqual(
|
|
model.every(({ read }) => read === true),
|
|
true
|
|
);
|
|
});
|
|
|
|
test("Mark read does not mark models read when response is not successful", async function (assert) {
|
|
const model = [
|
|
EmberObject.create({ read: false }),
|
|
EmberObject.create({ read: true }),
|
|
];
|
|
const controller = this.getController("user-notifications", { model });
|
|
pretender.put("/notifications/mark-read", () => {
|
|
return [500];
|
|
});
|
|
|
|
assert.rejects(controller.markRead());
|
|
assert.deepEqual(
|
|
model.map(({ read }) => read),
|
|
[false, true],
|
|
"models unmodified"
|
|
);
|
|
});
|
|
|
|
test("Marks all notifications read when no high priority notifications", function (assert) {
|
|
let markRead = false;
|
|
const currentUser = User.create({ unread_high_priority_notifications: 0 });
|
|
const controller = this.getController("user-notifications", {
|
|
model: [],
|
|
currentUser,
|
|
});
|
|
sinon.stub(controller, "markRead").callsFake(() => {
|
|
markRead = true;
|
|
});
|
|
|
|
controller.send("resetNew");
|
|
|
|
assert.strictEqual(markRead, true);
|
|
});
|
|
|
|
test("Shows modal when has high priority notifications", function (assert) {
|
|
let capturedProperties;
|
|
sinon
|
|
.stub(showModal, "default")
|
|
.withArgs("dismiss-notification-confirmation")
|
|
.returns({
|
|
setProperties: (properties) => (capturedProperties = properties),
|
|
});
|
|
const currentUser = User.create({ unread_high_priority_notifications: 1 });
|
|
const controller = this.getController("user-notifications", {
|
|
currentUser,
|
|
});
|
|
const markReadFake = sinon.fake();
|
|
sinon.stub(controller, "markRead").callsFake(markReadFake);
|
|
|
|
controller.send("resetNew");
|
|
|
|
assert.strictEqual(
|
|
capturedProperties.confirmationMessage,
|
|
I18n.t("notifications.dismiss_confirmation.body.default", { count: 1 })
|
|
);
|
|
capturedProperties.dismissNotifications();
|
|
assert.strictEqual(markReadFake.callCount, 1);
|
|
});
|
|
});
|