2023-05-25 03:56:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-06-06 21:26:58 -04:00
|
|
|
describe "Thread tracking state | full page", type: :system do
|
2023-05-25 03:56:19 -04:00
|
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
|
|
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-15 22:08:26 -04:00
|
|
|
let(:thread_list_page) { PageObjects::Components::Chat::ThreadList.new }
|
2023-05-25 03:56:19 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.enable_experimental_chat_threaded_discussions = true
|
|
|
|
chat_system_bootstrap(current_user, [channel])
|
|
|
|
sign_in(current_user)
|
|
|
|
thread.add(current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has unread messages for a thread" do
|
2023-06-27 23:14:01 -04:00
|
|
|
fab!(:message_1) do
|
2023-05-25 03:56:19 -04:00
|
|
|
Fabricate(:chat_message, chat_channel: channel, thread: thread, user: current_user)
|
|
|
|
end
|
2023-06-27 23:14:01 -04:00
|
|
|
fab!(:message_2) { Fabricate(:chat_message, chat_channel: channel, thread: thread) }
|
2023-05-25 03:56:19 -04:00
|
|
|
|
|
|
|
it "shows the count of threads with unread messages on the thread list button" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
expect(channel_page).to have_unread_thread_indicator(count: 1)
|
|
|
|
end
|
|
|
|
|
2023-07-05 19:47:34 -04:00
|
|
|
it "does not include threads with deleted original messages in the count of threads with unread messages" do
|
|
|
|
thread.original_message.trash!
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
expect(thread_page).to have_no_unread_list_indicator
|
|
|
|
end
|
|
|
|
|
2023-05-25 03:56:19 -04:00
|
|
|
it "shows an indicator on the unread thread in the list" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
channel_page.open_thread_list
|
2023-05-29 03:11:55 -04:00
|
|
|
expect(thread_list_page).to have_unread_item(thread.id, count: 1)
|
2023-05-25 03:56:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "marks the thread as read and removes both indicators when the user opens it" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
channel_page.open_thread_list
|
|
|
|
thread_list_page.item_by_id(thread.id).click
|
2023-05-30 04:10:07 -04:00
|
|
|
expect(thread_page).to have_no_unread_list_indicator
|
2023-06-27 19:58:47 -04:00
|
|
|
thread_page.back_to_previous_route
|
2023-05-25 03:56:19 -04:00
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
|
|
|
end
|
|
|
|
|
2023-05-30 04:10:07 -04:00
|
|
|
it "shows unread indicators for the header of the list when a new unread arrives" do
|
2023-06-27 23:14:01 -04:00
|
|
|
thread.membership_for(current_user).update!(last_read_message_id: message_2.id)
|
2023-05-25 03:56:19 -04:00
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
channel_page.open_thread_list
|
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
|
|
|
Fabricate(:chat_message, chat_channel: channel, thread: thread)
|
|
|
|
expect(thread_list_page).to have_unread_item(thread.id)
|
|
|
|
end
|
2023-05-25 06:54:50 -04:00
|
|
|
|
|
|
|
it "does not change the unread indicator for the header icon when the user is not a member of the thread" do
|
|
|
|
thread.remove(current_user)
|
|
|
|
chat_page.visit_channel(channel)
|
2023-05-30 04:10:07 -04:00
|
|
|
expect(channel_page).to have_no_unread_thread_indicator
|
2023-05-25 06:54:50 -04:00
|
|
|
Fabricate(:chat_message, chat_channel: channel, thread: thread)
|
|
|
|
expect(channel_page).to have_no_unread_thread_indicator
|
2023-05-30 04:10:07 -04:00
|
|
|
channel_page.open_thread_list
|
2023-05-25 06:54:50 -04:00
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
|
|
|
end
|
2023-06-15 22:08:26 -04:00
|
|
|
|
|
|
|
it "allows the user to change their tracking level for an existing thread" do
|
|
|
|
chat_page.visit_thread(thread)
|
|
|
|
thread_page.notification_level = :normal
|
2023-06-17 08:28:22 -04:00
|
|
|
expect(thread_page).to have_notification_level("normal")
|
2023-06-15 22:08:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "allows the user to start tracking a thread they have not replied to" do
|
|
|
|
new_thread = Fabricate(:chat_thread, channel: channel)
|
|
|
|
Fabricate(:chat_message, chat_channel: channel, thread: new_thread)
|
|
|
|
chat_page.visit_thread(new_thread)
|
|
|
|
thread_page.notification_level = :tracking
|
2023-06-17 08:28:22 -04:00
|
|
|
expect(thread_page).to have_notification_level("tracking")
|
2023-06-15 22:08:26 -04:00
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
channel_page.open_thread_list
|
|
|
|
expect(thread_list_page).to have_thread(new_thread)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user's notification level for the thread is set to normal" do
|
|
|
|
before { thread.membership_for(current_user).update!(notification_level: :normal) }
|
|
|
|
|
|
|
|
it "does not show a the count of threads with unread messages on the thread list button" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
expect(channel_page).to have_no_unread_thread_indicator
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show an indicator on the unread thread in the list" do
|
|
|
|
chat_page.visit_channel(channel)
|
|
|
|
channel_page.open_thread_list
|
|
|
|
expect(thread_list_page).to have_no_unread_item(thread.id)
|
|
|
|
end
|
|
|
|
end
|
2023-05-25 03:56:19 -04:00
|
|
|
end
|
|
|
|
end
|