From c6f82a57117d7ed4d75ab37e0c847a7de2c9c514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Fern=C3=A1ndez-Capel?= Date: Fri, 17 Nov 2023 13:50:08 +0000 Subject: [PATCH] Read the mutation logs to assert the direction attribute change It's less dependent on the timing of the mutation. Even if the attribute is no longer present, we can still assert that it was present at some point. --- src/tests/functional/visit_tests.js | 8 +++++--- src/tests/helpers/page.js | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/tests/functional/visit_tests.js b/src/tests/functional/visit_tests.js index fb44ab8ef..31a11141a 100644 --- a/src/tests/functional/visit_tests.js +++ b/src/tests/functional/visit_tests.js @@ -6,15 +6,16 @@ import { getSearchParam, isScrolledToSelector, isScrolledToTop, + nextAttributeMutationNamed, nextBeat, nextEventNamed, noNextAttributeMutationNamed, pathname, readEventLogs, + resetMutationLogs, scrollToSelector, visitAction, waitUntilNoSelector, - waitUntilSelector, willChangeBody } from "../helpers/page" @@ -224,7 +225,6 @@ test("test Visit with network error", async ({ page }) => { test("Visit direction data attribute when clicking a link", async ({ page }) => { page.click("#same-origin-link") - await assertVisitDirectionAttribute(page, "forward") }) @@ -232,6 +232,8 @@ test("Visit direction data attribute when navigating back", async ({ page }) => await page.click("#same-origin-link") await nextEventNamed(page, "turbo:load") + await resetMutationLogs(page) + page.goBack() await assertVisitDirectionAttribute(page, "back") @@ -270,6 +272,6 @@ async function visitLocation(page, location) { } async function assertVisitDirectionAttribute(page, direction) { - await waitUntilSelector(page, `[data-turbo-visit-direction='${direction}']`) + assert.equal(await nextAttributeMutationNamed(page, "html", "data-turbo-visit-direction"), direction) await waitUntilNoSelector(page, "[data-turbo-visit-direction]") } diff --git a/src/tests/helpers/page.js b/src/tests/helpers/page.js index 580327d25..5d203681b 100644 --- a/src/tests/helpers/page.js +++ b/src/tests/helpers/page.js @@ -162,6 +162,12 @@ export function propertyForSelector(page, selector, propertyName) { return page.locator(selector).evaluate((element, propertyName) => element[propertyName], propertyName) } +export function resetMutationLogs(page) { + return page.evaluate(() => { + window.mutationLogs = [] + }) +} + async function readArray(page, identifier, length) { return page.evaluate( ({ identifier, length }) => {