mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Only use lastViewedTopic when going 'back' to a topic list (#22594)
Using the lastViewedTopicId indiscriminately can cause strange scrolling behavior when navigating to a **different** topic list after viewing a topic. We only want to refocus the topic when going 'back' to the same topic list which originally triggered the navigation.
This commit is contained in:
@@ -34,6 +34,10 @@ module PageObjects
|
||||
find("#{TOPIC_LIST_BODY_SELECTOR} a", text: title).click
|
||||
end
|
||||
|
||||
def visit_topic(topic)
|
||||
find("#{topic_list_item_class(topic)} a.raw-topic-link").click
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_list_item_class(topic)
|
||||
|
||||
40
spec/system/topic_list_focus_spec.rb
Normal file
40
spec/system/topic_list_focus_spec.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe "Topic list focus", type: :system do
|
||||
let!(:topics) { Fabricate.times(10, :post).map(&:topic) }
|
||||
|
||||
before { Fabricate(:admin) }
|
||||
|
||||
let(:discovery) { PageObjects::Pages::Discovery.new }
|
||||
let(:topic) { PageObjects::Pages::Topic.new }
|
||||
|
||||
def focussed_topic_id
|
||||
page.evaluate_script(
|
||||
"document.activeElement.closest('.topic-list-item')?.dataset.topicId",
|
||||
)&.to_i
|
||||
end
|
||||
|
||||
it "refocusses last clicked topic when going back to topic list" do
|
||||
visit("/")
|
||||
expect(page).to have_css("body.navigation-topics")
|
||||
expect(discovery.topic_list).to have_topics
|
||||
|
||||
# Click a topic
|
||||
discovery.topic_list.visit_topic(topics[5])
|
||||
expect(topic).to have_topic_title(topics[5].title)
|
||||
|
||||
# Going back to the topic-list should re-focus
|
||||
page.go_back
|
||||
expect(page).to have_css("body.navigation-topics")
|
||||
expect(focussed_topic_id).to eq(topics[5].id)
|
||||
|
||||
# Click topic again
|
||||
discovery.topic_list.visit_topic(topics[5])
|
||||
expect(topic).to have_topic_title(topics[5].title)
|
||||
|
||||
# Visiting a topic list another way should not focus
|
||||
find(".sidebar-section-link[data-link-name='everything']").click
|
||||
expect(page).to have_css("body.navigation-topics")
|
||||
expect(focussed_topic_id).to eq(nil)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user