Files
discourse/plugins/chat/spec/serializer/current_user_serializer_spec.rb
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

67 lines
2.0 KiB
Ruby

# frozen_string_literal: true
RSpec.describe CurrentUserSerializer do
fab!(:current_user) { Fabricate(:user) }
let(:serializer) do
described_class.new(current_user, scope: Guardian.new(current_user), root: false)
end
before do
SiteSetting.chat_enabled = true
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
current_user.user_option.update(chat_enabled: true)
end
describe "#chat_separate_sidebar_mode" do
it "is present" do
expect(serializer.as_json[:user_option][:chat_separate_sidebar_mode]).to eq("default")
end
end
describe "#chat_quick_reaction_type" do
it "is present with default enum string" do
expect(serializer.as_json[:user_option][:chat_quick_reaction_type]).to eq("frequent")
end
end
describe "#chat_quick_reactions_custom" do
it "is present with default enum string" do
expect(serializer.as_json[:user_option][:chat_quick_reactions_custom]).to eq(nil)
end
context "with custom quick reactions" do
before { current_user.user_option.update!(chat_quick_reactions_custom: "tada|smiley") }
it "is present" do
expect(serializer.as_json[:user_option][:chat_quick_reactions_custom]).to eq("tada|smiley")
end
end
end
describe "#chat_drafts" do
context "when user can't chat" do
before { SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff] }
it "is not present" do
expect(serializer.as_json[:chat_drafts]).to be_blank
end
end
it "is ordered by most recent drafts" do
Fabricate(:chat_draft, user: current_user, value: "second draft")
Fabricate(:chat_draft, user: current_user, value: "first draft")
values =
serializer.as_json[:chat_drafts].map { |draft| MultiJson.load(draft[:data])["value"] }
expect(values).to eq(["first draft", "second draft"])
end
it "limits the numbers of drafts" do
21.times { Fabricate(:chat_draft, user: current_user) }
expect(serializer.as_json[:chat_drafts].length).to eq(20)
end
end
end