Skip to content

Commit

Permalink
Dispatch visit events on form elements
Browse files Browse the repository at this point in the history
  • Loading branch information
domchristie committed Sep 21, 2023
1 parent 7a5dfd6 commit 547f0c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/drive/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 14 additions & 2 deletions src/tests/functional/navigation_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

0 comments on commit 547f0c7

Please sign in to comment.