Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Allow choosing custom emoji in reaction (#34312)

fokxf002aa4022f6
diff --git a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb
index 45cfc086cc2..05a2725aece 100644
--- a/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb
+++ b/plugins/discourse-reactions/app/controllers/discourse_reactions/custom_reactions_controller.rb
@@ -9,10 +9,16 @@ class DiscourseReactions::CustomReactionsController < ApplicationController
def toggle
post = fetch_post_from_params
+ reaction = params[:reaction]
- if DiscourseReactions::Reaction.valid_reactions.exclude?(params[:reaction])
- return render_json_error(post)
- end
+ invalid_reaction =
+ if SiteSetting.discourse_reactions_experimental_allow_any_emoji
+ !Emoji.exists?(reaction)
+ else
+ DiscourseReactions::Reaction.valid_reactions.exclude?(params[:reaction])
+ end
+
+ return render_json_error(post) if invalid_reaction
begin
manager =
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
index f8532621f0a..b413bc7715b 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-actions.gjs
@@ -120,6 +120,7 @@ export default class DiscourseReactionsActions extends Component {
@tracked reactionsPickerExpanded = false;
@tracked statePanelExpanded = false;
+ @tracked clickOutsideDisabled = false;
get classes() {
const { post } = this.args;
@@ -294,43 +295,58 @@ export default class DiscourseReactionsActions extends Component {
const scales = [1.0, 1.75];
return new Promise((resolve) => {
- scaleReactionAnimation(pickedReaction, scales[0], scales[1], () => {
- scaleReactionAnimation(pickedReaction, scales[1], scales[0], () => {
- const post = this.args.post;
- const postContainer = document.querySelector(
- `[data-post-id="${params.postId}"]`
- );
-
- if (
- post.current_user_reaction &&
- post.current_user_reaction.id === params.reaction
- ) {
- this.toggleReaction(params);
-
- later(() => {
- dropReaction(postContainer, params.reaction, () => {
- return CustomReaction.toggle(this.args.post, params.reaction)
+ if (!pickedReaction) {
+ this.toggleReaction(params);
+ const post = this.args.post;
+
+ CustomReaction.toggle(post, params.reaction)
+ .then(resolve)
+ .catch((err) => {
+ this.dialog.alert(this._extractErrors(err));
+ this._rollbackState(post);
+ });
+ } else {
+ scaleReactionAnimation(pickedReaction, scales[0], scales[1], () => {
+ scaleReactionAnimation(pickedReaction, scales[1], scales[0], () => {
+ const post = this.args.post;
+ const postContainer = document.querySelector(
+ `[data-post-id="${params.postId}"]`
+ );
+
+ if (
+ post.current_user_reaction &&
+ post.current_user_reaction.id === params.reaction
+ ) {
+ this.toggleReaction(params);
+
+ later(() => {
+ dropReaction(postContainer, params.reaction, () => {
+ return CustomReaction.toggle(
+ this.args.post,
+ params.reaction
+ )
+ .then(resolve)
+ .catch((err) => {
+ this.dialog.alert(this._extractErrors(err));
+ this._rollbackState(post);
+ });
+ });
+ }, 100);
+ } else {
+ addReaction(postContainer, params.reaction, () => {
+ this.toggleReaction(params);
+
+ CustomReaction.toggle(this.args.post, params.reaction)
.then(resolve)
- .catch((e) => {
- this.dialog.alert(this._extractErrors(e));
+ .catch((err) => {
+ this.dialog.alert(this._extractErrors(err));
this._rollbackState(post);
});
});
- }, 100);
- } else {
- addReaction(postContainer, params.reaction, () => {
- this.toggleReaction(params);
-
- CustomReaction.toggle(this.args.post, params.reaction)
- .then(resolve)
- .catch((e) => {
- this.dialog.alert(this._extractErrors(e));
- this._rollbackState(post);
- });
- });
- }
+ }
+ });
});
- });
+ }
}).finally(() => {
this.collapseAllPanels();
});
@@ -441,7 +457,6 @@ export default class DiscourseReactionsActions extends Component {
} else {
post.current_user_used_main_reaction = false;
}
-
// Trigger re-render for anything autotracking reactions.
// In future, we should make reactions a deeply-trackable structure.
// eslint-disable-next-line no-self-assign
@@ -525,8 +540,8 @@ export default class DiscourseReactionsActions extends Component {
CustomReaction.toggle(this.args.post, toggleReaction)
.then(resolve)
- .catch((e) => {
- this.dialog.alert(this._extractErrors(e));
+ .catch((err) => {
+ this.dialog.alert(this._extractErrors(err));
this._rollbackState(post);
});
});
@@ -539,6 +554,16 @@ export default class DiscourseReactionsActions extends Component {
cancel(this._collapseHandler);
}
+ @action
+ disableClickOutside() {
+ this.clickOutsideDisabled = true;
+ }
+
+ @action
+ enableClickOutside() {
+ this.clickOutsideDisabled = false;
+ }
+
@action
cancelExpand() {
cancel(this._expandHandler);
@@ -565,6 +590,9 @@ export default class DiscourseReactionsActions extends Component {
@action
clickOutside() {
+ if (this.clickOutsideDisabled) {
+ return;
+ }
if (this.reactionsPickerExpanded || this.statePanelExpanded) {
this.collapseAllPanels();
}
@@ -756,6 +784,8 @@ export default class DiscourseReactionsActions extends Component {
@post={{@post}}
@scheduleCollapse={{this.scheduleCollapse}}
@cancelCollapse={{this.cancelCollapse}}
+ @disableClickOutside={{this.disableClickOutside}}
+ @enableClickOutside={{this.enableClickOutside}}
@reactionsPickerExpanded={{this.reactionsPickerExpanded}}
@toggle={{this.toggle}}
/>
diff --git a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-picker.gjs b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-picker.gjs
index d36d597e84b..58c55c1c501 100644
--- a/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-picker.gjs
+++ b/plugins/discourse-reactions/assets/javascripts/discourse/components/discourse-reactions-picker.gjs
@@ -4,6 +4,7 @@ import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
+import EmojiPicker from "discourse/components/emoji-picker";
import concatClass from "discourse/helpers/concat-class";
import emoji from "discourse/helpers/emoji";
import { i18n } from "discourse-i18n";
@@ -11,9 +12,11 @@ import { i18n } from "discourse-i18n";
export default class DiscourseReactionsPicker extends Component {
@service siteSettings;
+ emojiPickerIsOpen = false;
+
@action
pointerOut(event) {
- if (event.pointerType !== "mouse") {
+ if (event.pointerType !== "mouse" || this.emojiPickerIsOpen) {
return;
}
@@ -83,7 +86,13 @@ export default class DiscourseReactionsPicker extends Component {
});
}
- _getOptimalColsCount(count) {
+ get optimalColsCount() {
+ let count = this.reactionInfo.length;
+
+ if (this.siteSettings.discourse_reactions_experimental_allow_any_emoji) {
+ count += 1;
+ }
+
let x;
const colsByRow = [5, 6, 7, 8];
@@ -116,6 +125,28 @@ export default class DiscourseReactionsPicker extends Component {
return x;
}
+ @action
+ onSelectEmoji(selected_emoji) {
+ this.args.toggle({
+ reaction: selected_emoji,
+ postId: this.args.post.id,
+ canUndo: true,
+ });
+ }
+
+ @action
+ preventCollapse() {
+ this.emojiPickerIsOpen = true;
+ this.args.cancelCollapse?.();
+ this.args.disableClickOutside?.();
+ }
+
+ @action
+ reenableCollapse() {
+ this.emojiPickerIsOpen = false;
+ this.args.enableClickOutside?.();
+ }
+
<template>
<div
class={{concatClass
@@ -127,9 +158,7 @@ export default class DiscourseReactionsPicker extends Component {
>
{{#if @reactionsPickerExpanded}}
<div
- class="discourse-reactions-picker-container col-{{this._getOptimalColsCount
- this.reactionInfo.length
- }}"
+ class="discourse-reactions-picker-container col-{{this.optimalColsCount}}"
>
{{#each this.reactionInfo as |reaction|}}
<DButton
@@ -152,6 +181,18 @@ export default class DiscourseReactionsPicker extends Component {
{{emoji reaction.id}}
</DButton>
{{/each}}
+ {{#if
+ this.siteSettings.discourse_reactions_experimental_allow_any_emoji
+ }}
+ <EmojiPicker
+ ...attributes
+ @icon="far-face-smile"
+ @didSelectEmoji={{this.onSelectEmoji}}
+ @onShow={{this.preventCollapse}}
+ @onClose={{this.reenableCollapse}}
+ @btnClass="btn-icon btn-flat"
+ />
+ {{/if}}
</div>
{{/if}}
</div>
diff --git a/plugins/discourse-reactions/config/locales/server.en.yml b/plugins/discourse-reactions/config/locales/server.en.yml
index 2909d9a9c24..dc583c3e01d 100644
--- a/plugins/discourse-reactions/config/locales/server.en.yml
+++ b/plugins/discourse-reactions/config/locales/server.en.yml
@@ -7,6 +7,7 @@ en:
discourse_reactions_desaturated_reaction_panel: "Reduces visual noise of reactions by displaying them desaturated until hover."
discourse_reactions_excluded_from_like: "Reactions that do not count as a Like. Any reactions that are not on this list will count as a Like for badges, reporting, and other purposes."
discourse_reactions_like_sync_enabled: "If this is enabled, historical reactions will have their matching Like records created, except those reactions defined in `discourse_reactions_excluded_from_like`. This sync will happen on a regular basis in the background, and also when you change `discourse_reactions_excluded_from_like`."
+ discourse_reactions_experimental_allow_any_emoji: "EXPERIMENTAL: If this is enabled, will add a button allowing users to select any emoji in the reactions picker. Members will be allowed to choose any emoji, including custom emoji, for reactions, so enable this with caution."
errors:
invalid_excluded_emoji: "You cannot exclude emojis that are not in 'discourse reactions enabled reactions' and you cannot exclude the emoji used for 'discourse reactions reaction for like'."
badges:
diff --git a/plugins/discourse-reactions/config/settings.yml b/plugins/discourse-reactions/config/settings.yml
index b13319081fe..dd19721cc00 100644
--- a/plugins/discourse-reactions/config/settings.yml
+++ b/plugins/discourse-reactions/config/settings.yml
@@ -23,3 +23,7 @@ discourse_reactions:
validator: "ReactionsExcludedFromLikeSiteSettingValidator"
discourse_reactions_like_sync_enabled:
default: true
+ discourse_reactions_experimental_allow_any_emoji:
+ default: false
+ client: true
+ area: "experimental"
diff --git a/plugins/discourse-reactions/plugin.rb b/plugins/discourse-reactions/plugin.rb
index d28f8fac0b6..0d60609bb4f 100644
--- a/plugins/discourse-reactions/plugin.rb
+++ b/plugins/discourse-reactions/plugin.rb
@@ -193,8 +193,16 @@ after_initialize do
has_matching_reaction_user =
object.emoji_reactions.any? do |reaction|
- DiscourseReactions::Reaction.reactions_counting_as_like.include?(reaction.reaction_value) &&
- reaction.reaction_users.find { |ru| ru.user_id == scope.user.id }.present?
+ reaction.reaction_users.any? { |ru| ru.user_id == scope.user.id } &&
+ (
+ if SiteSetting.discourse_reactions_experimental_allow_any_emoji
+ reaction.reaction_value != DiscourseReactions::Reaction.main_reaction_id
+ else
+ DiscourseReactions::Reaction.reactions_counting_as_like.include?(
+ reaction.reaction_value,
+ )
+ end
+ )
end
like_post_action.present? && !has_matching_reaction_user
@@ -235,28 +243,28 @@ after_initialize do
reactions_results =
DB.query(<<~SQL, start_date: report.start_date.to_date, end_date: report.end_date.to_date)
- SELECT
- reactions.reaction_value,
- count(reaction_users.id) as reactions_count,
- date_trunc('day', reaction_users.created_at)::date as day
- FROM discourse_reactions_reactions as reactions
- LEFT OUTER JOIN discourse_reactions_reaction_users as reaction_users on reactions.id = reaction_users.reaction_id
- WHERE reactions.reaction_users_count IS NOT NULL
- AND reaction_users.created_at::DATE >= :start_date::DATE AND reaction_users.created_at::DATE <= :end_date::DATE
- GROUP BY reactions.reaction_value, day
- SQL
+ SELECT
+ reactions.reaction_value,
+ count(reaction_users.id) as reactions_count,
+ date_trunc('day', reaction_users.created_at)::date as day
+ FROM discourse_reactions_reactions as reactions
+ LEFT OUTER JOIN discourse_reactions_reaction_users as reaction_users on reactions.id = reaction_users.reaction_id
+ WHERE reactions.reaction_users_count IS NOT NULL
+ AND reaction_users.created_at::DATE >= :start_date::DATE AND reaction_users.created_at::DATE <= :end_date::DATE
+ GROUP BY reactions.reaction_value, day
+ SQL
likes_results =
DB.query(
<<~SQL,
- SELECT
- count(post_actions.id) as likes_count,
- date_trunc('day', post_actions.created_at)::date as day
- FROM post_actions as post_actions
- WHERE post_actions.created_at::DATE >= :start_date::DATE AND post_actions.created_at::DATE <= :end_date::DATE
- AND #{DiscourseReactions::PostActionExtension.filter_reaction_likes_sql}
- GROUP BY day
- SQL
+ SELECT
+ count(post_actions.id) as likes_count,
+ date_trunc('day', post_actions.created_at)::date as day
+ FROM post_actions as post_actions
+ WHERE post_actions.created_at::DATE >= :start_date::DATE AND post_actions.created_at::DATE <= :end_date::DATE
+ AND #{DiscourseReactions::PostActionExtension.filter_reaction_likes_sql}
+ GROUP BY day
+ SQL
start_date: report.start_date.to_date,
end_date: report.end_date.to_date,
like: PostActionType::LIKE_POST_ACTION_ID,
diff --git a/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb
new file mode 100644
index 00000000000..f9d2ba04227
--- /dev/null
+++ b/plugins/discourse-reactions/spec/requests/custom_reactions_controller_custom_emoji_spec.rb
@@ -0,0 +1,157 @@
+# frozen_string_literal: true
+
+require "rails_helper"
+
+describe DiscourseReactions::CustomReactionsController do
+ fab!(:user)
+ fab!(:post_1) { Fabricate(:post) }
+
+ let(:custom_emoji) { "wink" }
+
+ before do
+ SiteSetting.discourse_reactions_enabled = true
+ SiteSetting.discourse_reactions_experimental_allow_any_emoji = true
+ SiteSetting.discourse_reactions_enabled_reactions = "heart|thumbsup|laughing"
+ end
+
+ describe "custom emoji reactions with discourse_reactions_experimental_allow_any_emoji enabled" do
+ context "when user is logged in" do
+ before { sign_in(user) }
+
+ it "allows adding custom emoji reactions when setting is enabled" do
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(200)
+ json = response.parsed_body
+ expect(json).to be_present
+ end
+
+ it "creates reaction with custom emoji" do
+ expect do
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+ end.to change { DiscourseReactions::Reaction.count }.by(1)
+
+ reaction = DiscourseReactions::Reaction.last
+ expect(reaction.reaction_value).to eq("wink")
+ expect(reaction.post_id).to eq(post_1.id)
+ expect(reaction.reaction_users.first.user_id).to eq(user.id)
+ end
+
+ it "allows custom emoji not in enabled_reactions list" do
+ custom_emoji = "rainbow"
+ expect(SiteSetting.discourse_reactions_enabled_reactions).not_to include(custom_emoji)
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(200)
+ reaction = DiscourseReactions::Reaction.last
+ expect(reaction.reaction_value).to eq(custom_emoji)
+ end
+
+ it "denys invalid emoji" do
+ invalid_emoji = "a" * 20
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{invalid_emoji}/toggle.json"
+
+ expect(response.status).to eq(422)
+ end
+
+ it "handles emoji with skin tones" do
+ custom_emoji = "wave"
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(200)
+ reaction = DiscourseReactions::Reaction.last
+ expect(reaction.reaction_value).to eq(custom_emoji)
+ end
+
+ it "can toggle custom emoji reactions on and off" do
+ # Add custom emoji reaction
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+ expect(DiscourseReactions::Reaction.count).to eq(1)
+
+ # Remove custom emoji reaction
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+ expect(DiscourseReactions::Reaction.count).to eq(0)
+ end
+ end
+
+ context "when user is not logged in" do
+ it "returns 403 forbidden" do
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+ expect(response.status).to eq(403)
+ end
+ end
+ end
+
+ describe "custom emoji reactions with discourse_reactions_experimental_allow_any_emoji disabled" do
+ before do
+ SiteSetting.discourse_reactions_experimental_allow_any_emoji = false
+ sign_in(user)
+ end
+
+ it "prevents adding custom emoji when setting is disabled" do
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(422)
+ json = response.parsed_body
+ expect(json["errors"]).to be_present
+ end
+
+ it "still allows reactions from enabled_reactions list" do
+ enabled_reaction = "heart"
+ expect(SiteSetting.discourse_reactions_enabled_reactions).to include(enabled_reaction)
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{enabled_reaction}/toggle.json"
+
+ expect(response.status).to eq(200)
+ end
+ end
+
+ describe "validation and edge cases" do
+ before { sign_in(user) }
+
+ it "validates emoji format" do
+ invalid_emoji = "invalid emoji with spaces"
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{CGI.escape(invalid_emoji)}/toggle.json"
+
+ expect(response.status).to eq(422)
+ end
+
+ it "handles very long emoji names" do
+ long_emoji = "a" * 100
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{long_emoji}/toggle.json"
+
+ expect(response.status).to eq(422)
+ end
+
+ it "handles special characters in emoji names" do
+ special_emoji = "+1"
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{CGI.escape(special_emoji)}/toggle.json"
+
+ expect(response.status).to eq(200)
+ reaction = DiscourseReactions::Reaction.last
+ expect(reaction.reaction_value).to eq(special_emoji)
+ end
+
+ it "prevents reactions on deleted posts" do
+ post_1.trash!
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(404)
+ end
+
+ it "prevents reactions when reactions are disabled globally" do
+ SiteSetting.discourse_reactions_enabled = false
+
+ put "/discourse-reactions/posts/#{post_1.id}/custom-reactions/#{custom_emoji}/toggle.json"
+
+ expect(response.status).to eq(404)
+ end
+ end
+end
diff --git a/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-custom-emoji-test.js b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-custom-emoji-test.js
new file mode 100644
index 00000000000..d7c6e257286
--- /dev/null
+++ b/plugins/discourse-reactions/test/javascripts/acceptance/discourse-reactions-custom-emoji-test.js
@@ -0,0 +1,158 @@
+import { click, triggerEvent, visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import { acceptance } from "discourse/tests/helpers/qunit-helpers";
+import ReactionsTopics from "../fixtures/reactions-topic-fixtures";
+
+["enabled", "disabled"].forEach((postStreamMode) => {
+ acceptance(
+ `Discourse Reactions - Custom Emoji Picker (glimmer_post_stream_mode = ${postStreamMode})`,
+ function (needs) {
+ needs.user();
+
+ needs.settings({
+ discourse_reactions_enabled: true,
+ discourse_reactions_enabled_reactions: "otter|open_mouth|heart",
+ discourse_reactions_reaction_for_like: "heart",
+ discourse_reactions_like_icon: "heart",
+ discourse_reactions_experimental_allow_any_emoji: true,
+ glimmer_post_stream_mode: postStreamMode,
+ });
+
+ needs.pretender((server, helper) => {
+ const topicPath = "/t/374.json";
+ server.get(topicPath, () =>
+ helper.response(ReactionsTopics[topicPath])
+ );
+
+ server.put(
+ "/discourse-reactions/posts/:post_id/custom-reaction/:reaction",
+ () => helper.response({ success: true })
+ );
+
+ server.put(
+ "/discourse-reactions/posts/:post_id/custom-reactions/:reaction/toggle.json",
+ () => helper.response({ success: "OK" })
+ );
+ });
+
+ test("Shows EmojiPicker button when discourse_reactions_experimental_allow_any_emoji is enabled", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+ await triggerEvent(
+ "#post_2 button.btn-toggle-reaction-like",
+ "pointerover",
+ { pointerType: "mouse" }
+ );
+
+ assert
+ .dom(".emoji-picker-trigger")
+ .exists("EmojiPicker button exists in reactions picker");
+ });
+
+ test("Clicking EmojiPicker prevents reactions picker from collapsing", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+ await triggerEvent(
+ "#post_2 button.btn-toggle-reaction-like",
+ "pointerover",
+ { pointerType: "mouse" }
+ );
+
+ await click(".emoji-picker-trigger");
+
+ await triggerEvent("#site-logo", "pointerover", {
+ pointerType: "mouse",
+ });
+ await new Promise((resolve) => setTimeout(resolve, 1000));
+ assert
+ .dom(".discourse-reactions-picker.is-expanded")
+ .exists(
+ "Reactions picker remains expanded even if mouse moving outside when EmojiPicker is open"
+ );
+
+ await click("#post_4 .post-avatar");
+
+ assert
+ .dom(".discourse-reactions-picker.is-expanded")
+ .exists(
+ "Reactions picker remains expanded even if mouse clicking outside when EmojiPicker is open"
+ );
+ });
+
+ test("Selected custom emoji is added to reactions when discourse_reactions_experimental_allow_any_emoji is enabled", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+ await triggerEvent(
+ "#post_2 button.btn-toggle-reaction-like",
+ "pointerover",
+ { pointerType: "mouse" }
+ );
+ await click(".emoji-picker-trigger");
+ await click('img.emoji[alt="grinning"]');
+ // Assert the reactions list emoji on the left
+ assert
+ .dom('#post_2 .discourse-reactions-list-emoji img[alt="grinning"]')
+ .exists("Grinning emoji exists in reactions list");
+
+ // Assert the reaction button emoji
+ assert
+ .dom('#post_2 .btn.reaction-button img[alt=":grinning"]')
+ .exists("Grinning emoji exists in reaction button");
+ });
+ }
+ );
+
+ acceptance(
+ `Discourse Reactions - Custom Emoji Picker Disabled (glimmer_post_stream_mode = ${postStreamMode})`,
+ function (needs) {
+ needs.user();
+
+ needs.settings({
+ discourse_reactions_enabled: true,
+ discourse_reactions_enabled_reactions: "otter|open_mouth|heart",
+ discourse_reactions_reaction_for_like: "heart",
+ discourse_reactions_like_icon: "heart",
+ discourse_reactions_experimental_allow_any_emoji: false,
+ glimmer_post_stream_mode: postStreamMode,
+ });
+
+ needs.pretender((server, helper) => {
+ const topicPath = "/t/374.json";
+ server.get(topicPath, () =>
+ helper.response(ReactionsTopics[topicPath])
+ );
+
+ server.put(
+ "/discourse-reactions/posts/:post_id/custom-reactions/:reaction/toggle.json",
+ () => helper.response({ success: "OK" })
+ );
+ });
+
+ test("Does not show EmojiPicker button when discourse_reactions_experimental_allow_any_emoji is disabled", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+ await triggerEvent(
+ "#post_2 button.btn-toggle-reaction-like",
+ "pointerover",
+ { pointerType: "mouse" }
+ );
+
+ assert
+ .dom(".emoji-picker-trigger")
+ .doesNotExist(
+ "EmojiPicker button does not exist when setting is disabled"
+ );
+ });
+
+ test("Reactions picker grid only counts enabled reactions when EmojiPicker is disabled", async function (assert) {
+ await visit("/t/topic_with_reactions_and_likes/374");
+ await triggerEvent(
+ "#post_2 button.btn-toggle-reaction-like",
+ "pointerover",
+ { pointerType: "mouse" }
+ );
+
+ // With 3 enabled reactions and no emoji picker button = 3 total
+ assert
+ .dom(".discourse-reactions-picker-container")
+ .hasClass("col-3", "Grid has 3 columns without EmojiPicker button");
+ });
+ }
+ );
+});