From 100b4b9c07681946c906c02c966a00e39ec7b3d7 Mon Sep 17 00:00:00 2001 From: Ryan Lynch Date: Tue, 19 Sep 2023 12:45:02 -0400 Subject: [PATCH] Tests #1008 --- src/tests/fixtures/before_cache.html | 15 +++++++++ src/tests/fixtures/before_cache_home.html | 4 +++ src/tests/fixtures/before_cache_in.html | 4 +++ src/tests/functional/cache_observer_tests.js | 35 ++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 src/tests/fixtures/before_cache.html create mode 100644 src/tests/fixtures/before_cache_home.html create mode 100644 src/tests/fixtures/before_cache_in.html 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) +})