Skip to content

Commit

Permalink
Test async page refreshes (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fernández-Capel committed Feb 2, 2024
1 parent bb9dc70 commit e8d25b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tests/fixtures/page_refresh.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</style>
</head>
<body>
<h1>Page to be refreshed</h1>
<h1 id="title">Page to be refreshed</h1>

<a href="/src/tests/fixtures/page_refresh.html" id="reload-link">Reload</a>

Expand Down
16 changes: 16 additions & 0 deletions src/tests/functional/page_refresh_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ test("renders a page refresh with morphing", async ({ page }) => {
await nextEventNamed(page, "turbo:render", { renderMethod: "morph" })
})

test("async page refresh with turbo-stream", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")

await expect(page.locator("#title")).toHaveText("Page to be refreshed")

await page.evaluate(() => document.querySelector("#title").innerText = "Updated")
await expect(page.locator("#title")).toHaveText("Updated")

await page.evaluate(() => {
document.body.insertAdjacentHTML("beforeend", `<turbo-stream action="refresh"></turbo-stream>`)
})

await expect(page.locator("#title")).not.toHaveText("Updated")
await expect(page.locator("#title")).toHaveText("Page to be refreshed")
})

test("dispatches a turbo:before-morph-element and turbo:morph-element event for each morphed element", async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh.html")
await page.fill("#form-text", "Morph me")
Expand Down

0 comments on commit e8d25b2

Please sign in to comment.