mirror of
https://github.com/discourse/discourse.git
synced 2025-06-19 22:23:04 +08:00
DEV: implements initial messages component (#21727)
This should also make `message_notifications_with_sidebar_spec.rb` more resilient as we are now checking for `is-persisted` class instead of checking for the absence of `is-staged`.
This commit is contained in:
@ -22,6 +22,7 @@
|
|||||||
(if this.pane.selectingMessages "selecting-messages")
|
(if this.pane.selectingMessages "selecting-messages")
|
||||||
(if @message.highlighted "highlighted")
|
(if @message.highlighted "highlighted")
|
||||||
(if (eq @message.user.id this.currentUser.id) "is-by-current-user")
|
(if (eq @message.user.id this.currentUser.id) "is-by-current-user")
|
||||||
|
(if @message.staged "is-staged" "is-persisted")
|
||||||
}}
|
}}
|
||||||
data-id={{@message.id}}
|
data-id={{@message.id}}
|
||||||
data-thread-id={{@message.thread.id}}
|
data-thread-id={{@message.thread.id}}
|
||||||
@ -65,7 +66,6 @@
|
|||||||
{{did-update this.initMentionedUsers @message.version}}
|
{{did-update this.initMentionedUsers @message.version}}
|
||||||
class={{concat-class
|
class={{concat-class
|
||||||
"chat-message"
|
"chat-message"
|
||||||
(if @message.staged "chat-message-staged" "chat-message-persisted")
|
|
||||||
(if @message.deletedAt "deleted")
|
(if @message.deletedAt "deleted")
|
||||||
(if (and @message.inReplyTo (not this.hideReplyToInfo)) "is-reply")
|
(if (and @message.inReplyTo (not this.hideReplyToInfo)) "is-reply")
|
||||||
(if this.showThreadIndicator "is-threaded")
|
(if this.showThreadIndicator "is-threaded")
|
||||||
|
@ -6,7 +6,7 @@ RSpec.describe "Chat channel", type: :system, js: true do
|
|||||||
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }
|
||||||
|
|
||||||
let(:chat) { PageObjects::Pages::Chat.new }
|
let(:chat) { PageObjects::Pages::Chat.new }
|
||||||
let(:channel) { PageObjects::Pages::ChatChannel.new }
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
||||||
|
|
||||||
before { chat_system_bootstrap }
|
before { chat_system_bootstrap }
|
||||||
|
|
||||||
@ -21,15 +21,13 @@ RSpec.describe "Chat channel", type: :system, js: true do
|
|||||||
|
|
||||||
it "loads most recent messages" do
|
it "loads most recent messages" do
|
||||||
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1)
|
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1)
|
||||||
visit("/chat/c/-/#{channel_1.id}/#{message_1.id}")
|
chat.visit_channel(channel_1, message_id: message_1.id)
|
||||||
|
|
||||||
expect(channel).to have_no_loading_skeleton
|
expect(channel_page.messages).to have_no_message(id: unloaded_message.id)
|
||||||
expect(page).to have_no_css("[data-id='#{unloaded_message.id}']")
|
|
||||||
|
|
||||||
channel.send_message("test_message")
|
channel_page.send_message
|
||||||
|
|
||||||
expect(channel).to have_no_loading_skeleton
|
expect(channel_page.messages).to have_message(id: unloaded_message.id)
|
||||||
expect(page).to have_css("[data-id='#{unloaded_message.id}']")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,12 +44,12 @@ RSpec.describe "Chat channel", type: :system, js: true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
using_session(:tab_1) do |session|
|
using_session(:tab_1) do |session|
|
||||||
channel.send_message("test_message")
|
channel_page.send_message("test_message")
|
||||||
session.quit
|
session.quit
|
||||||
end
|
end
|
||||||
|
|
||||||
using_session(:tab_2) do |session|
|
using_session(:tab_2) do |session|
|
||||||
expect(channel).to have_message(text: "test_message")
|
expect(channel_page).to have_message(text: "test_message")
|
||||||
session.quit
|
session.quit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -59,12 +57,14 @@ RSpec.describe "Chat channel", type: :system, js: true do
|
|||||||
|
|
||||||
it "allows to edit this message once persisted" do
|
it "allows to edit this message once persisted" do
|
||||||
chat.visit_channel(channel_1)
|
chat.visit_channel(channel_1)
|
||||||
channel.send_message("aaaaaaaaaaaaaaaaaaaa")
|
channel_page.send_message("aaaaaa")
|
||||||
expect(page).to have_no_css(".chat-message-staged")
|
|
||||||
|
expect(channel_page.messages).to have_message(persisted: true, text: "aaaaaa")
|
||||||
|
|
||||||
last_message = find(".chat-message-container:last-child")
|
last_message = find(".chat-message-container:last-child")
|
||||||
last_message.hover
|
last_message.hover
|
||||||
|
|
||||||
expect(page).to have_css(
|
expect(channel_page).to have_css(
|
||||||
".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
|
".chat-message-actions-container[data-id='#{last_message["data-id"]}']",
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -81,12 +81,12 @@ RSpec.describe "Chat channel", type: :system, js: true do
|
|||||||
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1)
|
unloaded_message = Fabricate(:chat_message, chat_channel: channel_1)
|
||||||
visit("/chat/message/#{message_1.id}")
|
visit("/chat/message/#{message_1.id}")
|
||||||
|
|
||||||
expect(channel).to have_no_loading_skeleton
|
expect(channel_page).to have_no_loading_skeleton
|
||||||
expect(page).to have_no_css("[data-id='#{unloaded_message.id}']")
|
expect(page).to have_no_css("[data-id='#{unloaded_message.id}']")
|
||||||
|
|
||||||
find(".chat-scroll-to-bottom").click
|
find(".chat-scroll-to-bottom").click
|
||||||
|
|
||||||
expect(channel).to have_no_loading_skeleton
|
expect(channel_page).to have_no_loading_skeleton
|
||||||
expect(page).to have_css("[data-id='#{unloaded_message.id}']")
|
expect(page).to have_css("[data-id='#{unloaded_message.id}']")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,7 +19,7 @@ RSpec.describe "Deleted message", type: :system, js: true do
|
|||||||
chat_page.visit_channel(channel_1)
|
chat_page.visit_channel(channel_1)
|
||||||
channel_page.send_message("aaaaaaaaaaaaaaaaaaaa")
|
channel_page.send_message("aaaaaaaaaaaaaaaaaaaa")
|
||||||
|
|
||||||
expect(page).to have_css(".chat-message-persisted")
|
expect(page).to have_css(".is-persisted")
|
||||||
|
|
||||||
last_message = find(".chat-message-container:last-child")
|
last_message = find(".chat-message-container:last-child")
|
||||||
channel_page.delete_message(OpenStruct.new(id: last_message["data-id"]))
|
channel_page.delete_message(OpenStruct.new(id: last_message["data-id"]))
|
||||||
|
@ -4,19 +4,20 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
|
|||||||
fab!(:current_user) { Fabricate(:user) }
|
fab!(:current_user) { Fabricate(:user) }
|
||||||
|
|
||||||
let!(:chat_page) { PageObjects::Pages::Chat.new }
|
let!(:chat_page) { PageObjects::Pages::Chat.new }
|
||||||
let!(:chat_channel_page) { PageObjects::Pages::ChatChannel.new }
|
let!(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.navigation_menu = "sidebar"
|
SiteSetting.navigation_menu = "sidebar"
|
||||||
chat_system_bootstrap
|
chat_system_bootstrap
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_message(text: "this is fine", channel:, creator: Fabricate(:user))
|
def create_message(text: nil, channel:, creator: Fabricate(:user))
|
||||||
sign_in(creator)
|
sign_in(creator)
|
||||||
chat_page.visit_channel(channel)
|
chat_page.visit_channel(channel)
|
||||||
chat_channel_page.send_message(text)
|
channel_page.send_message(text)
|
||||||
expect(chat_channel_page).to have_no_css(".chat-message-staged")
|
args = { persisted: true }
|
||||||
expect(chat_channel_page).to have_message(text: text)
|
args[:text] = text if text
|
||||||
|
expect(channel_page.messages).to have_message(**args)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "as a user" do
|
context "as a user" do
|
||||||
@ -34,6 +35,7 @@ RSpec.describe "Message notifications - with sidebar", type: :system, js: true d
|
|||||||
context "when a message is created" do
|
context "when a message is created" do
|
||||||
it "doesn't show anything" do
|
it "doesn't show anything" do
|
||||||
visit("/")
|
visit("/")
|
||||||
|
|
||||||
using_session(:user_1) do |session|
|
using_session(:user_1) do |session|
|
||||||
create_message(channel: channel_1, creator: user_1)
|
create_message(channel: channel_1, creator: user_1)
|
||||||
session.quit
|
session.quit
|
||||||
|
@ -17,8 +17,8 @@ module PageObjects
|
|||||||
visit("/chat")
|
visit("/chat")
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_channel(channel)
|
def visit_channel(channel, message_id: nil)
|
||||||
visit(channel.url)
|
visit(channel.url + (message_id ? "/#{message_id}" : ""))
|
||||||
has_no_css?(".chat-channel--not-loaded-once")
|
has_no_css?(".chat-channel--not-loaded-once")
|
||||||
has_no_css?(".chat-skeleton")
|
has_no_css?(".chat-skeleton")
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,10 @@ module PageObjects
|
|||||||
@composer ||= PageObjects::Components::Chat::Composer.new(".chat-channel")
|
@composer ||= PageObjects::Components::Chat::Composer.new(".chat-channel")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def messages
|
||||||
|
@messages ||= PageObjects::Components::Chat::Messages.new(".chat-channel")
|
||||||
|
end
|
||||||
|
|
||||||
def replying_to?(message)
|
def replying_to?(message)
|
||||||
find(".chat-channel .chat-reply", text: message.message)
|
find(".chat-channel .chat-reply", text: message.message)
|
||||||
end
|
end
|
||||||
@ -115,10 +119,12 @@ module PageObjects
|
|||||||
end
|
end
|
||||||
|
|
||||||
def send_message(text = nil)
|
def send_message(text = nil)
|
||||||
|
text ||= Faker::Lorem.characters(number: SiteSetting.chat_minimum_message_length)
|
||||||
text = text.chomp if text.present? # having \n on the end of the string counts as an Enter keypress
|
text = text.chomp if text.present? # having \n on the end of the string counts as an Enter keypress
|
||||||
fill_composer(text)
|
fill_composer(text)
|
||||||
click_send_message
|
click_send_message
|
||||||
click_composer
|
click_composer
|
||||||
|
has_no_loading_skeleton?
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply_to(message)
|
def reply_to(message)
|
||||||
|
@ -12,6 +12,10 @@ module PageObjects
|
|||||||
PageObjects::Components::Chat::ComposerMessageDetails.new(".chat-thread")
|
PageObjects::Components::Chat::ComposerMessageDetails.new(".chat-thread")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def messages
|
||||||
|
@messages ||= PageObjects::Components::Chat::Messages.new(".chat-thread")
|
||||||
|
end
|
||||||
|
|
||||||
def header
|
def header
|
||||||
find(".chat-thread__header")
|
find(".chat-thread__header")
|
||||||
end
|
end
|
||||||
@ -47,6 +51,7 @@ module PageObjects
|
|||||||
end
|
end
|
||||||
|
|
||||||
def send_message(text = nil)
|
def send_message(text = nil)
|
||||||
|
text ||= Faker::Lorem.characters(number: SiteSetting.chat_minimum_message_length)
|
||||||
text = text.chomp if text.present? # having \n on the end of the string counts as an Enter keypress
|
text = text.chomp if text.present? # having \n on the end of the string counts as an Enter keypress
|
||||||
fill_composer(text)
|
fill_composer(text)
|
||||||
click_send_message
|
click_send_message
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PageObjects
|
||||||
|
module Components
|
||||||
|
module Chat
|
||||||
|
class Message < PageObjects::Components::Base
|
||||||
|
attr_reader :context
|
||||||
|
|
||||||
|
SELECTOR = ".chat-message-container"
|
||||||
|
|
||||||
|
def initialize(context)
|
||||||
|
@context = context
|
||||||
|
end
|
||||||
|
|
||||||
|
def exists?(**args)
|
||||||
|
selectors = SELECTOR
|
||||||
|
selectors += "[data-id=\"#{args[:id]}\"]" if args[:id]
|
||||||
|
selectors += ".is-persisted" if args[:persisted]
|
||||||
|
selectors += ".is-staged" if args[:staged]
|
||||||
|
|
||||||
|
if args[:text]
|
||||||
|
find(context).has_selector?(selectors + " " + ".chat-message-text", text: args[:text])
|
||||||
|
else
|
||||||
|
find(context).has_selector?(selectors)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,25 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module PageObjects
|
||||||
|
module Components
|
||||||
|
module Chat
|
||||||
|
class Messages < PageObjects::Components::Base
|
||||||
|
attr_reader :context
|
||||||
|
|
||||||
|
SELECTOR = ".chat-message-container"
|
||||||
|
|
||||||
|
def initialize(context)
|
||||||
|
@context = context
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_message?(**args)
|
||||||
|
PageObjects::Components::Chat::Message.new(".chat-channel").exists?(**args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_no_message?(**args)
|
||||||
|
!has_message?(**args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user