2023-05-24 21:36:46 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-07 09:26:58 +08:00
|
|
|
RSpec.describe "Chat composer draft", type: :system do
|
2023-05-24 21:36:46 +08:00
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
2023-07-13 07:44:56 +08:00
|
|
|
fab!(:message_1) do
|
|
|
|
Fabricate(
|
|
|
|
:chat_message,
|
2024-04-25 20:29:00 +08:00
|
|
|
use_service: true,
|
2023-07-13 07:44:56 +08:00
|
|
|
chat_channel: channel_1,
|
|
|
|
message: "This is a message for draft and replies",
|
|
|
|
)
|
|
|
|
end
|
2023-05-24 21:36:46 +08:00
|
|
|
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
2023-11-22 18:54:23 +08:00
|
|
|
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
2023-05-24 21:36:46 +08:00
|
|
|
|
|
|
|
before { chat_system_bootstrap }
|
|
|
|
|
|
|
|
context "when loading a channel with a draft" do
|
|
|
|
before do
|
2023-11-22 18:54:23 +08:00
|
|
|
create_draft(channel_1, user: current_user)
|
2023-05-24 21:36:46 +08:00
|
|
|
channel_1.add(current_user)
|
|
|
|
sign_in(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when loading another channel and back" do
|
|
|
|
fab!(:channel_2) { Fabricate(:chat_channel) }
|
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
before do
|
|
|
|
create_draft(channel_2, user: current_user, data: { message: "draft2" })
|
|
|
|
channel_2.add(current_user)
|
2023-05-24 21:36:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the correct drafts" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft")
|
|
|
|
|
|
|
|
chat_page.visit_channel(channel_2)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft2")
|
|
|
|
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
context "when editing" do
|
|
|
|
before do
|
|
|
|
create_draft(
|
|
|
|
channel_1,
|
2023-05-24 21:36:46 +08:00
|
|
|
user: current_user,
|
2023-11-22 18:54:23 +08:00
|
|
|
data: {
|
|
|
|
message: message_1.message,
|
|
|
|
id: message_1.id,
|
|
|
|
editing: true,
|
|
|
|
},
|
2023-05-24 21:36:46 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft with the editing state" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer).to be_editing_message(message_1)
|
|
|
|
end
|
2023-05-31 00:37:30 +08:00
|
|
|
|
|
|
|
context "when canceling editing" do
|
|
|
|
it "resets the draft" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
channel_page.composer.message_details.cancel_edit
|
|
|
|
|
|
|
|
expect(channel_page.composer).to be_blank
|
|
|
|
expect(channel_page.composer).to have_unsaved_draft
|
|
|
|
expect(channel_page.composer).to have_saved_draft
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 21:36:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with uploads" do
|
|
|
|
fab!(:upload_1) do
|
|
|
|
Fabricate(
|
|
|
|
:upload,
|
|
|
|
url: "/images/logo-dark.png",
|
|
|
|
original_filename: "logo_dark.png",
|
|
|
|
width: 400,
|
|
|
|
height: 300,
|
|
|
|
extension: "png",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-11-22 18:54:23 +08:00
|
|
|
before do
|
|
|
|
create_draft(channel_1, user: current_user, data: { message: "draft", uploads: [upload_1] })
|
2023-05-24 21:36:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft with the upload" do
|
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft")
|
|
|
|
expect(page).to have_selector(".chat-composer-upload--image", count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when replying" do
|
2023-11-22 18:54:23 +08:00
|
|
|
before do
|
|
|
|
create_draft(
|
|
|
|
channel_1,
|
2023-05-24 21:36:46 +08:00
|
|
|
user: current_user,
|
|
|
|
data: {
|
|
|
|
message: "draft",
|
|
|
|
replyToMsg: {
|
|
|
|
id: message_1.id,
|
|
|
|
excerpt: message_1.excerpt,
|
|
|
|
user: {
|
|
|
|
id: message_1.user.id,
|
|
|
|
name: nil,
|
|
|
|
avatar_template: message_1.user.avatar_template,
|
|
|
|
username: message_1.user.username,
|
|
|
|
},
|
|
|
|
},
|
2023-11-22 18:54:23 +08:00
|
|
|
},
|
2023-05-24 21:36:46 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2024-02-29 19:24:37 +08:00
|
|
|
it "loads the draft with replied to message" do
|
2023-05-24 21:36:46 +08:00
|
|
|
chat_page.visit_channel(channel_1)
|
|
|
|
|
|
|
|
expect(channel_page.composer.value).to eq("draft")
|
|
|
|
expect(page).to have_selector(".chat-reply__username", text: message_1.user.username)
|
|
|
|
expect(page).to have_selector(".chat-reply__excerpt", text: message_1.excerpt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-11-22 18:54:23 +08:00
|
|
|
|
|
|
|
context "when loading a thread with a draft" do
|
|
|
|
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
|
|
|
|
fab!(:thread_1) { Fabricate(:chat_thread, channel: channel_1) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_draft(channel_1, user: current_user, thread: thread_1)
|
|
|
|
channel_1.add(current_user)
|
|
|
|
sign_in(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft" do
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
|
|
|
|
expect(thread_page.composer.value).to eq("draft")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when loading another channel and back" do
|
|
|
|
fab!(:channel_2) { Fabricate(:chat_channel, threading_enabled: true) }
|
|
|
|
fab!(:thread_2) { Fabricate(:chat_thread, channel: channel_2) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_draft(channel_2, user: current_user, thread: thread_2, data: { message: "draft2" })
|
|
|
|
channel_2.add(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the correct drafts" do
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
|
|
|
|
expect(thread_page.composer.value).to eq("draft")
|
|
|
|
|
|
|
|
chat_page.visit_thread(thread_2)
|
|
|
|
|
|
|
|
expect(thread_page.composer.value).to eq("draft2")
|
|
|
|
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
|
|
|
|
expect(thread_page.composer.value).to eq("draft")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when editing" do
|
|
|
|
before do
|
|
|
|
create_draft(
|
|
|
|
channel_1,
|
|
|
|
user: current_user,
|
|
|
|
thread: thread_1,
|
|
|
|
data: {
|
|
|
|
message: message_1.message,
|
|
|
|
id: message_1.id,
|
|
|
|
editing: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft with the editing state" do
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
|
|
|
|
expect(thread_page.composer).to be_editing_message(message_1)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when canceling editing" do
|
|
|
|
it "resets the draft" do
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
thread_page.composer.message_details.cancel_edit
|
|
|
|
|
|
|
|
expect(thread_page.composer).to be_blank
|
|
|
|
expect(thread_page.composer).to have_unsaved_draft
|
|
|
|
expect(thread_page.composer).to have_saved_draft
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with uploads" do
|
|
|
|
fab!(:upload_1) do
|
|
|
|
Fabricate(
|
|
|
|
:upload,
|
|
|
|
url: "/images/logo-dark.png",
|
|
|
|
original_filename: "logo_dark.png",
|
|
|
|
width: 400,
|
|
|
|
height: 300,
|
|
|
|
extension: "png",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
create_draft(
|
|
|
|
channel_1,
|
|
|
|
user: current_user,
|
|
|
|
thread: thread_1,
|
|
|
|
data: {
|
|
|
|
message: "draft",
|
|
|
|
uploads: [upload_1],
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "loads the draft with the upload" do
|
|
|
|
chat_page.visit_thread(thread_1)
|
|
|
|
|
|
|
|
expect(thread_page.composer.value).to eq("draft")
|
|
|
|
expect(page).to have_selector(".chat-composer-upload--image", count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2023-05-24 21:36:46 +08:00
|
|
|
end
|