0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/chat/test/javascripts/acceptance/chat-disabled-test.js
Régis Hanol 87f9d907ab
FIX: Handle a member disabling chat in their preferences (#41805)
Previously, a member who turned chat off in their preferences saw their
existing chat notifications render as blank rows, and any chat link
silently bounced them to the homepage.

This change registers the chat notification renderers whenever chat is
enabled site-wide so those notifications still render correctly, and
sends chat links to a new "chat is disabled" page that explains how to
turn it back on.

**BEFORE**

(the notification are "blank")

<img width="1400" height="1200" alt="before-notifications"
src="https://github.com/user-attachments/assets/d8dcef2e-98eb-4b30-bf33-4a1f8c2c4626"
/>

**AFTER**

(the notification are there)

<img width="1400" height="1200" alt="after-notifications"
src="https://github.com/user-attachments/assets/72b17123-8f82-4c5e-a74d-7d5347de623a"
/>

(the "blank slate" page that is displayed when you click a #chat
notification after you've disabled #chat in your preferences)

<img width="1400" height="1200" alt="after-disabled-page"
src="https://github.com/user-attachments/assets/1905ecb5-7b8c-4682-87a9-1559ca4ec569"
/>
2026-07-17 16:21:12 +02:00

80 lines
2.2 KiB
JavaScript
Vendored

import {
click,
currentRouteName,
currentURL,
visit,
} from "@ember/test-helpers";
import { test } from "qunit";
import { NOTIFICATION_TYPES } from "discourse/tests/fixtures/concerns/notification-types";
import {
acceptance,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { i18n } from "discourse-i18n";
acceptance("Chat | Disabled in preferences", function (needs) {
needs.user();
needs.settings({ chat_enabled: true });
needs.pretender((server, helper) => {
server.get("/notifications", () =>
helper.response({
notifications: [
{
id: 1,
user_id: 1,
notification_type: NOTIFICATION_TYPES.chat_invitation,
read: false,
high_priority: true,
created_at: "2026-01-01T00:00:00.000Z",
data: {
chat_channel_id: 9,
chat_channel_title: "Design",
chat_channel_slug: "design",
invited_by_username: "alice",
chat_message_id: 5,
},
},
],
total_rows_notifications: 1,
seen_notification_id: 0,
})
);
});
test("shows an empty state instead of redirecting to the homepage", async function (assert) {
updateCurrentUser({ can_chat: true, has_chat_enabled: false });
await visit("/chat/c/design/9/5");
assert.strictEqual(
currentRouteName(),
"chat.disabled",
"lands on the chat disabled route rather than bouncing home"
);
assert
.dom(".chat-disabled .empty-state__title")
.hasText(i18n("chat.disabled.title"));
assert
.dom(".chat-disabled .empty-state__cta a")
.hasAttribute(
"href",
/\/my\/preferences\/chat$/,
"the call to action links to chat preferences"
);
});
test("clicking a chat notification lands on the disabled page", async function (assert) {
updateCurrentUser({ can_chat: true, has_chat_enabled: false });
await visit("/");
await click("#toggle-current-user");
await click(".user-menu .notification.chat-invitation a");
assert.strictEqual(
currentURL(),
"/chat/disabled",
"clicking the chat notification lands on the disabled page"
);
});
});