discourse/plugins/chat/test/javascripts/acceptance/chat-sidebar-user-status-test.js
Martin Brennan 8437081d94
FIX: Add MessageBust.last_id to chat channel subscriptions (#19255)
This commit adds variousMessageBus.last_ids to serializer payloads
for chat channels and the chat view (for chat live pane) so
we can use those IDs when subscribing to MessageBus channels
from chat.

This allows us to ensure that any messages created between the
server being hit and the UI loaded and subscribing end up being
delivered to the client, rather than just silently dropped.

This commit also fixes an issue where we were subscribing to
the new-messages and new-mentions MessageBus channels multiple
times when following/unfollowing a channel multiple times.
2022-12-02 10:57:53 +10:00

129 lines
3.3 KiB
JavaScript

import {
acceptance,
exists,
publishToMessageBus,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
acceptance("Discourse Chat - Sidebar - User Status", function (needs) {
const directMessageUserId = 1;
const status = { description: "off to dentist", emoji: "tooth" };
needs.user({ has_chat_enabled: true });
needs.settings({
chat_enabled: true,
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
});
needs.pretender((server, helper) => {
const directMessageChannel = {
chatable: {
users: [
{
id: directMessageUserId,
username: "user1",
avatar_template:
"/letter_avatar_proxy/v4/letter/t/f9ae1b/{size}.png",
status,
},
],
},
chatable_type: "DirectMessage",
title: "@user1",
message_bus_last_ids: {
new_mentions: 0,
new_messages: 0,
},
};
server.get("/chat/chat_channels.json", () => {
return helper.response({
public_channels: [],
direct_message_channels: [directMessageChannel],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
});
test("Shows user status", async function (assert) {
await visit("/");
const statusEmoji = query(
".sidebar-sections .sidebar-section-link-content-text .emoji"
);
assert.ok(statusEmoji, "status is shown");
assert.ok(
statusEmoji.src.includes(status.emoji),
"status emoji is correct"
);
assert.equal(
statusEmoji.title,
status.description,
"status description is correct"
);
});
test("Status gets updated after receiving a message bus update", async function (assert) {
await visit("/");
let statusEmoji = query(
".sidebar-sections .sidebar-section-link-content-text .emoji"
);
assert.ok(statusEmoji, "old status is shown");
assert.ok(
statusEmoji.src.includes(status.emoji),
"old status emoji is correct"
);
assert.equal(
statusEmoji.title,
status.description,
"old status description is correct"
);
const newStatus = { description: "surfing", emoji: "surfer" };
await publishToMessageBus(`/user-status`, {
[directMessageUserId]: newStatus,
});
statusEmoji = query(
".sidebar-sections .sidebar-section-link-content-text .emoji"
);
assert.ok(statusEmoji, "new status is shown");
assert.ok(
statusEmoji.src.includes(newStatus.emoji),
"new status emoji is correct"
);
assert.equal(
statusEmoji.title,
newStatus.description,
"new status description is correct"
);
});
test("Status disappears after receiving a message bus update", async function (assert) {
await visit("/");
let statusEmoji = query(
".sidebar-sections .sidebar-section-link-content-text .emoji"
);
assert.ok(statusEmoji, "old status is shown");
await publishToMessageBus(`/user-status`, { [directMessageUserId]: null });
assert.notOk(
exists(".sidebar-sections .sidebar-section-link-content-text .emoji"),
"status has disappeared"
);
});
});