discourse/plugins/chat/spec/system/user_threads_spec.rb
Joffrey JAFFEUX 09277bc543
FEATURE: my threads page (#24771)
This commit adds a new "My threads" link in sidebar and drawer. This link will open the "/chat/threads" page which contains all threads where the current user is a member. It's ordered by activity (unread and then last message created).

Moreover, the threads list of a channel page is now showing every threads of a channel, and not just the ones where you are a member.
2023-12-11 07:38:07 +01:00

195 lines
5.3 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "User threads", type: :system do
fab!(:current_user) { Fabricate(:user) }
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:user_threads_page) { PageObjects::Pages::UserThreads.new }
before do
chat_system_bootstrap
sign_in(current_user)
end
context "when in sidebar" do
it "shows a link to user threads" do
visit("/")
expect(sidebar_page).to have_user_threads_section
end
context "when user has unreads" do
before do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
end
xit "has an unread indicator" do
visit("/")
expect(sidebar_page).to have_unread_user_threads
end
end
it "has no unread indicator when user has no unreads" do
visit("/")
expect(sidebar_page).to have_no_unread_user_threads
end
it "lists threads" do
Fabricate
.times(5, :chat_channel, threading_enabled: true)
.each do |channel|
chat_thread_chain_bootstrap(
channel: channel,
users: [current_user, Fabricate(:user)],
messages_count: 2,
)
end
chat_page.visit_user_threads
expect(user_threads_page).to have_threads(count: 5)
end
it "can load more threads" do
Fabricate
.times(20, :chat_channel, threading_enabled: true)
.each do |channel|
chat_thread_chain_bootstrap(
channel: channel,
users: [current_user, Fabricate(:user)],
messages_count: 2,
)
end
chat_page.visit_user_threads
expect(user_threads_page).to have_threads(count: 10)
page.execute_script("window.scrollTo(0, document.body.scrollHeight)")
expect(user_threads_page).to have_threads(count: 20)
end
it "can open a thread" do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
chat_page.visit_user_threads
user_threads_page.open_thread(channel_1.threads.first)
expect(chat_page).to have_current_path(
"/chat/c/#{channel_1.slug}/#{channel_1.id}/t/#{channel_1.threads.first.id} ",
)
end
it "navigating back from a thread opens the user threads" do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
chat_page.visit_user_threads
user_threads_page.open_thread(channel_1.threads.first)
thread_page.back
expect(user_threads_page).to have_threads
end
end
context "when in drawer" do
it "shows a link to user threads" do
visit("/")
chat_page.open_from_header
expect(drawer_page).to have_user_threads_section
end
context "when user has unreads" do
before do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
end
xit "has an unread indicator" do
visit("/")
chat_page.open_from_header
expect(drawer_page).to have_unread_user_threads
end
end
it "has no unread indicator when user has no unreads" do
visit("/")
expect(sidebar_page).to have_no_unread_user_threads
end
it "lists threads" do
Fabricate
.times(5, :chat_channel, threading_enabled: true)
.each do |channel|
chat_thread_chain_bootstrap(
channel: channel,
users: [current_user, Fabricate(:user)],
messages_count: 2,
)
end
visit("/")
chat_page.open_from_header
drawer_page.click_user_threads
expect(user_threads_page).to have_threads(count: 5)
end
it "can load more threads" do
Fabricate
.times(20, :chat_channel, threading_enabled: true)
.each do |channel|
chat_thread_chain_bootstrap(
channel: channel,
users: [current_user, Fabricate(:user)],
messages_count: 2,
)
end
visit("/")
chat_page.open_from_header
drawer_page.click_user_threads
expect(user_threads_page).to have_threads(count: 10)
page.execute_script(
"document.querySelector('.chat-drawer-content').scrollTo(0, document.querySelector('.chat-drawer-content').scrollHeight)",
)
expect(user_threads_page).to have_threads(count: 20)
end
it "can open a thread" do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
visit("/")
chat_page.open_from_header
drawer_page.click_user_threads
user_threads_page.open_thread(channel_1.threads.first)
expect(drawer_page).to have_open_thread(channel_1.threads.first)
end
it "navigating back from a thread opens the user threads" do
chat_thread_chain_bootstrap(channel: channel_1, users: [current_user, Fabricate(:user)])
visit("/")
chat_page.open_from_header
drawer_page.click_user_threads
user_threads_page.open_thread(channel_1.threads.first)
drawer_page.back
expect(user_threads_page).to have_threads
end
end
end