The personal finance app for everyone (by everyone)
Ruby
Centre the chart in the resized window before the vertical-swipe test swipes (#5732)
Yong Cong Sin7aac9d428183
diff --git a/test/system/chart_touch_test.rb b/test/system/chart_touch_test.rbindex 640426599c..f1bb1c4a16 100644--- a/test/system/chart_touch_test.rb+++ b/test/system/chart_touch_test.rb@@ -308,7 +308,7 @@ class ChartTouchTest < ApplicationSystemTestCasetest "a vertical swipe on the chart scrolls the page and hides the tooltip" dopage.driver.browser.manage.window.resize_to(1400, 700)- page.execute_script(%(document.querySelector("#{CHART}").scrollIntoView({ block: "center" })))+ center_chart_in_window(height: 700)before = scroll_offsetsstart = chart_point(0.5)@@ -400,6 +400,22 @@ class ChartTouchTest < ApplicationSystemTestCasepage.evaluate_script(%(document.querySelector("#{CHART} > .chart-tooltip").style.opacity)) == "1"end+ # Scrolls the chart to the middle of a window resized to `height`. The new+ # size can reach the page after resize_to returns: centred before it does,+ # the chart sits where the middle of the taller window was, below the+ # bottom of the shorter one, and a touch there lands off screen. So it+ # centres again until the chart is on screen at the new size.+ def center_chart_in_window(height:)+ page.document.synchronize(5) do+ page.execute_script(%(document.querySelector("#{CHART}").scrollIntoView({ block: "center" })))+ box = chart_box+ inner = page.evaluate_script("innerHeight")+ unless inner < height && box["top"] >= 0 && box["top"] + box["height"] <= inner+ raise Capybara::ExpectationNotMet, "the chart is not on screen in the #{height}px window"+ end+ end+ end+# Every scrollable box's offset, since the page scrolls inside the layout.def scroll_offsetspage.evaluate_script(<<~JS)