Files
openproject/spec/support/shared/scroll_into_view_helpers.rb
Christophe Bliard 72736f413f Restore direct click and work around issue with other specs
The `./spec/features/work_packages/tabs/relations_children_spec.rb`
works better when using `target.click` instead of
`target.trigger('click')`.

The `./spec/features/work_packages/progress_modal_spec.rb` was scrolling
to the middle of the screen when clicking on the work field to display
the progress popover for some reason.

Then when updating the status field on the work package creation page,
it was made active by clicking it, which displayed the dropdown, and
then it was clicked again for the autocompletion, which scrolled at the
top of the page for some reason. Problem is: the dropdown is fixed and
scrolling up make it overlap the status field, and when calling
`target.click`, Capybara refuses saying that something overlaps it.

The adopted solution is to scroll to the top of the page before updating
the status. Not satisfying, but works.
2025-07-22 08:18:11 +02:00

77 lines
2.8 KiB
Ruby

# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
# Scrolls a native element into view using JS
# @param element [Capybara::Node::Element] the element to scroll into view
# @param block [Symbol] (optional) Defines vertical alignment.
# One of `:start`, `:center`, `:end`, or `:nearest`. Defaults to `:start`.
# @param inline [Symbol] (optional) Defines horizontal alignment.
# One of `:start`, `:center`, `:end`, or `:nearest`. Defaults to `:nearest`..
def scroll_to_element(element, block: :start, inline: :nearest)
script = <<-JS
arguments[0].scrollIntoView({block: "#{block}", inline: "#{inline}"});
JS
if using_cuprite?
page.driver.execute_script(script, element.native)
else
Capybara.current_session.driver.browser.execute_script(script, element.native)
end
end
def scroll_to_and_click(element, block: :start, inline: :nearest)
retry_block do
scroll_to_element(element, block:, inline:)
element.click
end
end
def scroll_to_top
top_element = page.find_by_id("content-body")
page.execute_script("arguments[0].scrollTo(0, 0);", top_element.native)
end
def expect_element_in_view(element)
script = <<-JS
(function(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 && rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
})(arguments[0]);
JS
retry_block do
result = page.evaluate_script(script, element.native)
raise "Expected #{element} to be visible in window, but wasn't." unless result
end
end