From 1aa94c42d57943dc650ef9bce2460f67a4dd76c2 Mon Sep 17 00:00:00 2001
From: Sean Doyle Navigation
diff --git a/src/tests/functional/navigation_tests.js b/src/tests/functional/navigation_tests.js index c4263d0f3..c4435dd7a 100644 --- a/src/tests/functional/navigation_tests.js +++ b/src/tests/functional/navigation_tests.js @@ -27,19 +27,16 @@ test.beforeEach(async ({ page }) => { await readEventLogs(page) }) -test("test navigating renders a progress bar", async ({ page }) => { - assert.equal( - await page.locator("style").evaluate((style) => style.nonce), - "123", - "renders progress bar stylesheet inline with nonce" - ) - +test("test navigating renders a progress bar until the next turbo:load", async ({ page }) => { await page.evaluate(() => window.Turbo.setProgressBarDelay(0)) await page.click("#delayed-link") await waitUntilSelector(page, ".turbo-progress-bar") assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar") + await nextEventNamed(page, "turbo:render") + assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar") + await nextEventNamed(page, "turbo:load") await waitUntilNoSelector(page, ".turbo-progress-bar") @@ -53,6 +50,22 @@ test("test navigating does not render a progress bar before expiring the delay", assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "does not show progress bar before delay") }) +test("test navigating hides the progress bar on failure", async ({ page }) => { + await page.evaluate(() => window.Turbo.setProgressBarDelay(0)) + await page.click("#delayed-failure-link") + + await waitUntilSelector(page, ".turbo-progress-bar") + assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar") + + await nextEventNamed(page, "turbo:render") + assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar") + + await nextEventNamed(page, "turbo:load") + await waitUntilNoSelector(page, ".turbo-progress-bar") + + assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "hides progress bar") +}) + test("test after loading the page", async ({ page }) => { assert.equal(pathname(page.url()), "/src/tests/fixtures/navigation.html") assert.equal(await visitAction(page), "load") diff --git a/src/tests/server.mjs b/src/tests/server.mjs index 0628f2e30..4c777f87b 100644 --- a/src/tests/server.mjs +++ b/src/tests/server.mjs @@ -74,8 +74,9 @@ router.get("/headers", (request, response) => { }) router.get("/delayed_response", (request, response) => { + const { status } = request.query const fixture = path.join(__dirname, "../../src/tests/fixtures/one.html") - setTimeout(() => response.status(200).sendFile(fixture), 1000) + setTimeout(() => response.status(parseInt(status || "200")).sendFile(fixture), 1000) }) router.post("/messages", (request, response) => {