The personal finance app for everyone (by everyone)
Ruby
Bring back the page-scroll check in the vertical-swipe touch test (#5775)
Yong Cong Sina91360864007
diff --git a/test/system/chart_touch_test.rb b/test/system/chart_touch_test.rbindex b97eee49d3..5a41fe1dac 100644--- a/test/system/chart_touch_test.rb+++ b/test/system/chart_touch_test.rb@@ -306,11 +306,9 @@ class ChartTouchTest < ApplicationSystemTestCaseassert_nil URI.parse(page.current_url).queryend- # After a vertical swipe, scrolling the page is the browser's job, not the- # chart's, and a headless browser does not do it reliably enough to assert- # on. The chart's part is to leave vertical movement to the browser and not- # to take the swipe for a scrub or a selection.- test "a vertical swipe on the chart is left to the browser and shows no tooltip" do+ test "a vertical swipe on the chart scrolls the page and shows no tooltip" do+ center_chart_in_layout+ before = scroll_offsetsstart = chart_point(0.5)touch("touchStart", start)@@ -319,6 +317,9 @@ class ChartTouchTest < ApplicationSystemTestCaseassert_equal "pan-y pinch-zoom", page.evaluate_script(%(getComputedStyle(document.querySelector("#{CHART} svg")).touchAction)),"the chart takes horizontal slides and leaves vertical scrolling and pinch zoom to the browser"+ page.document.synchronize(5) do+ raise Capybara::ExpectationNotMet, "the page did not scroll" if scroll_offsets == before+ endassert_not tooltip_visible?, "a vertical swipe showed the tooltip"assert_no_selector "#{CHART} .touch-selection", visible: :allassert_equal "/", URI.parse(page.current_url).path@@ -399,4 +400,26 @@ class ChartTouchTest < ApplicationSystemTestCase# Shown and hidden through its inline opacity (the class starts it hidden).page.evaluate_script(%(document.querySelector("#{CHART} > .chart-tooltip").style.opacity)) == "1"end++ # Scrolls the chart to the middle of the page's scrolling area. The layout+ # takes its height from --app-height, which viewport_controller.js sets+ # only when the window's resize event arrives, after the window has its+ # new size. Centred before then, the chart is brought into view by+ # scrolling the document rather than the page's scrolling area, and drops+ # back below the fold once the layout catches up. So it waits for the+ # layout to have the window's height first.+ def center_chart_in_layout+ page.document.synchronize(5) do+ laid_out = page.evaluate_script(%(document.documentElement.style.getPropertyValue("--app-height") === `${innerHeight}px`))+ raise Capybara::ExpectationNotMet, "the layout does not have the window's height yet" unless laid_out+ end+ page.execute_script(%(document.querySelector("#{CHART}").scrollIntoView({ block: "center" })))+ end++ # Every scrollable box's offset, since the page scrolls inside the layout.+ def scroll_offsets+ page.evaluate_script(<<~JS)+ [document.scrollingElement.scrollTop, ...Array.from(document.querySelectorAll("*")).filter((el) => el.scrollHeight > el.clientHeight && /auto|scroll/.test(getComputedStyle(el).overflowY)).map((el) => el.scrollTop)]+ JS+ endend