diff --git a/src/tests/fixtures/before_cache.html b/src/tests/fixtures/before_cache.html new file mode 100644 index 000000000..480efa6e7 --- /dev/null +++ b/src/tests/fixtures/before_cache.html @@ -0,0 +1,15 @@ +z + + + + Turbo + + + + +
+

Cache Observer - Before Cache

+ rendering +
+ + diff --git a/src/tests/fixtures/before_cache_home.html b/src/tests/fixtures/before_cache_home.html new file mode 100644 index 000000000..cdceadfc5 --- /dev/null +++ b/src/tests/fixtures/before_cache_home.html @@ -0,0 +1,4 @@ + + home + rendering + diff --git a/src/tests/fixtures/before_cache_in.html b/src/tests/fixtures/before_cache_in.html new file mode 100644 index 000000000..98aa8c215 --- /dev/null +++ b/src/tests/fixtures/before_cache_in.html @@ -0,0 +1,4 @@ + + + in + \ No newline at end of file diff --git a/src/tests/functional/cache_observer_tests.js b/src/tests/functional/cache_observer_tests.js index 99441d6ae..b96058eab 100644 --- a/src/tests/functional/cache_observer_tests.js +++ b/src/tests/functional/cache_observer_tests.js @@ -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) +})