Skip to content

Commit

Permalink
added failing test: debounced refresh of stale URL does not hijack ne…
Browse files Browse the repository at this point in the history
…w location navigated to
  • Loading branch information
klevo committed Apr 23, 2024
1 parent 8e10279 commit bfca516
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/tests/fixtures/page_refresh_stream_action.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<div id="content">
<span>Hello</span>
<a id="regular-link" href="/src/tests/fixtures/one.html">Regular link</a>
</div>
</body>
</html>
19 changes: 18 additions & 1 deletion src/tests/functional/page_refresh_stream_action_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextPageRefresh, readEventLogs } from "../helpers/page"
import { nextPageRefresh, readEventLogs, pathname } from "../helpers/page"

test.beforeEach(async ({ page }) => {
await page.goto("/src/tests/fixtures/page_refresh_stream_action.html")
Expand Down Expand Up @@ -54,6 +54,19 @@ test("debounce stream page refreshes", async ({ page }) => {
assert.equal(requestLogs.length, 2)
})

test("debounced refresh of stale URL does not hijack new location navigated to", async ({ page }) => {
const urlBeforeVisit = page.url()

await page.click("#refresh button")
await page.click("#regular-link")
await nextPageRefresh(page)

const urlAfterVisit = page.url()
assert.notEqual(urlBeforeVisit, urlAfterVisit)
const expectedPath = "/src/tests/fixtures/one.html"
assert.equal(pathname(urlAfterVisit), expectedPath)
})

async function textContent(page) {
const messages = await page.locator("#content")
return await messages.textContent()
Expand All @@ -65,3 +78,7 @@ async function fetchRequestId(page) {
return response.text()
})
}

async function visitLocation(page, location) {
return page.evaluate((location) => window.Turbo.visit(location), location)
}

0 comments on commit bfca516

Please sign in to comment.