Commit 38413c48 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Implement better version of `scroll_to` QA helper

parent f7036e9a
......@@ -3,8 +3,7 @@ module QA
module Admin
class Settings < Page::Base
def enable_hashed_storage
# TODO need to scroll to "Repository storage" text
scroll_to 'application_setting_clientside_sentry_dsn'
scroll_to 'legend', text: 'Repository Storage'
check 'Create new projects using hashed storage paths'
end
......
......@@ -10,16 +10,17 @@ module QA
visit current_path
end
def scroll_to(selector)
if selector.start_with?('.')
page.execute_script <<~JS
document.getElementsByClassName("#{selector.sub(/^\./, '')}")[0].scrollIntoView();
JS
else
page.execute_script <<~JS
document.getElementById("#{selector}").scrollIntoView();
JS
end
def scroll_to(selector, text: nil)
page.execute_script <<~JS
var elements = Array.from(document.querySelectorAll('#{selector}'));
var text = '#{text}';
if (text.length > 0) {
elements.find(e => e.textContent === text).scrollIntoView();
} else {
elements[0].scrollIntoView();
}
JS
page.within(selector) { yield } if block_given?
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment