discourse/plugins/chat/test/javascripts/acceptance/chat-channels-list-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

64 lines
1.7 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 {
acceptance,
exists,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
import { directMessageChannels } from "discourse/plugins/chat/chat-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
acceptance(
"Discourse Chat - Chat Channels list - no joinable public channels",
function (needs) {
needs.user({ has_chat_enabled: true, has_joinable_public_channels: false });
needs.settings({
chat_enabled: true,
enable_sidebar: false,
enable_experimental_sidebar_hamburger: false,
});
needs.pretender((server, helper) => {
server.get("/chat/chat_channels.json", () => {
return helper.response({
public_channels: [],
direct_message_channels: cloneJSON(directMessageChannels).mapBy(
"chat_channel"
),
message_bus_last_ids: {
channel_metadata: 0,
channel_edits: 0,
channel_status: 0,
new_channel: 0,
user_tracking_state: 0,
},
});
});
server.get("/chat/:id/messages.json", () => {
return helper.response({
chat_messages: [],
meta: { can_chat: true },
});
});
});
test("Public chat channels section visibility", async function (assert) {
await visit("/chat");
assert.ok(
exists(".public-channels-section"),
"it shows the section for staff"
);
updateCurrentUser({ admin: false, moderator: false });
assert.notOk(
exists(".public-channels-section"),
"it doesnt show the section for regular user"
);
});
}
);