From f8ac6c688f526afa6fe1828805ab340070a12bc1 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Mon, 18 Jul 2022 00:13:40 -0400 Subject: [PATCH] Add tests for pausable Frame Rendering Follow-up to https://github.com/hotwired/turbo/pull/431 Support for the `turbo:before-frame-render` event relies on the same underlying infrastructure as the `turbo:before-render` event (i.e. the `Renderer` abstract class). As a result of re-using that abstraction, listeners for the `turbo:before-frame-render` event can also leverage the `detail.resume` function in the same way to handle asynchronous rendering. The changes made in [hotwired/turbo#431][] excluded test coverage for that behavior. This commit adds that coverage to guard against regressions in that behvaior. [hotwired/turbo#431]: https://github.com/hotwired/turbo/pull/431 --- src/tests/fixtures/pausable_rendering.html | 24 +++++++++++------ .../functional/pausable_rendering_tests.ts | 27 +++++++++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/tests/fixtures/pausable_rendering.html b/src/tests/fixtures/pausable_rendering.html index 2894afb39..9c453a8e1 100644 --- a/src/tests/fixtures/pausable_rendering.html +++ b/src/tests/fixtures/pausable_rendering.html @@ -6,20 +6,28 @@

Pausable Rendering

Link

+ + +

Pausable Frame Rendering

+ + #hello Frame Link +
diff --git a/src/tests/functional/pausable_rendering_tests.ts b/src/tests/functional/pausable_rendering_tests.ts index 2e3c307a0..31a5e2b23 100644 --- a/src/tests/functional/pausable_rendering_tests.ts +++ b/src/tests/functional/pausable_rendering_tests.ts @@ -32,3 +32,30 @@ test("test aborts rendering", async ({ page }) => { assert.equal(await page.textContent("h1"), "Pausable Rendering") }) + +test("test pauses and resumes rendering a Frame", async ({ page }) => { + page.on("dialog", (dialog) => { + assert.strictEqual(dialog.message(), "Continue rendering?") + dialog.accept() + }) + + await page.click("#frame-link") + await nextBeat() + + assert.equal(await page.textContent("#hello h2"), "Hello from a frame") +}) + +test("test aborts rendering a Frame", async ({ page }) => { + const [firstDialog] = await Promise.all([page.waitForEvent("dialog"), page.click("#frame-link")]) + + assert.strictEqual(firstDialog.message(), "Continue rendering?") + + firstDialog.dismiss() + + const nextDialog = await page.waitForEvent("dialog") + + assert.strictEqual(nextDialog.message(), "Rendering aborted") + nextDialog.accept() + + assert.equal(await page.textContent("#hello h2"), "Pausable Frame Rendering") +})