From 00c81a9b6f6f6e1d6b8c2e4ec44ed755af9afdc1 Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Mon, 21 Nov 2022 11:03:16 -0500 Subject: [PATCH] Add test coverage from #793 The issues outlined by [hotwired/turbo#793][] are resolved by the introduction of the `FrameVisit` object and its lifecycle. To ensure that behavior is fixed, this commit cherry-picks the test coverage introduced in that branch. [hotwired/turbo#793]: https://github.com/hotwired/turbo/pull/793 --- .../functional/frame_navigation_tests.ts | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/tests/functional/frame_navigation_tests.ts b/src/tests/functional/frame_navigation_tests.ts index 3a2fadde1..ac6eb0317 100644 --- a/src/tests/functional/frame_navigation_tests.ts +++ b/src/tests/functional/frame_navigation_tests.ts @@ -1,5 +1,12 @@ import { test } from "@playwright/test" -import { getFromLocalStorage, nextEventNamed, nextEventOnTarget, pathname, scrollToSelector } from "../helpers/page" +import { + getFromLocalStorage, + nextBeat, + nextEventNamed, + nextEventOnTarget, + pathname, + scrollToSelector, +} from "../helpers/page" import { assert } from "chai" test("test frame navigation with descendant link", async ({ page }) => { @@ -97,3 +104,38 @@ test("test promoted frame navigations are cached", async ({ page }) => { assert.equal(await page.getAttribute("#tab-frame", "src"), null, "caches one.html without #tab-frame[src]") assert.equal(await page.getAttribute("#tab-frame", "complete"), null, "caches one.html without [complete]") }) + +test("test canceling frame requests don't mutate the history", async ({ page }) => { + await page.goto("/src/tests/fixtures/tabs.html") + + await page.click("#tab-2") + + await nextEventOnTarget(page, "tab-frame", "turbo:frame-load") + await nextEventNamed(page, "turbo:load") + + assert.equal(await page.textContent("#tab-content"), "Two") + assert.equal(pathname((await page.getAttribute("#tab-frame", "src")) || ""), "/src/tests/fixtures/tabs/two.html") + assert.equal(await page.getAttribute("#tab-frame", "complete"), "", "sets [complete]") + + // This request will be canceled + page.click("#tab-1") + await page.click("#tab-3") + + await nextEventOnTarget(page, "tab-frame", "turbo:frame-load") + await nextEventNamed(page, "turbo:load") + + assert.equal(await page.textContent("#tab-content"), "Three") + assert.equal(pathname((await page.getAttribute("#tab-frame", "src")) || ""), "/src/tests/fixtures/tabs/three.html") + + await page.goBack() + await nextEventNamed(page, "turbo:load") + + assert.equal(await page.textContent("#tab-content"), "Two") + assert.equal(pathname((await page.getAttribute("#tab-frame", "src")) || ""), "/src/tests/fixtures/tabs/two.html") + + // Make sure the frame is not mutated after some time. + await nextBeat() + + assert.equal(await page.textContent("#tab-content"), "Two") + assert.equal(pathname((await page.getAttribute("#tab-frame", "src")) || ""), "/src/tests/fixtures/tabs/two.html") +})