2023-05-25 15:56:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-07 09:26:58 +08:00
|
|
|
describe "Thread tracking state | drawer", type: :system do
|
2023-07-18 13:45:52 +08:00
|
|
|
include ActiveSupport::Testing::TimeHelpers
|
|
|
|
|
2023-05-25 15:56:19 +08:00
|
|
|
fab!(:current_user) { Fabricate(:admin) }
|
|
|
|
fab!(:channel) { Fabricate(:chat_channel, threading_enabled: true) }
|
|
|
|
fab!(:other_user) { Fabricate(:user) }
|
|
|
|
fab!(:thread) { Fabricate(:chat_thread, channel: channel) }
|
|
|
|
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
|
|
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
|
|
|
|
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
2023-06-16 10:08:26 +08:00
|
|
|
let(:thread_list_page) { PageObjects::Components::Chat::ThreadList.new }
|
2023-05-25 15:56:19 +08:00
|
|
|
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
chat_system_bootstrap(current_user, [channel])
|
2023-07-18 13:45:52 +08:00
|
|
|
chat_system_user_bootstrap(user: other_user, channel: channel)
|
2023-05-25 15:56:19 +08:00
|
|
|
sign_in(current_user)
|
|
|
|
thread.add(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has unread messages for a thread" do
|
2023-06-28 11:14:01 +08:00
|
|
|
fab!(:message_1) do
|
2023-08-24 21:22:51 +08:00
|
|
|
Fabricate(:chat_message, thread: thread, user: current_user, use_service: true)
|
2023-05-25 15:56:19 +08:00
|
|
|
end
|
2023-08-24 21:22:51 +08:00
|
|
|
fab!(:message_2) { Fabricate(:chat_message, thread: thread, use_service: true) }
|
2023-05-25 15:56:19 +08:00
|
|
|
|
|
|
|
it "shows the count of threads with unread messages on the thread list button" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
expect(drawer_page).to have_unread_thread_indicator(count: 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows an indicator on the unread thread in the list" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.open_thread_list
|
|
|
|
expect(drawer_page).to have_open_thread_list
|
|
|
|
expect(thread_list_page).to have_unread_item(thread.id)
|
|
|
|
end
|
|
|
|
|
2024-09-02 20:45:55 +08:00
|
|
|
it "shows an urgent indicator on the watched thread in the list" do
|
|
|
|
thread.membership_for(current_user).update!(
|
|
|
|
notification_level: ::Chat::NotificationLevels.all[:watching],
|
|
|
|
)
|
|
|
|
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.open_thread_list
|
|
|
|
expect(drawer_page).to have_open_thread_list
|
|
|
|
expect(thread_list_page).to have_unread_item(thread.id, urgent: true)
|
|
|
|
end
|
|
|
|
|
2023-05-25 15:56:19 +08:00
|
|
|
it "marks the thread as read and removes both indicators when the user opens it" do
|
2023-12-19 16:27:09 +08:00
|
|
|
skip("Flaky on CI") if ENV["CI"]
|
|
|
|
|
2023-05-25 15:56:19 +08:00
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.open_thread_list
|
2023-12-19 00:49:58 +08:00
|
|
|
thread_list_page.open_thread(thread)
|
|
|
|
|
2023-05-25 15:56:19 +08:00
|
|
|
expect(drawer_page).to have_no_unread_thread_indicator
|
2023-12-19 00:49:58 +08:00
|
|
|
|
|
|
|
# this is a hack to ensure we don't destroy the component as it's doing the mark as read request
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
drawer_page.back
|
|
|
|
|
2023-05-25 15:56:19 +08:00
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
|
|
|
end
|
|
|
|
|
2023-07-27 21:12:22 +08:00
|
|
|
xit "shows unread indicators for the header icon and the list when a new unread arrives" do
|
2023-06-28 11:14:01 +08:00
|
|
|
thread.membership_for(current_user).update!(last_read_message_id: message_2.id)
|
2023-05-25 15:56:19 +08:00
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.open_thread_list
|
|
|
|
expect(drawer_page).to have_no_unread_thread_indicator
|
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
2023-07-18 13:45:52 +08:00
|
|
|
travel_to(1.minute.from_now)
|
2023-08-24 21:22:51 +08:00
|
|
|
Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
|
2023-05-25 15:56:19 +08:00
|
|
|
expect(drawer_page).to have_unread_thread_indicator(count: 1)
|
|
|
|
expect(thread_list_page).to have_unread_item(thread.id)
|
|
|
|
end
|
2023-07-17 11:00:49 +08:00
|
|
|
|
|
|
|
describe "channel index unread indicators" do
|
|
|
|
fab!(:other_channel) { Fabricate(:chat_channel) }
|
|
|
|
|
|
|
|
before { other_channel.add(current_user) }
|
|
|
|
|
|
|
|
it "shows an unread indicator for the channel with unread threads in the index" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
expect(drawer_page).to have_unread_channel(channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show an unread indicator for the channel if the user has visited the channel since the unread thread message arrived" do
|
|
|
|
channel.membership_for(current_user).update!(last_viewed_at: Time.zone.now)
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
expect(drawer_page).to have_no_unread_channel(channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "clears the index unread indicator for the channel when opening it but keeps the thread list unread indicator" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
expect(channel_page).to have_unread_thread_indicator(count: 1)
|
|
|
|
drawer_page.back
|
|
|
|
expect(drawer_page).to have_no_unread_channel(channel)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show an unread indicator for the channel index if a new thread message arrives while the user is looking at the channel" do
|
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
expect(drawer_page).to have_unread_channel(channel)
|
|
|
|
drawer_page.open_channel(channel)
|
2023-08-24 21:22:51 +08:00
|
|
|
Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
|
2023-07-17 11:00:49 +08:00
|
|
|
drawer_page.back
|
|
|
|
expect(drawer_page).to have_no_unread_channel(channel)
|
|
|
|
end
|
|
|
|
|
2023-07-18 13:45:52 +08:00
|
|
|
it "shows an unread indicator for the channel index if a new thread message arrives while the user is not looking at the channel" do
|
2023-07-17 11:00:49 +08:00
|
|
|
visit("/")
|
|
|
|
chat_page.open_from_header
|
|
|
|
drawer_page.open_channel(channel)
|
|
|
|
drawer_page.back
|
|
|
|
expect(drawer_page).to have_no_unread_channel(channel)
|
2023-07-18 13:45:52 +08:00
|
|
|
travel_to(1.minute.from_now)
|
2023-08-24 21:22:51 +08:00
|
|
|
Fabricate(:chat_message, thread: thread, user: other_user, use_service: true)
|
2023-07-17 11:00:49 +08:00
|
|
|
expect(drawer_page).to have_unread_channel(channel)
|
|
|
|
end
|
|
|
|
end
|
2023-05-25 15:56:19 +08:00
|
|
|
end
|
|
|
|
end
|