2024-07-25 21:09:06 +08:00
|
|
|
import { getOwner } from "@ember/owner";
|
2022-11-02 21:41:30 +08:00
|
|
|
import { settled } from "@ember/test-helpers";
|
2023-09-27 01:05:34 +08:00
|
|
|
import { setupTest } from "ember-qunit";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2023-11-20 23:49:49 +08:00
|
|
|
function emojisResponse() {
|
2022-11-02 21:41:30 +08:00
|
|
|
return { favorites: [{ name: "sad" }] };
|
|
|
|
}
|
|
|
|
|
|
|
|
module(
|
|
|
|
"Discourse Chat | Unit | Service | chat-emoji-picker-manager",
|
|
|
|
function (hooks) {
|
2023-09-27 01:05:34 +08:00
|
|
|
setupTest(hooks);
|
|
|
|
|
2022-11-02 21:41:30 +08:00
|
|
|
hooks.beforeEach(function () {
|
|
|
|
pretender.get("/chat/emojis.json", () => {
|
2023-11-20 23:49:49 +08:00
|
|
|
return [200, {}, emojisResponse()];
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
this.manager = getOwner(this).lookup("service:chat-emoji-picker-manager");
|
|
|
|
});
|
|
|
|
|
|
|
|
hooks.afterEach(function () {
|
|
|
|
this.manager.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("addVisibleSections", async function (assert) {
|
|
|
|
this.manager.addVisibleSections(["favorites", "objects"]);
|
|
|
|
|
|
|
|
assert.deepEqual(this.manager.visibleSections, [
|
|
|
|
"favorites",
|
|
|
|
"smileys_&_emotion",
|
|
|
|
"objects",
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("sections", async function (assert) {
|
|
|
|
assert.deepEqual(this.manager.sections, []);
|
|
|
|
|
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
|
|
|
this.manager.open({});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
assert.deepEqual(this.manager.sections, []);
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
assert.deepEqual(this.manager.sections, ["favorites"]);
|
|
|
|
});
|
|
|
|
|
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
|
|
|
test("open", async function (assert) {
|
|
|
|
this.manager.open({ context: "chat-composer" });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.manager.loading);
|
|
|
|
assert.deepEqual(this.manager.picker, {
|
|
|
|
context: "chat-composer",
|
|
|
|
});
|
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
|
|
|
assert.strictEqual(this.manager.picker.context, "chat-composer");
|
2022-11-02 21:41:30 +08:00
|
|
|
assert.deepEqual(this.manager.visibleSections, [
|
|
|
|
"favorites",
|
|
|
|
"smileys_&_emotion",
|
|
|
|
]);
|
|
|
|
assert.strictEqual(this.manager.lastVisibleSection, "favorites");
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
2023-11-20 23:49:49 +08:00
|
|
|
assert.deepEqual(this.manager.emojis, emojisResponse());
|
2024-11-27 20:02:55 +08:00
|
|
|
assert.false(this.manager.loading);
|
2022-11-02 21:41:30 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("closeExisting", 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
|
|
|
this.manager.open({ context: "channel-composer", trigger: "foo" });
|
2022-11-02 21:41:30 +08:00
|
|
|
this.manager.addVisibleSections("objects");
|
|
|
|
this.manager.lastVisibleSection = "objects";
|
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
|
|
|
this.manager.open({ context: "thread-composer", trigger: "bar" });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
assert.strictEqual(
|
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
|
|
|
this.manager.picker.context,
|
|
|
|
"thread-composer",
|
|
|
|
"it resets the picker to latest picker"
|
2022-11-02 21:41:30 +08:00
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
this.manager.visibleSections,
|
|
|
|
["favorites", "smileys_&_emotion"],
|
|
|
|
"it resets sections"
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
this.manager.lastVisibleSection,
|
|
|
|
"favorites",
|
|
|
|
"it resets last visible section"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("close", 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
|
|
|
this.manager.open({ context: "channel-composer" });
|
2022-11-02 21:41:30 +08:00
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.deepEqual(this.manager.picker, {
|
|
|
|
context: "channel-composer",
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
this.manager.addVisibleSections("objects");
|
|
|
|
this.manager.lastVisibleSection = "objects";
|
|
|
|
this.manager.close();
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
assert.true(this.manager.closing);
|
|
|
|
assert.deepEqual(this.manager.picker, {
|
|
|
|
context: "channel-composer",
|
|
|
|
});
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
2024-11-04 17:27:30 +08:00
|
|
|
assert.strictEqual(this.manager.picker, null);
|
|
|
|
assert.false(this.manager.closing);
|
2022-11-02 21:41:30 +08:00
|
|
|
assert.deepEqual(
|
|
|
|
this.manager.visibleSections,
|
|
|
|
["favorites", "smileys_&_emotion"],
|
|
|
|
"it resets visible sections"
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
this.manager.lastVisibleSection,
|
|
|
|
"favorites",
|
|
|
|
"it resets last visible section"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|