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:
Joffrey JAFFEUX
2023-05-24 19:28:54 +02:00
committed by GitHub
parent 38d358fb9a
commit f3f841a018
9 changed files with 91 additions and 23 deletions

View File

@ -17,8 +17,8 @@ module PageObjects
visit("/chat")
end
def visit_channel(channel)
visit(channel.url)
def visit_channel(channel, message_id: nil)
visit(channel.url + (message_id ? "/#{message_id}" : ""))
has_no_css?(".chat-channel--not-loaded-once")
has_no_css?(".chat-skeleton")
end

View File

@ -7,6 +7,10 @@ module PageObjects
@composer ||= PageObjects::Components::Chat::Composer.new(".chat-channel")
end
def messages
@messages ||= PageObjects::Components::Chat::Messages.new(".chat-channel")
end
def replying_to?(message)
find(".chat-channel .chat-reply", text: message.message)
end
@ -115,10 +119,12 @@ module PageObjects
end
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
fill_composer(text)
click_send_message
click_composer
has_no_loading_skeleton?
end
def reply_to(message)

View File

@ -12,6 +12,10 @@ module PageObjects
PageObjects::Components::Chat::ComposerMessageDetails.new(".chat-thread")
end
def messages
@messages ||= PageObjects::Components::Chat::Messages.new(".chat-thread")
end
def header
find(".chat-thread__header")
end
@ -47,6 +51,7 @@ module PageObjects
end
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
fill_composer(text)
click_send_message

View File

@ -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

View File

@ -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