DEV: add spec for chat drawer channel lists (#28927)

Adds a spec for chat channels lists in desktop drawer mode.
This commit is contained in:
David Battersby 2024-09-16 12:15:21 +04:00 committed by GitHub
parent 38c286ac40
commit d7293eafef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,136 @@
# frozen_string_literal: true
RSpec.describe "List channels | Drawer", type: :system do
fab!(:current_user) { Fabricate(:user) }
let(:chat) { PageObjects::Pages::Chat.new }
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
before do
chat_system_bootstrap
sign_in(current_user)
chat.prefers_drawer
end
context "when channels tab" do
context "when channels are available" do
fab!(:category_channel_1) { Fabricate(:category_channel) }
context "when member of the channel" do
before { category_channel_1.add(current_user) }
it "shows the channel" do
drawer_page.visit_index
expect(drawer_page).to have_channel(category_channel_1)
end
end
context "when not member of the channel" do
it "does not show the channel" do
drawer_page.visit_index
expect(drawer_page).to have_no_channel(category_channel_1)
end
end
end
context "when multiple channels are present" do
fab!(:channel_1) { Fabricate(:category_channel, name: "a channel") }
fab!(:channel_2) { Fabricate(:category_channel, name: "b channel") }
fab!(:channel_3) { Fabricate(:category_channel, name: "c channel") }
fab!(:channel_4) { Fabricate(:category_channel, name: "d channel") }
before do
channel_1.add(current_user)
channel_2.add(current_user)
channel_3.add(current_user)
channel_4.add(current_user)
end
it "sorts them by urgent, unread, then by slug" do
drawer_page.visit_index
Fabricate(
:chat_message,
chat_channel: channel_1,
created_at: 5.minutes.ago,
use_service: true,
)
Fabricate(
:chat_message,
chat_channel: channel_2,
created_at: 2.minutes.ago,
use_service: true,
)
Fabricate(
:chat_message,
chat_channel: channel_3,
message: "@#{current_user.username}",
use_service: true,
)
Fabricate(:chat_message, chat_channel: channel_4, use_service: true)
expect(drawer_page).to have_channel_at_position(channel_3, 1)
expect(drawer_page).to have_channel_at_position(channel_1, 2)
expect(drawer_page).to have_channel_at_position(channel_2, 3)
end
end
end
context "when no category channels" do
it "shows the empty channel list" do
drawer_page.visit_index
expect(drawer_page).to have_selector(".channel-list-empty-message")
end
end
context "when direct messages tab" do
context "when member of the channel" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user]) }
it "shows the channel" do
drawer_page.visit_index
drawer_page.click_direct_messages
expect(drawer_page).to have_channel(dm_channel_1)
end
end
context "when not member of the channel" do
fab!(:dm_channel_1) { Fabricate(:direct_message_channel) }
it "does not show the channel" do
drawer_page.visit_index
drawer_page.click_direct_messages
expect(drawer_page).to have_no_channel(dm_channel_1)
end
end
context "when multiple channels are present" do
fab!(:user_1) { Fabricate(:user) }
fab!(:dm_channel_1) { Fabricate(:direct_message_channel, users: [current_user]) }
fab!(:dm_channel_2) { Fabricate(:direct_message_channel, users: [current_user, user_1]) }
before do
Fabricate(:chat_message, chat_channel: dm_channel_2, user: user_1, use_service: true)
end
it "sorts them by latest activity" do
drawer_page.visit_index
drawer_page.click_direct_messages
expect(drawer_page).to have_channel_at_position(dm_channel_2, 1)
expect(drawer_page).to have_channel_at_position(dm_channel_1, 2)
end
end
end
context "when no direct message channels" do
it "shows the empty channel list" do
drawer_page.visit_index
drawer_page.click_direct_messages
expect(drawer_page).to have_selector(".channel-list-empty-message")
end
end
end

View File

@ -29,6 +29,14 @@ module PageObjects
".chat-channel-row[data-chat-channel-id='#{channel.id}']"
end
def has_channel?(channel)
has_css?(channel_row_selector(channel))
end
def has_no_channel?(channel)
has_no_css?(channel_row_selector(channel))
end
def has_unread_channel?(channel, count: nil, wait: Capybara.default_max_wait_time)
unread_indicator_selector =
"#{channel_row_selector(channel)} .chat-channel-unread-indicator"

View File

@ -48,6 +48,20 @@ module PageObjects
has_no_css?(".chat-skeleton")
end
def has_channel?(channel)
channels_index.has_channel?(channel)
end
def has_no_channel?(channel)
channels_index.has_no_channel?(channel)
end
def has_channel_at_position?(channel, position)
find(
"#{VISIBLE_DRAWER} .chat-channel-row:nth-child(#{position})[data-chat-channel-id='#{channel.id}']",
)
end
def has_unread_channel?(channel)
channels_index.has_unread_channel?(channel)
end