discourse/plugins/chat/spec/system/chat_composer_spec.rb
Jan Cernik 6325e641d8
FIX: Emoji autocomplete “more” button not working in chat (#20113)
* FIX: Emoji autocomplete “more” button not working

* Rely on setting an intial value on the filter input

This commit removes custom logic applied on initial filter and instead gives a param to use as value for the input, automatically triggering the existing filtering handler.

Other notes:
- Slightly changes the API to be able to set a filter and open the composer in one go
- Adds a very simple service spec
- Adds a system spec to fully validate the behavior

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-02-02 15:04:52 -03:00

136 lines
3.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "Chat composer", type: :system, js: true do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel) }
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
let(:chat) { PageObjects::Pages::Chat.new }
let(:channel) { PageObjects::Pages::ChatChannel.new }
before { chat_system_bootstrap }
xit "it stores draft in replies" do
end
xit "it stores draft" do
end
context "when replying to a message" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "adds the reply indicator to the composer" do
chat.visit_channel(channel_1)
channel.reply_to(message_1)
expect(page).to have_selector(
".chat-composer-message-details .chat-reply__username",
text: message_1.user.username,
)
end
end
context "when editing a message" do
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel_1, user: current_user) }
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "adds the edit indicator" do
chat.visit_channel(channel_1)
channel.edit_message(message_2)
expect(page).to have_selector(
".chat-composer-message-details .chat-reply__username",
text: current_user.username,
)
expect(find(".chat-composer-input").value).to eq(message_2.message)
end
context "when pressing escape" do
it "cancels editing" do
chat.visit_channel(channel_1)
channel.edit_message(message_2)
find(".chat-composer-input").send_keys(:escape)
expect(page).to have_no_selector(".chat-composer-message-details .chat-reply__username")
end
end
end
context "when adding an emoji through the picker" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "adds the emoji to the composer" do
chat.visit_channel(channel_1)
channel.open_action_menu
channel.click_action_button("emoji")
find("[data-emoji='grimacing']").click(wait: 0.5)
expect(find(".chat-composer-input").value).to eq(":grimacing:")
end
end
context "when adding an emoji through the autocomplete" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "adds the emoji to the composer" do
chat.visit_channel(channel_1)
find(".chat-composer-input").fill_in(with: ":gri")
find(".emoji-shortname", text: "grimacing").click
expect(find(".chat-composer-input").value).to eq(":grimacing: ")
end
end
context "when opening emoji picker through more button of the autocomplete" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "prefills the emoji picker filter input" do
chat.visit_channel(channel_1)
find(".chat-composer-input").fill_in(with: ":gri")
click_link(I18n.t("js.composer.more_emoji"))
expect(find(".chat-emoji-picker .dc-filter-input").value).to eq("gri")
end
end
context "when typing on keyboard" do
before do
channel_1.add(current_user)
sign_in(current_user)
end
it "propagates keys to composer" do
chat.visit_channel(channel_1)
find("body").send_keys("b")
expect(find(".chat-composer-input").value).to eq("b")
find("body").send_keys("b")
expect(find(".chat-composer-input").value).to eq("bb")
find("body").send_keys(:enter) # special case
expect(find(".chat-composer-input").value).to eq("bb")
end
end
end