From 59c952076ba488ff13d91d49585a8d750b6ffaa6 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 | 22 ++++++++++------- .../functional/pausable_rendering_tests.ts | 24 +++++++++++++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/tests/fixtures/pausable_rendering.html b/src/tests/fixtures/pausable_rendering.html index 2894afb39..d80a5158d 100644 --- a/src/tests/fixtures/pausable_rendering.html +++ b/src/tests/fixtures/pausable_rendering.html @@ -6,20 +6,26 @@

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..d55f0128c 100644 --- a/src/tests/functional/pausable_rendering_tests.ts +++ b/src/tests/functional/pausable_rendering_tests.ts @@ -25,10 +25,26 @@ test("test aborts rendering", async ({ page }) => { firstDialog.dismiss() - const nextDialog = await page.waitForEvent("dialog") + assert.equal(await page.textContent("h1"), "Pausable Rendering") +}) - assert.strictEqual(nextDialog.message(), "Rendering aborted") - nextDialog.accept() +test("test pauses and resumes rendering a Frame", async ({ page }) => { + page.on("dialog", (dialog) => { + assert.strictEqual(dialog.message(), "Continue rendering?") + dialog.accept() + }) - assert.equal(await page.textContent("h1"), "Pausable Rendering") + 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 }) => { + page.on("dialog", (dialog) => { + assert.strictEqual(dialog.message(), "Continue rendering?") + dialog.dismiss() + }) + + assert.equal(await page.textContent("#hello h2"), "Pausable Frame Rendering") })