Skip to content

Commit

Permalink
Add test coverage from hotwired#793
Browse files Browse the repository at this point in the history
The issues outlined by [hotwired#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#793]: hotwired#793
  • Loading branch information
seanpdoyle committed Dec 18, 2022
1 parent 820e7bd commit d10b72b
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/tests/functional/frame_navigation_tests.ts
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down Expand Up @@ -146,3 +153,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")
})

0 comments on commit d10b72b

Please sign in to comment.