Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Add a direct mentions tab to the user menu (#44924)

Keegan George167479b1fa54
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index b9384aa2842..e0f4d7a4104 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1933,6 +1933,8 @@ en:
You will be notified in this panel about activity directly relevant to you, including replies to your topics and posts, when someone <b>@mentions</b> you or quotes you, and replies to topics you are watching. Notifications will also be sent to your email when you haven’t logged in for a while.
<br><br>
Look for the %{icon} to decide which specific topics, categories and tags you want to be notified about. For more, see your <a href='%{preferencesUrl}'>notification preferences</a>.
+ no_mentions_title: "You haven’t been mentioned yet"
+ no_mentions_body: "When someone mentions your @username in a post, the notification will appear here."
no_other_notifications_title: "You don’t have any other notifications yet"
no_other_notifications_body: >
You will be notified in this panel about other kinds of activity that may be relevant to you - for example, when someone links to or edits one of your posts.
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 89d99e18600..6a57bd7178d 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -3218,6 +3218,7 @@ en:
prioritize_recently_used_tags: "When adding tags while creating or editing a topic, show the tags the member has recently used on their own topics at the top of the list, before the most popular tags of the forum."
experimental_impersonation_time_limit_minutes: "How long before an impersonation session is automatically ended."
page_loading_indicator: "Configure the loading indicator which appears during page navigations within Discourse. 'Spinner' is a full page indicator. 'Slider' shows a narrow bar at the top of the screen."
+ enable_user_menu_mentions_tab: "Add a Mentions tab to the user menu that shows direct @username mentions separately from replies and group mentions."
show_user_menu_avatars: "Show user avatars in the user menu"
about_page_hidden_groups: "Do not show admins or moderators who are also members of these specific groups on the /about page."
about_page_extra_groups: "Groups to show on the about page below the moderators."
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 12f9d8cab8f..4dc2470d215 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -4790,6 +4790,14 @@ dashboard:
client: true
experimental:
+ enable_user_menu_mentions_tab:
+ default: false
+ client: true
+ hidden: true
+ upcoming_change:
+ status: "beta"
+ impact: "feature,all_members"
+ learn_more_url: "https://meta.discourse.org/t/-/415579"
enable_markdown_endpoints:
default: false
hidden: true
diff --git a/frontend/discourse/app/components/user-menu/mentions-list-empty-state.gjs b/frontend/discourse/app/components/user-menu/mentions-list-empty-state.gjs
new file mode 100644
index 00000000000..fbcd9bf225b
--- /dev/null
+++ b/frontend/discourse/app/components/user-menu/mentions-list-empty-state.gjs
@@ -0,0 +1,11 @@
+import DEmptyState from "discourse/ui-kit/d-empty-state";
+import { i18n } from "discourse-i18n";
+
+const MentionsListEmptyState = <template>
+ <DEmptyState
+ @body={{i18n "user.no_mentions_body"}}
+ @title={{i18n "user.no_mentions_title"}}
+ />
+</template>;
+
+export default MentionsListEmptyState;
diff --git a/frontend/discourse/app/components/user-menu/mentions-notifications-list.js b/frontend/discourse/app/components/user-menu/mentions-notifications-list.js
new file mode 100644
index 00000000000..db83a577197
--- /dev/null
+++ b/frontend/discourse/app/components/user-menu/mentions-notifications-list.js
@@ -0,0 +1,20 @@
+import UserMenuMentionsListEmptyState from "discourse/components/user-menu/mentions-list-empty-state";
+import UserMenuNotificationsList from "discourse/components/user-menu/notifications-list";
+
+export default class UserMenuMentionsNotificationsList extends UserMenuNotificationsList {
+ get dismissTypes() {
+ return this.filterByTypes;
+ }
+
+ get emptyStateComponent() {
+ return UserMenuMentionsListEmptyState;
+ }
+
+ get renderDismissConfirmation() {
+ return false;
+ }
+
+ get showAllHref() {
+ return `${this.currentUser.path}/notifications/mentions`;
+ }
+}
diff --git a/frontend/discourse/app/components/user-menu/menu.gjs b/frontend/discourse/app/components/user-menu/menu.gjs
index 4253b3e17f8..10905e120e8 100644
--- a/frontend/discourse/app/components/user-menu/menu.gjs
+++ b/frontend/discourse/app/components/user-menu/menu.gjs
@@ -17,6 +17,7 @@ import { NO_REMINDER_ICON } from "discourse/models/bookmark";
import { i18n } from "discourse-i18n";
import UserMenuBookmarksList from "./bookmarks-list.js";
import UserMenuLikesNotificationsList from "./likes-notifications-list.js";
+import UserMenuMentionsNotificationsList from "./mentions-notifications-list.js";
import UserMenuMessagesList from "./messages-list.js";
import UserMenuNotificationsList from "./notifications-list.js";
import UserMenuOtherNotificationsList from "./other-notifications-list.js";
@@ -44,21 +45,18 @@ const CORE_TOP_TABS = [
id = "replies";
icon = "user_menu.replies";
panelComponent = UserMenuRepliesNotificationsList;
- notificationTypes = [
- "mentioned",
- "group_mentioned",
- "posted",
- "quoted",
- "replied",
- ];
+
+ get notificationTypes() {
+ const types = ["group_mentioned", "posted", "quoted", "replied"];
+ return this.siteSettings.enable_user_menu_mentions_tab
+ ? types
+ : ["mentioned", ...types];
+ }
get count() {
- return (
- this.getUnreadCountForType("mentioned") +
- this.getUnreadCountForType("group_mentioned") +
- this.getUnreadCountForType("posted") +
- this.getUnreadCountForType("quoted") +
- this.getUnreadCountForType("replied")
+ return this.notificationTypes.reduce(
+ (sum, type) => sum + this.getUnreadCountForType(type),
+ 0
);
}
@@ -67,6 +65,25 @@ const CORE_TOP_TABS = [
}
},
+ class extends UserMenuTab {
+ id = "mentions";
+ icon = "at";
+ panelComponent = UserMenuMentionsNotificationsList;
+ notificationTypes = ["mentioned"];
+
+ get shouldDisplay() {
+ return this.siteSettings.enable_user_menu_mentions_tab;
+ }
+
+ get count() {
+ return this.getUnreadCountForType("mentioned");
+ }
+
+ get linkWhenActive() {
+ return `${this.currentUser.path}/notifications/mentions`;
+ }
+ },
+
class extends UserMenuTab {
id = "likes";
icon = "heart";
diff --git a/frontend/discourse/tests/acceptance/user-menu-test.js b/frontend/discourse/tests/acceptance/user-menu-test.js
index 31dba9da73a..cf5c0e28c3b 100644
--- a/frontend/discourse/tests/acceptance/user-menu-test.js
+++ b/frontend/discourse/tests/acceptance/user-menu-test.js
@@ -37,6 +37,7 @@ acceptance("User menu", function (needs) {
});
needs.settings({
+ enable_user_menu_mentions_tab: true,
allow_anonymous_mode: true,
});
@@ -183,6 +184,7 @@ acceptance("User menu", function (needs) {
"user-menu-button-replies": i18n("user_menu.tabs.replies_with_unread", {
count: 2,
}),
+ "user-menu-button-mentions": i18n("user_menu.tabs.mentions"),
"user-menu-button-likes": i18n("user_menu.tabs.likes"),
"user-menu-button-messages": i18n("user_menu.tabs.messages"),
"user-menu-button-bookmarks": i18n("user_menu.tabs.bookmarks"),
@@ -262,13 +264,14 @@ acceptance("User menu", function (needs) {
const expectedTabOrder = {
"user-menu-button-all-notifications": "0",
"user-menu-button-replies": "1",
- "user-menu-button-likes": "2",
- "user-menu-button-messages": "3",
- "user-menu-button-bookmarks": "4",
- "user-menu-button-custom-tab-1": "5",
- "user-menu-button-custom-tab-2": "6",
- "user-menu-button-review-queue": "7",
- "user-menu-button-other-notifications": "8",
+ "user-menu-button-mentions": "2",
+ "user-menu-button-likes": "3",
+ "user-menu-button-messages": "4",
+ "user-menu-button-bookmarks": "5",
+ "user-menu-button-custom-tab-1": "6",
+ "user-menu-button-custom-tab-2": "7",
+ "user-menu-button-review-queue": "8",
+ "user-menu-button-other-notifications": "9",
};
await visit("/");
@@ -295,7 +298,7 @@ acceptance("User menu", function (needs) {
.dom(".tabs-list.bottom-tabs .btn")
.hasAttribute(
"data-tab-number",
- "9",
+ "10",
"bottom tab has the correct data-tab-number"
);
@@ -751,6 +754,7 @@ acceptance("User menu", function (needs) {
const tabs = [
["#user-menu-button-custom-tab-1", "/u/eviltrout/preferences/account"],
["#user-menu-button-replies", "/u/eviltrout/notifications/responses"],
+ ["#user-menu-button-mentions", "/u/eviltrout/notifications/mentions"],
["#user-menu-button-messages", "/u/eviltrout/messages"],
["#user-menu-button-bookmarks", "/u/eviltrout/activity/bookmarks"],
["#user-menu-button-likes", "/u/eviltrout/notifications/likes-received"],
diff --git a/frontend/discourse/tests/integration/components/user-menu/menu-test.gjs b/frontend/discourse/tests/integration/components/user-menu/menu-test.gjs
index 3cfe0d6e673..b136334f10a 100644
--- a/frontend/discourse/tests/integration/components/user-menu/menu-test.gjs
+++ b/frontend/discourse/tests/integration/components/user-menu/menu-test.gjs
@@ -2,12 +2,103 @@ import { click, findAll, render, settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import Menu from "discourse/components/user-menu/menu";
import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types";
+import NotificationFixtures from "discourse/tests/fixtures/notification-fixtures";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import pretender from "discourse/tests/helpers/create-pretender";
+import { i18n } from "discourse-i18n";
module("Integration | Component | UserMenu", function (hooks) {
setupRenderingTest(hooks);
+ hooks.beforeEach(function () {
+ this.siteSettings.enable_user_menu_mentions_tab = true;
+ });
+
+ test("mentions tab is hidden when the upcoming change is disabled", async function (assert) {
+ this.siteSettings.enable_user_menu_mentions_tab = false;
+ this.currentUser.set("grouped_unread_notifications", {
+ [NOTIFICATION_TYPES.mentioned]: 2,
+ [NOTIFICATION_TYPES.group_mentioned]: 3,
+ [NOTIFICATION_TYPES.replied]: 4,
+ });
+ let filterByTypes;
+ pretender.get("/notifications", (request) => {
+ filterByTypes = request.queryParams.filter_by_types;
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ { notifications: [] },
+ ];
+ });
+ await render(<template><Menu /></template>);
+
+ assert
+ .dom("#user-menu-button-mentions")
+ .doesNotExist("the mentions tab is hidden while the change is disabled");
+ assert
+ .dom("#user-menu-button-replies")
+ .exists("the existing Replies tab remains available");
+ assert
+ .dom("#user-menu-button-replies .badge-notification")
+ .hasText(
+ "9",
+ "direct mentions are still counted in Replies when disabled"
+ );
+ await click("#user-menu-button-replies");
+ assert.strictEqual(
+ filterByTypes,
+ "mentioned,group_mentioned,posted,quoted,replied",
+ "Replies retains direct mentions when the change is disabled"
+ );
+ });
+ test("replies exclude direct mentions from their filter, count and dismissal when enabled", async function (assert) {
+ this.currentUser.set("grouped_unread_notifications", {
+ [NOTIFICATION_TYPES.mentioned]: 2,
+ [NOTIFICATION_TYPES.group_mentioned]: 3,
+ [NOTIFICATION_TYPES.replied]: 4,
+ });
+ let filterByTypes;
+ let dismissTypes;
+ pretender.get("/notifications", (request) => {
+ filterByTypes = request.queryParams.filter_by_types;
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ {
+ notifications: [
+ NotificationFixtures["/notifications"].notifications[1],
+ ],
+ },
+ ];
+ });
+ pretender.put("/notifications/mark-read", (request) => {
+ dismissTypes = new URLSearchParams(request.requestBody).get(
+ "dismiss_types"
+ );
+ return [200, { "Content-Type": "application/json" }, { success: true }];
+ });
+
+ await render(<template><Menu /></template>);
+ assert
+ .dom("#user-menu-button-replies .badge-notification")
+ .hasText("7", "direct mentions are excluded from the Replies badge");
+ await click("#user-menu-button-replies");
+ assert.strictEqual(
+ filterByTypes,
+ "group_mentioned,posted,quoted,replied",
+ "Replies includes group mentions but not direct mentions"
+ );
+ await click(".user-menu .notifications-dismiss");
+ assert.strictEqual(
+ dismissTypes,
+ "group_mentioned,posted,quoted,replied",
+ "dismissing Replies excludes direct mentions"
+ );
+ assert
+ .dom("#user-menu-button-mentions .badge-notification")
+ .hasText("2", "direct mentions remain unread after dismissing Replies");
+ });
+
test("default tab is all notifications", async function (assert) {
await render(<template><Menu /></template>);
@@ -41,14 +132,19 @@ module("Integration | Component | UserMenu", function (hooks) {
this.currentUser.set("can_send_private_messages", true);
await render(<template><Menu /></template>);
const tabs = findAll(".top-tabs.tabs-list .btn");
- assert.strictEqual(tabs.length, 6);
- ["all-notifications", "replies", "likes", "messages", "bookmarks"].forEach(
- (tab, index) => {
- assert.strictEqual(tabs[index].id, `user-menu-button-${tab}`);
- assert.strictEqual(tabs[index].dataset.tabNumber, index.toString());
- assert.dom(tabs[index]).hasAria("controls", `quick-access-${tab}`);
- }
- );
+ assert.strictEqual(tabs.length, 7);
+ [
+ "all-notifications",
+ "replies",
+ "mentions",
+ "likes",
+ "messages",
+ "bookmarks",
+ ].forEach((tab, index) => {
+ assert.strictEqual(tabs[index].id, `user-menu-button-${tab}`);
+ assert.strictEqual(tabs[index].dataset.tabNumber, index.toString());
+ assert.dom(tabs[index]).hasAria("controls", `quick-access-${tab}`);
+ });
});
test("the menu has a group of tabs at the bottom", async function (assert) {
@@ -58,7 +154,7 @@ module("Integration | Component | UserMenu", function (hooks) {
assert.strictEqual(tabs.length, 1);
const profileTab = tabs[0];
assert.strictEqual(profileTab.id, "user-menu-button-profile");
- assert.strictEqual(profileTab.dataset.tabNumber, "6");
+ assert.strictEqual(profileTab.dataset.tabNumber, "7");
assert.dom(profileTab).hasAttribute("tabindex", "-1");
});
@@ -69,11 +165,11 @@ module("Integration | Component | UserMenu", function (hooks) {
assert.dom("#user-menu-button-likes").doesNotExist();
const tabs = findAll(".tabs-list .btn"); // top and bottom tabs
- assert.strictEqual(tabs.length, 6);
+ assert.strictEqual(tabs.length, 7);
assert.deepEqual(
tabs.map((t) => t.dataset.tabNumber),
- ["0", "1", "2", "3", "4", "5"],
+ ["0", "1", "2", "3", "4", "5", "6"],
"data-tab-number of the tabs has no gaps when the likes tab is hidden"
);
});
@@ -86,14 +182,14 @@ module("Integration | Component | UserMenu", function (hooks) {
assert
.dom("#user-menu-button-review-queue")
- .hasAttribute("data-tab-number", "5");
+ .hasAttribute("data-tab-number", "6");
const tabs = findAll(".tabs-list .btn"); // top and bottom tabs
- assert.strictEqual(tabs.length, 8);
+ assert.strictEqual(tabs.length, 9);
assert.deepEqual(
tabs.map((t) => t.dataset.tabNumber),
- ["0", "1", "2", "3", "4", "5", "6", "7"],
+ ["0", "1", "2", "3", "4", "5", "6", "7", "8"],
"data-tab-number of the tabs has no gaps when the reviewables tab is show"
);
});
@@ -116,11 +212,11 @@ module("Integration | Component | UserMenu", function (hooks) {
assert.dom("#user-menu-button-messages").doesNotExist();
const tabs = findAll(".tabs-list .btn"); // top and bottom tabs
- assert.strictEqual(tabs.length, 6);
+ assert.strictEqual(tabs.length, 7);
assert.deepEqual(
tabs.map((t) => t.dataset.tabNumber),
- ["0", "1", "2", "3", "4", "5"],
+ ["0", "1", "2", "3", "4", "5", "6"],
"data-tab-number of the tabs has no gaps when the messages tab is hidden"
);
});
@@ -224,14 +320,13 @@ module("Integration | Component | UserMenu", function (hooks) {
},
];
} else if (
- queryParams.filter_by_types ===
- "mentioned,group_mentioned,posted,quoted,replied"
+ queryParams.filter_by_types === "group_mentioned,posted,quoted,replied"
) {
data = [
{
id: 6,
user_id: 1,
- notification_type: NOTIFICATION_TYPES.mentioned,
+ notification_type: NOTIFICATION_TYPES.replied,
read: true,
high_priority: false,
created_at: "2021-11-25T19:31:13.241Z",
@@ -283,8 +378,8 @@ module("Integration | Component | UserMenu", function (hooks) {
assert.dom("#quick-access-replies.quick-access-panel").exists();
assert.strictEqual(
queryParams.filter_by_types,
- "mentioned,group_mentioned,posted,quoted,replied",
- "request params has filter_by_types set to `mentioned`, `posted`, `quoted` and `replied`"
+ "group_mentioned,posted,quoted,replied",
+ "request params include group mentions, posted, quoted and replied notifications"
);
assert.strictEqual(queryParams.silent, "true");
activeTabs = findAll(".top-tabs .btn.active");
@@ -307,6 +402,160 @@ module("Integration | Component | UserMenu", function (hooks) {
assert.dom("#quick-access-review-queue ul li").exists({ count: 8 });
});
+ test("mentions tab only requests direct mentions", async function (assert) {
+ let queryParams;
+ pretender.get("/notifications", (request) => {
+ queryParams = request.queryParams;
+ const types = queryParams.filter_by_types?.split(",");
+ const notifications = [
+ "mentioned",
+ "group_mentioned",
+ "replied",
+ "quoted",
+ ].map((type, index) => ({
+ ...NotificationFixtures["/notifications"].notifications[1],
+ id: 1000 + index,
+ notification_type: NOTIFICATION_TYPES[type],
+ }));
+ return [
+ 200,
+ { "Content-Type": "application/json" },
+ {
+ notifications: notifications.filter(
+ (n) =>
+ !types ||
+ types.some((t) => NOTIFICATION_TYPES[t] === n.notification_type)
+ ),
+ },
+ ];
+ });
+
+ await render(<template><Menu /></template>);
+ await click("#user-menu-button-mentions");
+
+ assert.strictEqual(
+ queryParams.filter_by_types,
+ "mentioned",
+ "only direct mentions are requested"
+ );
+ assert.strictEqual(
+ queryParams.silent,
+ "true",
+ "filtering does not mark other notifications seen"
+ );
+ assert
+ .dom("#quick-access-mentions ul")
+ .hasAria(
+ "labelledby",
+ "user-menu-button-mentions",
+ "the list is labelled by its tab"
+ );
+ assert
+ .dom("#quick-access-mentions li.notification")
+ .exists({ count: 1 }, "only the direct mention is rendered");
+ assert
+ .dom("#quick-access-mentions li.mentioned")
+ .exists("the direct mention is visible");
+ assert
+ .dom("#user-menu-button-mentions")
+ .hasAttribute(
+ "href",
+ "/u/eviltrout/notifications/mentions",
+ "the tab links to mention history"
+ );
+ });
+
+ test("mentions tab has a dedicated empty state", async function (assert) {
+ pretender.get("/notifications", () => [
+ 200,
+ { "Content-Type": "application/json" },
+ { notifications: [] },
+ ]);
+ await render(<template><Menu /></template>);
+ await click("#user-menu-button-mentions");
+
+ assert
+ .dom("#quick-access-mentions")
+ .includesText(
+ i18n("user.no_mentions_title"),
+ "the empty state describes missing mentions"
+ );
+ assert
+ .dom("#quick-access-mentions")
+ .includesText(
+ i18n("user.no_mentions_body"),
+ "the empty state explains direct mentions"
+ );
+ });
+
+ test("mentions badge counts only direct mentions and updates dynamically", async function (assert) {
+ this.currentUser.set("grouped_unread_notifications", {
+ [NOTIFICATION_TYPES.mentioned]: 2,
+ [NOTIFICATION_TYPES.group_mentioned]: 3,
+ [NOTIFICATION_TYPES.replied]: 4,
+ });
+ await render(<template><Menu /></template>);
+
+ assert
+ .dom("#user-menu-button-mentions .badge-notification")
+ .hasText("2", "the badge excludes group mentions and replies");
+ assert
+ .dom("#user-menu-button-mentions")
+ .hasAttribute(
+ "title",
+ i18n("user_menu.tabs.mentions_with_unread", { count: 2 }),
+ "the title includes the unread count"
+ );
+
+ this.currentUser.set("grouped_unread_notifications", {
+ [NOTIFICATION_TYPES.group_mentioned]: 3,
+ [NOTIFICATION_TYPES.replied]: 4,
+ });
+ await settled();
+
+ assert
+ .dom("#user-menu-button-mentions .badge-notification")
+ .doesNotExist("there is no badge without unread direct mentions");
+ assert
+ .dom("#user-menu-button-mentions")
+ .hasAttribute(
+ "title",
+ i18n("user_menu.tabs.mentions"),
+ "the title no longer includes an unread count"
+ );
+ });
+
+ test("dismissing mentions leaves other notification types unread", async function (assert) {
+ this.currentUser.set("grouped_unread_notifications", {
+ [NOTIFICATION_TYPES.mentioned]: 2,
+ [NOTIFICATION_TYPES.group_mentioned]: 3,
+ [NOTIFICATION_TYPES.replied]: 4,
+ });
+ let dismissTypes;
+ pretender.put("/notifications/mark-read", (request) => {
+ dismissTypes = new URLSearchParams(request.requestBody).get(
+ "dismiss_types"
+ );
+ return [200, { "Content-Type": "application/json" }, { success: true }];
+ });
+
+ await render(<template><Menu /></template>);
+ await click("#user-menu-button-mentions");
+ await click(".user-menu .notifications-dismiss");
+
+ assert.strictEqual(
+ dismissTypes,
+ "mentioned",
+ "only direct mentions are marked read"
+ );
+ assert
+ .dom("#user-menu-button-mentions .badge-notification")
+ .doesNotExist("the mentions badge is cleared");
+ assert
+ .dom("#user-menu-button-replies .badge-notification")
+ .hasText("7", "group mentions and replies remain unread");
+ });
+
test("count on the likes tab", async function (assert) {
this.currentUser.set("grouped_unread_notifications", {
[NOTIFICATION_TYPES.liked]: 1,
diff --git a/public/images/upcoming_changes/enable_user_menu_mentions_tab.png b/public/images/upcoming_changes/enable_user_menu_mentions_tab.png
new file mode 100644
index 00000000000..559bb290484
Binary files /dev/null and b/public/images/upcoming_changes/enable_user_menu_mentions_tab.png differ
diff --git a/spec/system/header_spec.rb b/spec/system/header_spec.rb
index 87b87399e89..d6851f56d3c 100644
--- a/spec/system/header_spec.rb
+++ b/spec/system/header_spec.rb
@@ -116,6 +116,8 @@ RSpec.describe "Glimmer Header" do
end
it "moves focus between tabs using arrow keys" do
+ SiteSetting.enable_user_menu_mentions_tab = true
+
sign_in(current_user)
visit "/"
find(".header-dropdown-toggle.current-user").click
@@ -124,6 +126,9 @@ RSpec.describe "Glimmer Header" do
find("##{header.active_element_id}").send_keys(:down)
expect(header.active_element_id).to eq("user-menu-button-replies")
+ find("##{header.active_element_id}").send_keys(:down)
+ expect(header.active_element_id).to eq("user-menu-button-mentions")
+
4.times { find("##{header.active_element_id}").send_keys(:down) }
expect(header.active_element_id).to eq("user-menu-button-profile")
diff --git a/spec/system/page_objects/components/user_menu.rb b/spec/system/page_objects/components/user_menu.rb
index 4677ce4f5ed..aa435522a5b 100644
--- a/spec/system/page_objects/components/user_menu.rb
+++ b/spec/system/page_objects/components/user_menu.rb
@@ -15,6 +15,12 @@ module PageObjects
self
end
+ def click_mentions_notifications_tab
+ click_link("user-menu-button-mentions")
+ has_css?("#quick-access-mentions")
+ self
+ end
+
def click_bookmarks_tab
click_link("user-menu-button-bookmarks")
has_css?("#quick-access-bookmarks")
@@ -95,6 +101,21 @@ module PageObjects
expect(find("#user-menu-button-replies").text).to eq(count.to_s)
end
+ def has_no_direct_mentions?
+ page.has_no_css?(".user-menu .notification.mentioned")
+ end
+
+ def has_no_mentions_notifications_tab?
+ page.has_no_css?("#user-menu-button-mentions")
+ end
+
+ def has_direct_mention_notification?(post)
+ page.has_css?(
+ "#quick-access-mentions .mentioned .item-description[data-topic-id='#{post.topic_id}']",
+ text: post.topic.title,
+ )
+ end
+
def has_notification_count_of?(count)
page.has_css?(".user-menu li.notification", count: count)
end
diff --git a/spec/system/viewing_user_menu_spec.rb b/spec/system/viewing_user_menu_spec.rb
index 96611817a2c..1e8e4ab5f77 100644
--- a/spec/system/viewing_user_menu_spec.rb
+++ b/spec/system/viewing_user_menu_spec.rb
@@ -5,6 +5,55 @@ RSpec.describe "Viewing User Menu" do
let(:user_menu) { PageObjects::Components::UserMenu.new }
+ it "keeps the mentions tab hidden when the upcoming change is disabled" do
+ SiteSetting.enable_user_menu_mentions_tab = false
+
+ sign_in(user)
+ visit("/latest")
+ user_menu.open
+
+ expect(user_menu).to have_no_mentions_notifications_tab
+ end
+
+ it "lets the user filter direct mentions and visit the mentioned post" do
+ SiteSetting.enable_user_menu_mentions_tab = true
+ Jobs.run_immediately!
+
+ mentioned_post =
+ PostCreator.create!(
+ Fabricate(:user),
+ topic_id: Fabricate(:post).topic_id,
+ raw: "Hello @#{user.username}, what do you think about this?",
+ )
+ Fabricate(:replied_notification, user: user, post: Fabricate(:post))
+ Fabricate(
+ :group_mentioned_notification,
+ user: user,
+ post: Fabricate(:post),
+ group: Fabricate(:group),
+ )
+
+ sign_in(user)
+ visit("/latest")
+ user_menu.open
+
+ expect(user_menu).to have_notification_count_of(3)
+
+ user_menu.click_replies_notifications_tab
+
+ expect(user_menu).to have_notification_count_of(2)
+ expect(user_menu).to have_no_direct_mentions
+
+ user_menu.click_mentions_notifications_tab
+
+ expect(user_menu).to have_direct_mention_notification(mentioned_post)
+ expect(user_menu).to have_notification_count_of(1)
+
+ user_menu.click_notification_with_href(mentioned_post.url)
+
+ expect(page).to have_current_path(mentioned_post.url)
+ end
+
describe "with notification limit set via plugin api" do
it "only displays as many notifications as the limit" do
sign_in(user)
@@ -65,6 +114,8 @@ RSpec.describe "Viewing User Menu" do
describe "when viewing replies notifications tab" do
fab!(:topic)
+ before { SiteSetting.enable_user_menu_mentions_tab = false }
+
it "shows group-mention notifications in the tab" do
Jobs.run_immediately!