Files
discourse/plugins/chat/test/javascripts/unit/lib/chat-message-interactor-test.js
Joffrey JAFFEUX 4c8420833e FEATURE: One-click chat reaction settings (#32150)
Adds a one-click chat reactions setting to the chat preferences page
where members can determine what one-click reactions are shown in chat.

- Frequent: This will be the default setting. (Automatically set based
on most used chat reactions)
- Custom: Members can choose up to three reactions they want to see in
their one-click chat/DM reactions menu. Defaults are `❤️`, `👍` ,
and `😄`.


![image](https://github.com/user-attachments/assets/8913db0e-d6ec-4347-ad91-2329206b127c)

This pull request is essentially the work of @dsims in
https://github.com/discourse/discourse/pull/31761

---------

Co-authored-by: dsims <1041068+dsims@users.noreply.github.com>
2025-04-04 09:15:13 +02:00

123 lines
3.8 KiB
JavaScript

import { getOwner } from "@ember/owner";
import { setupTest } from "ember-qunit";
import { module, test } from "qunit";
import {
logIn,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import ChatMessageInteractor from "discourse/plugins/chat/discourse/lib/chat-message-interactor";
import ChatFabricators from "discourse/plugins/chat/discourse/lib/fabricators";
module("Discourse Chat | Unit | chat-message-interactor", function (hooks) {
setupTest(hooks);
hooks.beforeEach(function () {
logIn(getOwner(this));
const message = new ChatFabricators(getOwner(this)).message();
this.messageInteractor = new ChatMessageInteractor(getOwner(this), message);
this.emojiStore = getOwner(this).lookup("service:emoji-store");
this.siteSettings = getOwner(this).lookup("service:site-settings");
});
test("emojiReactions with no option uses site default", function (assert) {
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["+1", "heart", "tada"]
);
});
test("emojiReactions empty when no frequent or site defaults", function (assert) {
this.siteSettings.default_emoji_reactions = "";
assert.deepEqual(this.messageInteractor.emojiReactions, []);
});
test("emojiReactions with user option frequent falls back to site defaults", function (assert) {
updateCurrentUser({
user_option: {
chat_quick_reaction_type: "frequent",
},
});
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["+1", "heart", "tada"]
);
});
test("emojiReactions with top 3 frequent", function (assert) {
this.emojiStore.trackEmojiForContext("eyes", "chat");
this.emojiStore.trackEmojiForContext("camera", "chat");
this.emojiStore.trackEmojiForContext("butterfly", "chat");
this.emojiStore.trackEmojiForContext("butterfly", "chat");
this.emojiStore.trackEmojiForContext("laptop", "chat");
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["butterfly", "laptop", "camera"]
);
});
test("emojiReactions with 1 frequent falls back to system", function (assert) {
this.emojiStore.trackEmojiForContext("butterfly", "chat");
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["butterfly", "+1", "heart"]
);
});
test("emojiReactions uses custom user option", function (assert) {
updateCurrentUser({
user_option: {
chat_quick_reaction_type: "custom",
chat_quick_reactions_custom: "grin|fearful|angry",
},
});
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["grin", "fearful", "angry"]
);
});
test("emojiReactions does not use custom if set to frequent", function (assert) {
updateCurrentUser({
user_option: {
chat_quick_reaction_type: "frequent",
chat_quick_reactions_custom: "grin|fearful|angry",
},
});
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["+1", "heart", "tada"]
);
});
test("emojiReactions avoids duplicates from frequent and site", function (assert) {
this.emojiStore.trackEmojiForContext("+1", "chat");
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["+1", "heart", "tada"]
);
});
test("emojiReactions avoids duplicates from custom + frequent + site", function (assert) {
updateCurrentUser({
user_option: {
chat_quick_reaction_type: "custom",
chat_quick_reactions_custom: "+1|+1|+1",
},
});
this.emojiStore.trackEmojiForContext("+1", "chat");
this.emojiStore.trackEmojiForContext("butterfly", "chat");
assert.deepEqual(
this.messageInteractor.emojiReactions.map((r) => r.emoji),
["+1", "butterfly", "heart"]
);
});
});