mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 20:18:23 -05:00
Previously we were implementing scroll reset/memorization on a per-page basis. Many of these approaches relied on the `didInsertElement` hook, which is no longer appropriate since Discourse changed to use the 'loading slider' strategy for page transitions. This commit rips out all of our custom scroll resetting/memorizing, and implements those things in a generic service. There are two features: 1. After every route transition, scroll to the top of the page 2. When using browser back/forward buttons, restore the last known scroll position for those routes To opt-out of the behaviour, individual routes can add a scrollOnTransition boolean to their RouteInfo metadata using Ember's `buildRouteInfoMetadata` hook.
45 lines
1.0 KiB
Ruby
45 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module PageObjects
|
|
module Components
|
|
class TopicList < PageObjects::Components::Base
|
|
TOPIC_LIST_BODY_SELECTOR = ".topic-list-body"
|
|
TOPIC_LIST_ITEM_SELECTOR = "#{TOPIC_LIST_BODY_SELECTOR} .topic-list-item"
|
|
|
|
def topic_list
|
|
TOPIC_LIST_BODY_SELECTOR
|
|
end
|
|
|
|
def has_topics?(count: nil)
|
|
if count.nil?
|
|
page.has_css?(TOPIC_LIST_ITEM_SELECTOR)
|
|
else
|
|
page.has_css?(TOPIC_LIST_ITEM_SELECTOR, count: count)
|
|
end
|
|
end
|
|
|
|
def has_no_topics?
|
|
page.has_no_css?(TOPIC_LIST_ITEM_SELECTOR)
|
|
end
|
|
|
|
def has_topic?(topic)
|
|
page.has_css?(topic_list_item_class(topic))
|
|
end
|
|
|
|
def has_no_topic?(topic)
|
|
page.has_no_css?(topic_list_item_class(topic))
|
|
end
|
|
|
|
def visit_topic_with_title(title)
|
|
find("#{TOPIC_LIST_BODY_SELECTOR} a", text: title).click
|
|
end
|
|
|
|
private
|
|
|
|
def topic_list_item_class(topic)
|
|
"#{TOPIC_LIST_ITEM_SELECTOR}[data-topic-id='#{topic.id}']"
|
|
end
|
|
end
|
|
end
|
|
end
|