Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix turbo-confirm for links without a turbo-method #1266

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/observers/form_link_click_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class FormLinkClickObserver {
willFollowLinkToLocation(link, location, originalEvent) {
return (
this.delegate.willSubmitFormLinkToLocation(link, location, originalEvent) &&
(link.hasAttribute("data-turbo-method") || link.hasAttribute("data-turbo-stream"))
(link.hasAttribute("data-turbo-method") || link.hasAttribute("data-turbo-stream") || link.hasAttribute("data-turbo-confirm"))
)
}

Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/drive.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Drive</h1>

<div>
<a id="drive_enabled" href="/src/tests/fixtures/drive.html">Drive enabled link</a>
<a id="drive_enabled_with_confirm" href="/src/tests/fixtures/drive.html?confirmed=true" data-turbo-confirm="Are you sure?">Drive enabled link with confirm</a>
<a id="drive_enabled_external" href="https://example.com">Drive enabled external link</a>
</div>

Expand Down
24 changes: 23 additions & 1 deletion src/tests/functional/drive_tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextBody, pathname, visitAction } from "../helpers/page"
import { nextBody, pathname, visitAction, search } from "../helpers/page"

const path = "/src/tests/fixtures/drive.html"

Expand Down Expand Up @@ -33,3 +33,25 @@ test("drive enabled by default; click link inside data-turbo='false'", async ({
assert.equal(pathname(page.url()), path)
assert.equal(await visitAction(page), "load")
})

test("link with confirmation without method confirmed", async ({ page }) => {
page.on("dialog", (alert) => {
assert.equal(alert.message(), "Are you sure?")
alert.accept()
})

await page.click("#drive_enabled_with_confirm")
await nextBody(page)
assert.equal(search(page.url()), "?confirmed=true")
})

test("link with confirmation without method cancelled", async ({ page }) => {
page.on("dialog", (alert) => {
assert.equal(alert.message(), "Are you sure?")
alert.dismiss()
})

await page.click("#drive_enabled_with_confirm")
await nextBody(page)
assert.notEqual(search(page.url()), "?confirmed=true")
})