Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Assert what the chart controls in the vertical-swipe touch test (#5773)

Yong Cong Sin76550af0b7b3
diff --git a/test/system/chart_touch_test.rb b/test/system/chart_touch_test.rb
index f1bb1c4a16..b97eee49d3 100644
--- a/test/system/chart_touch_test.rb
+++ b/test/system/chart_touch_test.rb
@@ -306,10 +306,11 @@ class ChartTouchTest < ApplicationSystemTestCase
assert_nil URI.parse(page.current_url).query
end
- test "a vertical swipe on the chart scrolls the page and hides the tooltip" do
- page.driver.browser.manage.window.resize_to(1400, 700)
- center_chart_in_window(height: 700)
- before = scroll_offsets
+ # 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
start = chart_point(0.5)
touch("touchStart", start)
@@ -318,8 +319,7 @@ class ChartTouchTest < ApplicationSystemTestCase
assert_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"
- assert_not_equal before, scroll_offsets, "the page did not scroll"
- assert_not tooltip_visible?, "the tooltip stayed after the page scrolled"
+ assert_not tooltip_visible?, "a vertical swipe showed the tooltip"
assert_no_selector "#{CHART} .touch-selection", visible: :all
assert_equal "/", URI.parse(page.current_url).path
end
@@ -399,27 +399,4 @@ 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 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_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
- end
end