mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 03:23:37 +08:00
ea548292bc
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>
117 lines
3.2 KiB
JavaScript
117 lines
3.2 KiB
JavaScript
import { module, test } from "qunit";
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
|
import pretender from "discourse/tests/helpers/create-pretender";
|
|
import { settled } from "@ember/test-helpers";
|
|
|
|
function emojisReponse() {
|
|
return { favorites: [{ name: "sad" }] };
|
|
}
|
|
|
|
module(
|
|
"Discourse Chat | Unit | Service | chat-emoji-picker-manager",
|
|
function (hooks) {
|
|
hooks.beforeEach(function () {
|
|
pretender.get("/chat/emojis.json", () => {
|
|
return [200, {}, emojisReponse()];
|
|
});
|
|
|
|
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, []);
|
|
|
|
this.manager.open({});
|
|
|
|
assert.deepEqual(this.manager.sections, []);
|
|
|
|
await settled();
|
|
|
|
assert.deepEqual(this.manager.sections, ["favorites"]);
|
|
});
|
|
|
|
test("open", async function (assert) {
|
|
this.manager.open({ context: "chat-composer" });
|
|
|
|
assert.ok(this.manager.loading);
|
|
assert.ok(this.manager.picker);
|
|
assert.strictEqual(this.manager.picker.context, "chat-composer");
|
|
assert.deepEqual(this.manager.visibleSections, [
|
|
"favorites",
|
|
"smileys_&_emotion",
|
|
]);
|
|
assert.strictEqual(this.manager.lastVisibleSection, "favorites");
|
|
|
|
await settled();
|
|
|
|
assert.deepEqual(this.manager.emojis, emojisReponse());
|
|
assert.strictEqual(this.manager.loading, false);
|
|
});
|
|
|
|
test("closeExisting", async function (assert) {
|
|
this.manager.open({ context: "channel-composer", trigger: "foo" });
|
|
this.manager.addVisibleSections("objects");
|
|
this.manager.lastVisibleSection = "objects";
|
|
this.manager.open({ context: "thread-composer", trigger: "bar" });
|
|
|
|
assert.strictEqual(
|
|
this.manager.picker.context,
|
|
"thread-composer",
|
|
"it resets the picker to latest picker"
|
|
);
|
|
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) {
|
|
this.manager.open({ context: "channel-composer" });
|
|
|
|
assert.ok(this.manager.picker);
|
|
|
|
this.manager.addVisibleSections("objects");
|
|
this.manager.lastVisibleSection = "objects";
|
|
this.manager.close();
|
|
|
|
assert.ok(this.manager.closing);
|
|
assert.ok(this.manager.picker);
|
|
|
|
await settled();
|
|
|
|
assert.notOk(this.manager.picker);
|
|
assert.notOk(this.manager.closing);
|
|
assert.deepEqual(
|
|
this.manager.visibleSections,
|
|
["favorites", "smileys_&_emotion"],
|
|
"it resets visible sections"
|
|
);
|
|
assert.strictEqual(
|
|
this.manager.lastVisibleSection,
|
|
"favorites",
|
|
"it resets last visible section"
|
|
);
|
|
});
|
|
}
|
|
);
|