Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftyp committed Sep 19, 2023
1 parent 32cadc0 commit 4ae5fe0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/tests/fixtures/before_cache.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
z<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Turbo</title>
<script src="/dist/turbo.es2017-umd.js" data-turbo-track="reload"></script>
<script src="/src/tests/fixtures/test.js"></script>
</head>
<body>
<section>
<h1>Cache Observer - Before Cache</h1>
<a id="advance-home" href="/src/tests/fixtures/before_cache_home.html?in_frame=n">rendering</a>
</section>
</body>
</html>
4 changes: 4 additions & 0 deletions src/tests/fixtures/before_cache_home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<turbo-frame data-turbo-frame="main-frame" data-turbo-action="advance" id="frame">
<span id="origin">home</span>
<a id="advance-in" href="/src/tests/fixtures/before_cache_in.html?in_frame=y">rendering</a>
</turbo-frame>
4 changes: 4 additions & 0 deletions src/tests/fixtures/before_cache_in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<turbo-frame data-turbo-frame="main-frame" data-turbo-action="advance" id="frame">
<span id="origin">in</span>
</turbo-frame>
35 changes: 35 additions & 0 deletions src/tests/functional/cache_observer_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,38 @@ test("test following a redirect renders [data-turbo-temporary] elements before t

assert.equal(await page.textContent("#temporary"), "data-turbo-temporary")
})

test("test before cache content should reflect page content prior to navigation for links outside advance turbo frames", async ({ page }) => {
await page.goto("/src/tests/fixtures/before_cache.html?start=y")
await page.evaluate(() => {
document.addEventListener("turbo:before-cache", () => {
console.log(`before-cache ${JSON.stringify(window.location.search)} ${document.querySelector('#origin')?.innerText}`)
})
})

page.addListener("console", (message) => {
assert.equal(message.text(), `before-cache "?start=y" undefined`)
})

await page.click("#advance-home")
await nextBody(page)
})

test("test before cache content should reflect page content prior to navigation for links inside advance turbo frames", async ({ page }) => {
await page.goto("/src/tests/fixtures/before_cache.html?")
await page.click("#advance-home")
await nextBody(page)

await page.evaluate(() => {
document.addEventListener("turbo:before-cache", () => {
console.log(`before-cache ${JSON.stringify(window.location.search)} ${document.querySelector('#origin')?.innerText}`)
})
})

page.addListener("console", (message) => {
assert.equal(message.text(), `before-cache "?home=y" home`)
})

await page.click("#advance-in")
await nextBody(page)
})

0 comments on commit 4ae5fe0

Please sign in to comment.