Issue #3591609: Fix flaky undo-redo.cy.js and assert undo/redo for real
Fixes the intermittent failure of undo-redo.cy.js and makes its undo/redo assertions actually run. See #3591609 (closed) for the full analysis.
Root cause (two test-side problems)
- The hero-count checks used
cy.getIframeBody().find(selector, callback), but.find()'s second argument is an options object, not a callback — so the4 → 3 → 4counts were never asserted. The test only verified that some hero existed and would pass even if undo/redo did nothing. - Each insert/undo/redo re-renders the preview asynchronously and swaps the iframe; during the swap there is a brief window with no
data-canvas-swap-activeiframe, so a default-timeout query caught the swap gap or a stale frame.
Changes
- Add a
waitForElementCountInIframe()command that re-queries the currently active preview iframe on every retry and resolves once the count settles, so it rides through the iframe swap. - Use it to assert the hero count
4 → 3 → 4across insert/undo/redo, so the assertions now genuinely run.
Validation
Ran undo-redo.cy.js locally 5×: 5/5 clean passes, with the assertions now actually executing.
AI usage
Developed with AI assistance (Claude / Claude Code). All changes were reviewed and validated locally by the contributor.