FEATURE: Conditionally change back button route for thread (#22129)

When clicking back from a thread, we want to either go back to the
channel if the thread was opened from an indicator, or to the thread
list if we opened it from there. Since ember doesn't give a nice way
to get the previous route, we need to store this ourselves. We only
do this on mobile, on desktop we just follow existing behaviour.

Also implements a chat router history.

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
Martin Brennan
2023-06-28 09:58:47 +10:00
committed by GitHub
parent aef7c2fe8f
commit cec68b3e2c
15 changed files with 144 additions and 37 deletions

View File

@ -4,18 +4,22 @@ RSpec.describe "Navigation", type: :system do
fab!(:category) { Fabricate(:category) }
fab!(:topic) { Fabricate(:topic) }
fab!(:post) { Fabricate(:post, topic: topic) }
fab!(:user) { Fabricate(:admin) }
fab!(:current_user) { Fabricate(:admin) }
fab!(:category_channel) { Fabricate(:category_channel) }
fab!(:category_channel_2) { Fabricate(:category_channel) }
fab!(:message) { Fabricate(:chat_message, chat_channel: category_channel) }
let(:chat_page) { PageObjects::Pages::Chat.new }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
let(:thread_list_page) { PageObjects::Components::Chat::ThreadList.new }
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
let(:side_panel_page) { PageObjects::Pages::ChatSidePanel.new }
let(:sidebar_page) { PageObjects::Pages::Sidebar.new }
let(:sidebar_component) { PageObjects::Components::Sidebar.new }
let(:chat_drawer_page) { PageObjects::Pages::ChatDrawer.new }
before do
chat_system_bootstrap(user, [category_channel, category_channel_2])
sign_in(user)
chat_system_bootstrap(current_user, [category_channel, category_channel_2])
sign_in(current_user)
end
context "when clicking chat icon and drawer is viewing channel" do
@ -127,6 +131,66 @@ RSpec.describe "Navigation", type: :system do
end
end
context "when opening a thread" do
fab!(:thread) { Fabricate(:chat_thread, channel: category_channel) }
before do
SiteSetting.enable_experimental_chat_threaded_discussions = true
category_channel.update!(threading_enabled: true)
Fabricate(:chat_message, thread: thread)
thread.add(current_user)
end
context "when opening a thread from the thread list" do
it "goes back to the thread list when clicking the back button" do
visit("/chat")
chat_page.visit_channel(category_channel)
channel_page.open_thread_list
expect(thread_list_page).to have_loaded
thread_list_page.open_thread(thread)
expect(side_panel_page).to have_open_thread(thread)
thread_page.back_to_previous_route
expect(thread_list_page).to have_loaded
end
context "for mobile" do
it "goes back to the thread list when clicking the back button", mobile: true do
visit("/chat")
chat_page.visit_channel(category_channel)
channel_page.open_thread_list
expect(thread_list_page).to have_loaded
thread_list_page.open_thread(thread)
expect(side_panel_page).to have_open_thread(thread)
thread_page.back_to_previous_route
expect(thread_list_page).to have_loaded
end
end
end
context "when opening a thread from indicator" do
it "goes back to the thread list when clicking the back button" do
visit("/chat")
chat_page.visit_channel(category_channel)
channel_page.message_thread_indicator(thread.original_message).click
expect(side_panel_page).to have_open_thread(thread)
thread_page.back_to_previous_route
expect(thread_list_page).to have_loaded
end
context "for mobile" do
it "closes the thread and goes back to the channel when clicking the back button",
mobile: true do
visit("/chat")
chat_page.visit_channel(category_channel)
channel_page.message_thread_indicator(thread.original_message).click
expect(side_panel_page).to have_open_thread(thread)
thread_page.back_to_previous_route
expect(side_panel_page).not_to be_open
end
end
end
end
context "when sidebar is configured as the navigation menu" do
before { SiteSetting.navigation_menu = "sidebar" }
@ -244,7 +308,7 @@ RSpec.describe "Navigation", type: :system do
context "when opening a channel in full page" do
fab!(:other_user) { Fabricate(:user) }
fab!(:dm_channel) { Fabricate(:direct_message_channel, users: [user, other_user]) }
fab!(:dm_channel) { Fabricate(:direct_message_channel, users: [current_user, other_user]) }
it "activates the channel in the sidebar" do
visit("/chat/c/#{category_channel.slug}/#{category_channel.id}")

View File

@ -3,6 +3,10 @@
module PageObjects
module Pages
class ChatSidePanel < PageObjects::Pages::Base
def open?
has_css?(".chat-side-panel")
end
def has_open_thread?(thread = nil)
if thread
has_css?(".chat-side-panel .chat-thread[data-id='#{thread.id}']")

View File

@ -58,17 +58,17 @@ module PageObjects
header.find(".chat-thread__close").click
end
def back_to_list
header.find(".chat-thread__back-to-list").click
def back_to_previous_route
header.find(".chat-thread__back-to-previous-route").click
end
def has_no_unread_list_indicator?
has_no_css?(".chat-thread__back-to-list .chat-thread-header-unread-indicator")
has_no_css?(".chat-thread__back-to-previous-route .chat-thread-header-unread-indicator")
end
def has_unread_list_indicator?(count:)
has_css?(
".chat-thread__back-to-list .chat-thread-header-unread-indicator .chat-thread-header-unread-indicator__number",
".chat-thread__back-to-previous-route .chat-thread-header-unread-indicator .chat-thread-header-unread-indicator__number",
text: count.to_s,
)
end

View File

@ -15,6 +15,10 @@ module PageObjects
component.has_no_css?(".spinner")
end
def open_thread(thread)
item_by_id(thread.id).click
end
def has_thread?(thread)
item_by_id(thread.id)
end

View File

@ -40,7 +40,7 @@ describe "Thread tracking state | full page", type: :system do
channel_page.open_thread_list
thread_list_page.item_by_id(thread.id).click
expect(thread_page).to have_no_unread_list_indicator
thread_page.back_to_list
thread_page.back_to_previous_route
expect(thread_list_page).to have_no_unread_item(thread.id)
end