2023-07-13 10:23:36 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
describe "Topic list focus", type: :system do
|
2023-08-07 17:05:16 -04:00
|
|
|
fab!(:topics) { Fabricate.times(10, :post).map(&:topic) }
|
2023-07-13 10:23:36 -04:00
|
|
|
|
2023-08-07 17:05:16 -04:00
|
|
|
before_all do
|
|
|
|
sidebar_url = Fabricate(:sidebar_url, name: "my topic link", value: "/t/#{topics[4].id}")
|
|
|
|
|
|
|
|
Fabricate(
|
|
|
|
:sidebar_section_link,
|
|
|
|
sidebar_section:
|
|
|
|
SidebarSection.find_by(section_type: SidebarSection.section_types[:community]),
|
|
|
|
linkable: sidebar_url,
|
|
|
|
)
|
|
|
|
end
|
2023-07-13 10:23:36 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2023-12-08 11:06:21 -05:00
|
|
|
def focussed_post_id
|
|
|
|
page.evaluate_script("document.activeElement.closest('.onscreen-post')?.dataset.postId")&.to_i
|
|
|
|
end
|
|
|
|
|
2023-07-13 10:23:36 -04:00
|
|
|
it "refocusses last clicked topic when going back to topic list" do
|
2023-08-07 17:05:16 -04:00
|
|
|
visit("/latest")
|
2023-07-13 10:23:36 -04:00
|
|
|
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
|
2023-08-07 17:05:16 -04:00
|
|
|
|
|
|
|
it "refocusses properly when navigating via the 'last activity' link" do
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
# Visit topic via activity column and keyboard
|
|
|
|
discovery.topic_list.visit_topic_last_reply_via_keyboard(topics[2])
|
|
|
|
expect(topic).to have_topic_title(topics[2].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[2].id)
|
|
|
|
|
|
|
|
# Visit topic via keyboard using posts map (OP button)
|
|
|
|
discovery.topic_list.visit_topic_first_reply_via_keyboard(topics[4])
|
|
|
|
expect(topic).to have_topic_title(topics[4].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[4].id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not refocus topic when visiting via something other than topic list" do
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
# Clicking sidebar link should visit topic
|
|
|
|
find(".sidebar-section-link[data-link-name='my topic link']").click
|
|
|
|
expect(topic).to have_topic_title(topics[4].title)
|
|
|
|
|
|
|
|
# Going back to the topic-list should not re-focus
|
|
|
|
page.go_back
|
|
|
|
expect(page).to have_css("body.navigation-topics")
|
|
|
|
expect(focussed_topic_id).to eq(nil)
|
|
|
|
end
|
2023-11-22 09:25:52 -05:00
|
|
|
|
|
|
|
it "refocusses properly when there are multiple pages of topics" do
|
|
|
|
extra_topics = Fabricate.times(25, :post).map(&:topic)
|
|
|
|
oldest_topic = Fabricate(:post).topic
|
|
|
|
oldest_topic.update(bumped_at: 1.day.ago)
|
|
|
|
|
|
|
|
visit("/latest")
|
|
|
|
|
|
|
|
# Scroll to bottom for infinite load
|
|
|
|
page.execute_script <<~JS
|
|
|
|
document.querySelectorAll('.topic-list-item')[24].scrollIntoView(true);
|
|
|
|
JS
|
|
|
|
|
|
|
|
# Click a topic
|
|
|
|
discovery.topic_list.visit_topic(oldest_topic)
|
|
|
|
expect(topic).to have_topic_title(oldest_topic.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(oldest_topic.id)
|
|
|
|
end
|
2023-07-13 10:23:36 -04:00
|
|
|
end
|