2021-11-13 20:10:13 +08:00
|
|
|
import { click, visit } from "@ember/test-helpers";
|
2021-05-31 14:27:13 +08:00
|
|
|
import {
|
|
|
|
acceptance,
|
2021-06-08 23:54:12 +08:00
|
|
|
count,
|
2021-08-26 00:57:27 +08:00
|
|
|
exists,
|
2021-05-31 14:27:13 +08:00
|
|
|
publishToMessageBus,
|
2021-06-08 23:54:12 +08:00
|
|
|
query,
|
|
|
|
queryAll,
|
2021-05-31 14:27:13 +08:00
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { test } from "qunit";
|
2022-02-25 10:08:22 +08:00
|
|
|
import User from "discourse/models/user";
|
2021-05-31 14:27:13 +08:00
|
|
|
|
|
|
|
acceptance("User Notifications", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
|
|
|
|
test("Update works correctly", async function (assert) {
|
|
|
|
await visit("/");
|
|
|
|
await click("li.current-user");
|
|
|
|
|
|
|
|
// set older notifications to read
|
|
|
|
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/notification/19", {
|
2021-05-31 14:27:13 +08:00
|
|
|
unread_notifications: 5,
|
|
|
|
unread_private_messages: 0,
|
|
|
|
unread_high_priority_notifications: 0,
|
|
|
|
read_first_notification: false,
|
|
|
|
last_notification: {},
|
|
|
|
recent: [
|
|
|
|
[123, false],
|
|
|
|
[456, false],
|
|
|
|
[789, true],
|
|
|
|
[1234, true],
|
|
|
|
[5678, true],
|
|
|
|
],
|
|
|
|
seen_notification_id: null,
|
|
|
|
});
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
assert.strictEqual(count("#quick-access-notifications li"), 6);
|
2021-05-31 14:27:13 +08:00
|
|
|
|
|
|
|
// high priority, unread notification - should be first
|
|
|
|
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/notification/19", {
|
2021-05-31 14:27:13 +08:00
|
|
|
unread_notifications: 6,
|
|
|
|
unread_private_messages: 0,
|
|
|
|
unread_high_priority_notifications: 1,
|
|
|
|
read_first_notification: false,
|
|
|
|
last_notification: {
|
|
|
|
notification: {
|
|
|
|
id: 42,
|
|
|
|
user_id: 1,
|
|
|
|
notification_type: 5,
|
|
|
|
read: false,
|
|
|
|
high_priority: true,
|
|
|
|
created_at: "2021-01-01 12:00:00 UTC",
|
|
|
|
post_number: 1,
|
|
|
|
topic_id: 42,
|
|
|
|
fancy_title: "First notification",
|
|
|
|
slug: "topic",
|
|
|
|
data: {
|
|
|
|
topic_title: "First notification",
|
|
|
|
original_post_id: 42,
|
|
|
|
original_post_type: 1,
|
|
|
|
original_username: "foo",
|
|
|
|
revision_number: null,
|
|
|
|
display_username: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
recent: [
|
|
|
|
[42, false],
|
|
|
|
[123, false],
|
|
|
|
[456, false],
|
|
|
|
[789, true],
|
|
|
|
[1234, true],
|
|
|
|
[5678, true],
|
|
|
|
],
|
|
|
|
seen_notification_id: null,
|
|
|
|
});
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
assert.strictEqual(count("#quick-access-notifications li"), 6);
|
|
|
|
assert.strictEqual(
|
2021-06-08 23:54:12 +08:00
|
|
|
query("#quick-access-notifications li span[data-topic-id]").innerText,
|
2021-05-31 14:27:13 +08:00
|
|
|
"First notification"
|
|
|
|
);
|
|
|
|
|
|
|
|
// high priority, read notification - should be second
|
|
|
|
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/notification/19", {
|
2021-05-31 14:27:13 +08:00
|
|
|
unread_notifications: 7,
|
|
|
|
unread_private_messages: 0,
|
|
|
|
unread_high_priority_notifications: 1,
|
|
|
|
read_first_notification: false,
|
|
|
|
last_notification: {
|
|
|
|
notification: {
|
|
|
|
id: 43,
|
|
|
|
user_id: 1,
|
|
|
|
notification_type: 5,
|
|
|
|
read: true,
|
|
|
|
high_priority: false,
|
|
|
|
created_at: "2021-01-01 12:00:00 UTC",
|
|
|
|
post_number: 1,
|
|
|
|
topic_id: 42,
|
|
|
|
fancy_title: "Second notification",
|
|
|
|
slug: "topic",
|
|
|
|
data: {
|
|
|
|
topic_title: "Second notification",
|
|
|
|
original_post_id: 42,
|
|
|
|
original_post_type: 1,
|
|
|
|
original_username: "foo",
|
|
|
|
revision_number: null,
|
|
|
|
display_username: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
recent: [
|
|
|
|
[42, false],
|
|
|
|
[43, true],
|
|
|
|
[123, false],
|
|
|
|
[456, false],
|
|
|
|
[789, true],
|
|
|
|
[1234, true],
|
|
|
|
[5678, true],
|
|
|
|
],
|
|
|
|
seen_notification_id: null,
|
|
|
|
});
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
assert.strictEqual(count("#quick-access-notifications li"), 7);
|
|
|
|
assert.strictEqual(
|
2021-06-08 23:54:12 +08:00
|
|
|
queryAll("#quick-access-notifications li span[data-topic-id]")[1]
|
|
|
|
.innerText,
|
2021-05-31 14:27:13 +08:00
|
|
|
"Second notification"
|
|
|
|
);
|
2021-07-06 18:33:56 +08:00
|
|
|
|
|
|
|
// updates existing notifications
|
|
|
|
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/notification/19", {
|
2021-07-06 18:33:56 +08:00
|
|
|
unread_notifications: 8,
|
|
|
|
unread_private_messages: 0,
|
|
|
|
unread_high_priority_notifications: 1,
|
|
|
|
read_first_notification: false,
|
|
|
|
last_notification: {
|
|
|
|
notification: {
|
|
|
|
id: 44,
|
|
|
|
user_id: 1,
|
|
|
|
notification_type: 5,
|
|
|
|
read: true,
|
|
|
|
high_priority: false,
|
|
|
|
created_at: "2021-01-01 12:00:00 UTC",
|
|
|
|
post_number: 1,
|
|
|
|
topic_id: 42,
|
|
|
|
fancy_title: "Third notification",
|
|
|
|
slug: "topic",
|
|
|
|
data: {
|
|
|
|
topic_title: "Third notification",
|
|
|
|
original_post_id: 42,
|
|
|
|
original_post_type: 1,
|
|
|
|
original_username: "foo",
|
|
|
|
revision_number: null,
|
|
|
|
display_username: "foo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
recent: [
|
|
|
|
[5678, false],
|
|
|
|
[1234, false],
|
|
|
|
[789, false],
|
|
|
|
[456, true],
|
|
|
|
[123, true],
|
|
|
|
[44, false],
|
|
|
|
[43, false],
|
|
|
|
[42, true],
|
|
|
|
],
|
|
|
|
seen_notification_id: null,
|
|
|
|
});
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
assert.strictEqual(count("#quick-access-notifications li"), 8);
|
2021-07-06 18:33:56 +08:00
|
|
|
const texts = [];
|
2022-07-25 08:32:04 +08:00
|
|
|
[...queryAll("#quick-access-notifications li")].forEach((element) => {
|
|
|
|
texts.push(element.innerText.trim());
|
|
|
|
});
|
2021-07-06 18:33:56 +08:00
|
|
|
assert.deepEqual(texts, [
|
|
|
|
"foo First notification",
|
|
|
|
"foo Third notification",
|
|
|
|
"foo Second notification",
|
|
|
|
"velesin some title",
|
|
|
|
"aquaman liked 5 of your posts",
|
|
|
|
"5 messages in your test inbox",
|
|
|
|
"test1 accepted your invitation",
|
|
|
|
"Membership accepted in 'test'",
|
|
|
|
]);
|
2021-05-31 14:27:13 +08:00
|
|
|
});
|
|
|
|
});
|
2021-08-26 00:57:27 +08:00
|
|
|
|
2022-02-25 10:08:22 +08:00
|
|
|
acceptance("Category Notifications", function (needs) {
|
|
|
|
needs.user({ muted_category_ids: [1], indirectly_muted_category_ids: [2] });
|
|
|
|
|
|
|
|
test("New category is muted when parent category is muted", async function (assert) {
|
|
|
|
await visit("/");
|
|
|
|
const user = User.current();
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/categories", {
|
2022-02-25 10:08:22 +08:00
|
|
|
categories: [
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
parent_category_id: 99,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 4,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
assert.deepEqual(user.indirectly_muted_category_ids, [2]);
|
|
|
|
|
2022-07-25 01:55:58 +08:00
|
|
|
await publishToMessageBus("/categories", {
|
2022-02-25 10:08:22 +08:00
|
|
|
categories: [
|
|
|
|
{
|
|
|
|
id: 4,
|
|
|
|
parent_category_id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 5,
|
|
|
|
parent_category_id: 2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
assert.deepEqual(user.indirectly_muted_category_ids, [2, 4, 5]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-08-26 00:57:27 +08:00
|
|
|
acceptance(
|
|
|
|
"User Notifications - there is no notifications yet",
|
|
|
|
function (needs) {
|
|
|
|
needs.user();
|
|
|
|
|
|
|
|
needs.pretender((server, helper) => {
|
|
|
|
server.get("/notifications", () => {
|
|
|
|
return helper.response({
|
|
|
|
notifications: [],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("It renders the empty state panel", async function (assert) {
|
|
|
|
await visit("/u/eviltrout/notifications");
|
|
|
|
assert.ok(exists("div.empty-state"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("It does not render filter", async function (assert) {
|
|
|
|
await visit("/u/eviltrout/notifications");
|
|
|
|
|
2021-09-29 19:24:55 +08:00
|
|
|
assert.notOk(exists("div.user-notifications-filter"));
|
2021-08-26 00:57:27 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|