From 6a361376b7620dda7abf4d9c7b3cfc184d31adce Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 24 Sep 2024 14:53:19 +0200 Subject: [PATCH] failing test to expose issue with turbo-frames changing. --- src/tests/fixtures/frames.html | 3 +++ src/tests/functional/frame_tests.js | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index e6cc19fc7..60f96adef 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -17,6 +17,8 @@ target.closest("turbo-frame")?.setAttribute("refresh", "morph") } else if (target.id == "add-src-to-frame") { target.closest("turbo-frame")?.setAttribute("src", "/src/tests/fixtures/frames.html") + } else if (target.id == "change-frame-id-to-different-nested-child") { + target.closest("turbo-frame")?.setAttribute("id", "different-nested-child") } }) @@ -90,6 +92,7 @@

Frames: #nested-root

Frames: #nested-child

+ Load #nested-child Visit one.html diff --git a/src/tests/functional/frame_tests.js b/src/tests/functional/frame_tests.js index 372381f20..fc1321e52 100644 --- a/src/tests/functional/frame_tests.js +++ b/src/tests/functional/frame_tests.js @@ -306,7 +306,7 @@ test("calling reload on a frame[refresh=morph] morphs the contents", async ({ pa expect(await nextEventOnTarget(page, "frame", "turbo:before-frame-morph")).toBeTruthy() }) -test("calling reload on a frame[refresh=morph] reloads descendant frame[refresh=morph] with morphing", async ({ page }) => { +test("calling reload on a frame[refresh=morph] reloads descendant frame[refresh=morph]s via reload() as well", async ({ page }) => { await page.click("#nested-root #add-refresh-morph-to-frame") await page.click("#nested-root #add-src-to-frame") await page.click("#nested-child #add-refresh-morph-to-frame") @@ -321,6 +321,21 @@ test("calling reload on a frame[refresh=morph] reloads descendant frame[refresh= expect(await noNextEventOnTarget(page, "nested-child-navigate-top", "turbo:before-frame-morph")).toBeTruthy() }) +test("calling reload on a frame[refresh=morph] morphs descendant frame[refresh=morph] normally if the id no longer matches", async ({ page }) => { + await page.click("#nested-root #add-refresh-morph-to-frame") + await page.click("#nested-root #add-src-to-frame") + await page.click("#nested-child #add-refresh-morph-to-frame") + await page.click("#nested-child #add-src-to-frame") + await page.click("#nested-child #change-frame-id-to-different-nested-child") + + await page.evaluate(() => document.getElementById("nested-root").reload()) + + expect(await nextEventOnTarget(page, "nested-root", "turbo:before-frame-morph")).toBeTruthy() + expect(await noNextEventOnTarget(page, "different-nested-child", "turbo:before-frame-morph")).toBeTruthy() + assert.ok(await hasSelector(page, "#nested-child")) + assert.notOk(await hasSelector(page, "#different-nested-child")) +}) + test("calling reload on a frame[refresh=morph] preserves [data-turbo-permanent] elements", async ({ page }) => { await page.click("#add-src-to-frame") await page.click("#add-refresh-morph-to-frame")