discourse/plugins/chat/test/javascripts/acceptance/chat-live-pane-mobile-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

94 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { click, visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
acceptance("Discourse Chat - Chat live pane mobile", function (needs) {
needs.mobileView();
needs.user({
username: "eviltrout",
id: 1,
can_chat: true,
has_chat_enabled: true,
});
needs.settings({
chat_enabled: true,
});
needs.pretender((server, helper) => {
server.get("/chat/:chatChannelId/messages.json", () =>
helper.response({
meta: {
can_flag: true,
user_silenced: true,
},
chat_messages: [
{
id: 1,
message: "hi",
cooked: "<p>hi</p>",
excerpt: "hi",
created_at: "2021-07-20T08:14:16.950Z",
flag_count: 0,
user: {
avatar_template:
"/letter_avatar_proxy/v4/letter/t/a9a28c/{size}.png",
id: 1,
name: "Tomtom",
username: "tomtom",
},
},
{
id: 2,
message: "hi",
cooked: "<p>hi</p>",
excerpt: "hi",
created_at: "2021-07-20T08:14:16.950Z",
flag_count: 0,
user: {
avatar_template:
"/letter_avatar_proxy/v4/letter/t/a9a28c/{size}.png",
id: 1,
name: "Tomtom",
username: "tomtom",
},
},
],
})
);
server.get("/chat/chat_channels.json", () =>
helper.response({
public_channels: [],
direct_message_channels: [],
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
})
);
server.get("/chat/chat_channels/:chatChannelId", () =>
helper.response({ id: 1, title: "something" })
);
});
test("touching message", async function (assert) {
await visit("/chat/channel/1/cat");
const messageExists = (id) => {
return exists(
`.chat-message-container[data-id='${id}'] .chat-message-selected`
);
};
assert.notOk(messageExists(1));
assert.notOk(messageExists(2));
await click(".chat-message-container[data-id='1']");
assert.notOk(messageExists(1), "it doesnt select the touched message");
});
});