The personal finance app for everyone (by everyone)
Ruby
Fix stale chart animation test after sidebar resize changes (#5321)
Sure Admin (bot)7b68e1072f2e
diff --git a/test/system/chart_sidebar_resize_test.rb b/test/system/chart_sidebar_resize_test.rbindex c4fdab819c..2fa44f05cd 100644--- a/test/system/chart_sidebar_resize_test.rb+++ b/test/system/chart_sidebar_resize_test.rb@@ -505,26 +505,28 @@ class ChartSidebarResizeTest < ApplicationSystemTestCasepage.driver.browser.manage.window.resize_to(1100, 900) rescue nilend- # Resizing a sidebar from the keyboard (or resetting it) changes its- # max-width, which animates too: its end must redraw the chart at once, not- # a settle delay after the sidebar has stopped.- test "a sidebar's max-width animation redraws the chart as it ends" do- result = page.evaluate_async_script(<<~JS)- const done = arguments[0];+ # Opening or closing a sidebar animates its width; keyboard resizing and+ # resetting max-width apply immediately. The animated toggle must redraw+ # the chart at its end, not a settle delay after the sidebar has stopped.+ test "a sidebar toggle redraws the chart as its width animation ends" do+ page.execute_script(<<~JS)const chart = document.querySelector("#{NET_WORTH}");const sidebar = document.querySelector("[data-app-layout-target='leftSidebar']");- let ended = null; let drawn = null;- sidebar.addEventListener("transitionend", (event) => { if (event.propertyName === "max-width") ended ??= performance.now(); });+ window.__sidebarResize = { ended: null, drawn: null };+ sidebar.addEventListener("transitionend", (event) => {+ if (event.target === sidebar && event.propertyName === "width") window.__sidebarResize.ended ??= performance.now();+ });new MutationObserver((mutations) => {- if (ended !== null && drawn === null && mutations.some((m) => Array.from(m.addedNodes).some((n) => n.nodeName === "svg"))) drawn = performance.now();+ const result = window.__sidebarResize;+ if (result.ended !== null && result.drawn === null && mutations.some((m) => Array.from(m.addedNodes).some((n) => n.nodeName === "svg"))) result.drawn = performance.now();}).observe(chart, { childList: true, subtree: true });- // 60px narrower than it is now, as an arrow key or a reset would.- const width = Math.round(sidebar.getBoundingClientRect().width) - 60;- document.querySelector("[data-controller~='sidebar-resize']").style.setProperty("--left-sidebar-width", `${width}px`);- setTimeout(() => done({ ended, drawn }), 1200);JS+ before = net_worth_width+ toggle_left_sidebar+ wait_until_settled(changed_from: before)- assert result["ended"], "the sidebar's max-width never animated: #{result.inspect}"+ result = page.evaluate_script("window.__sidebarResize")+ assert result["ended"], "the sidebar's width never animated: #{result.inspect}"assert result["drawn"], "the chart was not redrawn after the animation: #{result.inspect}"assert_operator result["drawn"] - result["ended"], :<, 80, "the chart waited out the settle delay after the sidebar stopped: #{result.inspect}"end