2023-10-11 02:38:59 +08:00
|
|
|
import { render } from "@ember/test-helpers";
|
2022-11-02 21:41:30 +08:00
|
|
|
import hbs from "htmlbars-inline-precompile";
|
2022-12-22 21:35:18 +08:00
|
|
|
import { module, test } from "qunit";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 21:19:52 +08:00
|
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from 'discourse-i18n';
|
2023-10-11 02:38:59 +08:00
|
|
|
import ChatChannel from "discourse/plugins/chat/discourse/models/chat-channel";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Component | chat-composer placeholder",
|
|
|
|
function (hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("direct message to self shows Jot something down", async function (assert) {
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 21:19:52 +08:00
|
|
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
this.currentUser.set("id", 1);
|
2023-04-25 16:23:03 +08:00
|
|
|
this.channel = ChatChannel.create({
|
|
|
|
chatable_type: "DirectMessage",
|
|
|
|
chatable: {
|
|
|
|
users: [{ id: 1 }],
|
|
|
|
},
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
await render(hbs`<Chat::Composer::Channel @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
2023-04-25 16:23:03 +08:00
|
|
|
query(".chat-composer__input").placeholder,
|
2022-12-22 21:35:18 +08:00
|
|
|
"Jot something down"
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2024-09-04 13:52:23 +08:00
|
|
|
test("direct message to multiple folks shows their names when not a group", async function (assert) {
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 21:19:52 +08:00
|
|
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
this.channel = ChatChannel.create({
|
|
|
|
chatable_type: "DirectMessage",
|
|
|
|
chatable: {
|
2024-09-04 13:52:23 +08:00
|
|
|
group: false,
|
2023-04-25 16:23:03 +08:00
|
|
|
users: [
|
|
|
|
{ name: "Tomtom" },
|
|
|
|
{ name: "Steaky" },
|
|
|
|
{ username: "zorro" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
await render(hbs`<Chat::Composer::Channel @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
2023-04-25 16:23:03 +08:00
|
|
|
query(".chat-composer__input").placeholder,
|
2022-12-22 21:35:18 +08:00
|
|
|
"Chat with Tomtom, Steaky, @zorro"
|
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
2024-09-04 13:52:23 +08:00
|
|
|
test("direct message to group shows Chat in group", async function (assert) {
|
|
|
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
|
|
|
|
|
|
|
this.channel = ChatChannel.create({
|
|
|
|
chatable_type: "DirectMessage",
|
|
|
|
title: "Meetup Chat",
|
|
|
|
chatable: {
|
|
|
|
group: true,
|
|
|
|
users: [
|
|
|
|
{ username: "user1" },
|
|
|
|
{ username: "user2" },
|
|
|
|
{ username: "user3" },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
await render(hbs`<Chat::Composer::Channel @channel={{this.channel}} />`);
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".chat-composer__input").placeholder,
|
2024-11-20 04:45:18 +08:00
|
|
|
i18n("chat.placeholder_group")
|
2024-09-04 13:52:23 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
test("message to channel shows send message to channel name", async function (assert) {
|
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.
There are now several new classes and concepts:
* ChatMessageInteractor - This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.
The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.
This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 21:19:52 +08:00
|
|
|
pretender.get("/chat/emojis.json", () => [200, [], {}]);
|
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
this.channel = ChatChannel.create({
|
|
|
|
chatable_type: "Category",
|
|
|
|
title: "just-cats",
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-04-25 16:23:03 +08:00
|
|
|
await render(hbs`<Chat::Composer::Channel @channel={{this.channel}} />`);
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2022-12-22 21:35:18 +08:00
|
|
|
assert.strictEqual(
|
2023-04-25 16:23:03 +08:00
|
|
|
query(".chat-composer__input").placeholder,
|
|
|
|
"Chat in #just-cats"
|
2022-12-22 21:35:18 +08:00
|
|
|
);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|