Skip to content

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

FIX: regression causing missing indicator in sidebar (#36447)

Keegan George5660b303e8c4
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-sidebar-indicators.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-sidebar-indicators.gjs
index ac0233b832d..624225938b9 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-sidebar-indicators.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-sidebar-indicators.gjs
@@ -16,14 +16,16 @@ import icon from "discourse/helpers/d-icon";
*/
export default class ChatSidebarIndicators extends Component {
/**
- * Determines if the channel has any unread content (messages or threads).
+ * Determines if the channel has any unread content (messages, threads, mentions, or watched threads).
*
- * @returns {boolean} True if there are unread messages or threads
+ * @returns {boolean} True if there are any unreads that should show an indicator
*/
get hasUnread() {
return (
this.args.status?.unreadCount > 0 ||
- this.args.status?.unreadThreadsCount > 0
+ this.args.status?.unreadThreadsCount > 0 ||
+ this.args.status?.mentionCount > 0 ||
+ this.args.status?.watchedThreadsUnreadCount > 0
);
}
diff --git a/plugins/chat/test/javascripts/components/chat-sidebar-indicators-test.gjs b/plugins/chat/test/javascripts/components/chat-sidebar-indicators-test.gjs
new file mode 100644
index 00000000000..fca85f00fa9
--- /dev/null
+++ b/plugins/chat/test/javascripts/components/chat-sidebar-indicators-test.gjs
@@ -0,0 +1,111 @@
+import { render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import ChatSidebarIndicators from "discourse/plugins/chat/discourse/components/chat-sidebar-indicators";
+
+module(
+ "Discourse Chat | Component | chat-sidebar-indicators",
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("shows indicator when unreadCount > 0", async function (assert) {
+ const status = { unreadCount: 1 };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").exists();
+ });
+
+ test("shows indicator when unreadThreadsCount > 0", async function (assert) {
+ const status = { unreadThreadsCount: 1 };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").exists();
+ });
+
+ test("shows indicator when mentionCount > 0", async function (assert) {
+ const status = { mentionCount: 1 };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").exists();
+ assert.dom(".sidebar-section-link-content-badge").hasClass("urgent");
+ });
+
+ test("shows indicator when watchedThreadsUnreadCount > 0", async function (assert) {
+ const status = { watchedThreadsUnreadCount: 1 };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").exists();
+ assert.dom(".sidebar-section-link-content-badge").hasClass("urgent");
+ });
+
+ test("does not show indicator when all counts are 0", async function (assert) {
+ const status = {
+ unreadCount: 0,
+ unreadThreadsCount: 0,
+ mentionCount: 0,
+ watchedThreadsUnreadCount: 0,
+ };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").doesNotExist();
+ });
+
+ test("shows urgent class for DM with unread messages", async function (assert) {
+ const status = {
+ unreadCount: 1,
+ isDirectMessageChannel: true,
+ };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").hasClass("urgent");
+ });
+
+ test("shows unread class for public channel with unread messages", async function (assert) {
+ const status = {
+ unreadCount: 1,
+ isDirectMessageChannel: false,
+ };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").hasClass("unread");
+ });
+
+ test("shows urgent class when watchedThreadsUnreadCount > 0 even without other unreads", async function (assert) {
+ const status = {
+ unreadCount: 0,
+ unreadThreadsCount: 0,
+ mentionCount: 0,
+ watchedThreadsUnreadCount: 1,
+ isDirectMessageChannel: false,
+ };
+
+ await render(
+ <template><ChatSidebarIndicators @status={{status}} /></template>
+ );
+
+ assert.dom(".sidebar-section-link-content-badge").exists();
+ assert.dom(".sidebar-section-link-content-badge").hasClass("urgent");
+ });
+ }
+);