DEV: Add upload system specs for chat (#19604)
This commit is contained in:
parent
f17aed973e
commit
29638f0639
|
@ -32,6 +32,7 @@ class Chat::ChatMessageUpdater
|
|||
@chat_message.save!
|
||||
update_uploads(upload_info)
|
||||
revision = save_revision!
|
||||
@chat_message.reload
|
||||
ChatPublisher.publish_edit!(@chat_channel, @chat_message)
|
||||
Jobs.enqueue(:process_chat_message, { chat_message_id: @chat_message.id })
|
||||
Chat::ChatNotifier.notify_edit(chat_message: @chat_message, timestamp: revision.created_at)
|
||||
|
|
|
@ -74,8 +74,14 @@ Fabricator(:chat_message_reaction) do
|
|||
end
|
||||
|
||||
Fabricator(:chat_upload) do
|
||||
chat_message { Fabricate(:chat_message) }
|
||||
upload { Fabricate(:upload) }
|
||||
transient :user
|
||||
|
||||
user do
|
||||
Fabricate(:user)
|
||||
end
|
||||
|
||||
chat_message { |attrs| Fabricate(:chat_message, user: attrs[:user]) }
|
||||
upload { |attrs| Fabricate(:upload, user: attrs[:user]) }
|
||||
end
|
||||
|
||||
Fabricator(:chat_message_revision) do
|
||||
|
|
|
@ -71,8 +71,8 @@ RSpec.describe "Chat composer", type: :system, js: true do
|
|||
|
||||
it "adds the emoji to the composer" do
|
||||
chat.visit_channel(channel_1)
|
||||
find(".chat-composer-dropdown__trigger-btn").click
|
||||
find(".chat-composer-dropdown__action-btn.emoji").click
|
||||
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:")
|
||||
|
|
|
@ -57,11 +57,14 @@ module PageObjects
|
|||
find("[data-value='selectMessage']").click
|
||||
end
|
||||
|
||||
def edit_message(message, text = nil)
|
||||
def open_edit_message(message)
|
||||
hover_message(message)
|
||||
click_more_buttons(message)
|
||||
find("[data-value='edit']").click
|
||||
end
|
||||
|
||||
def edit_message(message, text = nil)
|
||||
open_edit_message(message)
|
||||
send_message(text) if text
|
||||
end
|
||||
|
||||
|
@ -108,6 +111,14 @@ module PageObjects
|
|||
find_reaction(message, reaction).click
|
||||
end
|
||||
|
||||
def open_action_menu
|
||||
find(".chat-composer-dropdown__trigger-btn").click
|
||||
end
|
||||
|
||||
def click_action_button(action_button_class)
|
||||
find(".chat-composer-dropdown__action-btn.#{action_button_class}").click
|
||||
end
|
||||
|
||||
def has_message?(text: nil, id: nil)
|
||||
if text
|
||||
has_css?(".chat-message-text", text: text)
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Uploading files in chat messages", 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 }
|
||||
|
||||
context "when uploading to a new message" do
|
||||
before do
|
||||
channel_1.add(current_user)
|
||||
sign_in(current_user)
|
||||
end
|
||||
|
||||
it "allows uploading a single file" do
|
||||
chat.visit_channel(channel_1)
|
||||
file_path = file_from_fixtures("logo.png", "images").path
|
||||
attach_file(file_path) do
|
||||
channel.open_action_menu
|
||||
channel.click_action_button("chat-upload-btn")
|
||||
end
|
||||
|
||||
expect(page).to have_css(".chat-composer-upload .preview .preview-img")
|
||||
expect(page).to have_content(File.basename(file_path))
|
||||
|
||||
channel.send_message("upload testing")
|
||||
|
||||
expect(page).not_to have_css(".chat-composer-upload")
|
||||
expect(channel).to have_message(text: "upload testing")
|
||||
expect(ChatMessage.last.uploads.count).to eq(1)
|
||||
end
|
||||
|
||||
it "allows uploading a huge image file with preprocessing" do
|
||||
SiteSetting.composer_media_optimization_image_bytes_optimization_threshold = 200.kilobytes
|
||||
chat.visit_channel(channel_1)
|
||||
file_path = file_from_fixtures("huge.jpg", "images").path
|
||||
attach_file(file_path) do
|
||||
channel.open_action_menu
|
||||
channel.click_action_button("chat-upload-btn")
|
||||
end
|
||||
|
||||
expect(page).to have_content(File.basename(file_path))
|
||||
expect(find(".chat-composer-upload")).to have_content("Processing")
|
||||
|
||||
# image processing clientside is slow! here we are waiting for processing
|
||||
# to complete then the upload to complete as well
|
||||
using_wait_time(10) do
|
||||
expect(find(".chat-composer-upload")).to have_content("Uploading")
|
||||
expect(page).to have_css(".chat-composer-upload .preview .preview-img")
|
||||
end
|
||||
|
||||
channel.send_message("upload testing")
|
||||
|
||||
expect(page).not_to have_css(".chat-composer-upload")
|
||||
expect(channel).to have_message(text: "upload testing")
|
||||
expect(ChatMessage.last.uploads.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "when editing a message with uploads" do
|
||||
fab!(:message_2) { Fabricate(:chat_message, user: current_user, chat_channel: channel_1) }
|
||||
fab!(:chat_upload) { Fabricate(:chat_upload, chat_message: message_2, user: current_user) }
|
||||
|
||||
before do
|
||||
channel_1.add(current_user)
|
||||
sign_in(current_user)
|
||||
|
||||
file = file_from_fixtures("logo-dev.png", "images")
|
||||
url = Discourse.store.store_upload(file, chat_upload.upload)
|
||||
chat_upload.upload.update!(url: url, sha1: Upload.generate_digest(file))
|
||||
end
|
||||
|
||||
it "allows deleting uploads" do
|
||||
chat.visit_channel(channel_1)
|
||||
channel.open_edit_message(message_2)
|
||||
find(".chat-composer-upload").find(".remove-upload").click
|
||||
channel.click_send_message
|
||||
expect(channel.message_by_id(message_2.id)).not_to have_css(".chat-uploads")
|
||||
expect(message_2.reload.uploads).to be_empty
|
||||
end
|
||||
|
||||
it "allows adding more uploads" do
|
||||
chat.visit_channel(channel_1)
|
||||
channel.open_edit_message(message_2)
|
||||
|
||||
file_path = file_from_fixtures("logo.png", "images").path
|
||||
attach_file(file_path) do
|
||||
channel.open_action_menu
|
||||
channel.click_action_button("chat-upload-btn")
|
||||
end
|
||||
|
||||
expect(page).to have_css(".chat-composer-upload .preview .preview-img", count: 2)
|
||||
expect(page).to have_content(File.basename(file_path))
|
||||
|
||||
channel.click_send_message
|
||||
|
||||
expect(page).not_to have_css(".chat-composer-upload")
|
||||
expect(page).to have_css(".chat-img-upload", count: 2)
|
||||
expect(message_2.reload.uploads.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context "when uploads are not allowed" do
|
||||
fab!(:user_2) { Fabricate(:user) }
|
||||
fab!(:direct_message_channel_1) do
|
||||
Fabricate(:direct_message_channel, users: [current_user, user_2])
|
||||
end
|
||||
|
||||
before do
|
||||
SiteSetting.chat_allow_uploads = false
|
||||
channel_1.add(current_user)
|
||||
sign_in(current_user)
|
||||
end
|
||||
|
||||
it "does not show the action button for uploading files in public channels" do
|
||||
chat.visit_channel(channel_1)
|
||||
channel.open_action_menu
|
||||
expect(page).not_to have_css(".chat-upload-btn")
|
||||
end
|
||||
|
||||
it "does not show the action button for uploading files in direct message channels" do
|
||||
chat.visit_channel(direct_message_channel_1)
|
||||
channel.open_action_menu
|
||||
expect(page).not_to have_css(".chat-upload-btn")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue