From 547f0c7578eca4143207aa7cf34f20b898f52140 Mon Sep 17 00:00:00 2001 From: Dom Christie Date: Thu, 21 Sep 2023 18:28:09 +0100 Subject: [PATCH] Dispatch visit events on form elements --- src/core/drive/navigator.js | 1 + src/tests/functional/navigation_tests.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/drive/navigator.js b/src/core/drive/navigator.js index a1d8dbb57..7bdfd5df1 100644 --- a/src/core/drive/navigator.js +++ b/src/core/drive/navigator.js @@ -85,6 +85,7 @@ export class Navigator { const { statusCode, redirected } = fetchResponse const action = this.getActionForFormSubmission(formSubmission) const visitOptions = { + initiator: formSubmission.formElement, action, shouldCacheSnapshot, response: { statusCode, responseHTML, redirected } diff --git a/src/tests/functional/navigation_tests.js b/src/tests/functional/navigation_tests.js index da5f37daa..9fad4407a 100644 --- a/src/tests/functional/navigation_tests.js +++ b/src/tests/functional/navigation_tests.js @@ -494,14 +494,26 @@ test("test ignores forms with a [target] attribute that target an iframe with [n assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html") }) -test("test visit events are dispatched on the initiator", async ({ page }) => { +test("test visit events are dispatched on links", async ({ page }) => { await page.click("#same-origin-unannotated-link") await nextEventOnTarget(page, "same-origin-unannotated-link", "turbo:before-visit") await nextEventOnTarget(page, "same-origin-unannotated-link", "turbo:visit") }) -test("test fetch events are dispatched on the initiator", async ({ page }) => { +test("test visit events are dispatched on forms", async ({ page }) => { + await page.click("#same-origin-unannotated-form button") + await nextEventOnTarget(page, "same-origin-unannotated-form", "turbo:before-visit") + await nextEventOnTarget(page, "same-origin-unannotated-form", "turbo:visit") +}) + +test("test fetch events are dispatched on links", async ({ page }) => { await page.click("#same-origin-unannotated-link") await nextEventOnTarget(page, "same-origin-unannotated-link", "turbo:before-fetch-request") await nextEventOnTarget(page, "same-origin-unannotated-link", "turbo:before-fetch-response") }) + +test("test fetch events are dispatched on forms", async ({ page }) => { + await page.click("#same-origin-unannotated-form button") + await nextEventOnTarget(page, "same-origin-unannotated-form", "turbo:before-fetch-request") + await nextEventOnTarget(page, "same-origin-unannotated-form", "turbo:before-fetch-response") +})