diff --git a/cypress/integration/basic_spec.js b/cypress/integration/basic_spec.js index 6e0a5117..1c3c6528 100644 --- a/cypress/integration/basic_spec.js +++ b/cypress/integration/basic_spec.js @@ -72,46 +72,32 @@ describe('Basic assertions', function () { }) it('should debounce onCropComplete during a burst of window resizes', function () { - // let a real frame elapse so the ResizeObserver notification for this - // resize has actually been delivered (mirrors cy.setViewportStable above) - const settle = () => - cy.window().then( - (win) => - new Cypress.Promise((resolve) => { - win.requestAnimationFrame(() => win.requestAnimationFrame(() => resolve())) - }) - ) const countOnCropComplete = (spy) => spy.getCalls().filter((call) => call.args[0] === 'onCropComplete!').length - // let the initial mount settle first so its own onCropComplete call - // doesn't get counted as part of the resize burst below - settle() + cy.get('#crop-area-x').should('contain', '15') + cy.window().then((win) => { cy.spy(win.console, 'log').as('consoleLog') }) - // freeze only the debounce timer itself (not rAF/Date), so ResizeObserver - // notifications are still delivered for real via the settle() waits below, - // but the resulting debounce timeout only fires when we call cy.tick cy.clock(Date.now(), ['setTimeout', 'clearTimeout']) - // several resizes in a row, simulating dragging the window edge - cy.viewport(700, 600) - settle() - cy.viewport(800, 650) - settle() - cy.viewport(900, 700) - settle() + let callCountBeforeResize = 0 + cy.get('@consoleLog').then((spy) => { + callCountBeforeResize = countOnCropComplete(spy) + }) + + cy.setViewportStable(700, 600) + cy.setViewportStable(800, 650) + cy.setViewportStable(900, 700) - // right after the burst, onCropComplete should still be debounced (not fired yet) cy.get('@consoleLog').should((spy) => { - expect(countOnCropComplete(spy)).to.eq(0) + expect(countOnCropComplete(spy)).to.eq(callCountBeforeResize) }) - // once the debounce window elapses, it should have fired exactly once for the whole burst cy.tick(260) cy.get('@consoleLog').should((spy) => { - expect(countOnCropComplete(spy)).to.eq(1) + expect(countOnCropComplete(spy)).to.eq(callCountBeforeResize + 1) }) }) })