Skip to content

Commit

Permalink
Add test coverage for turbo-frame[disabled]
Browse files Browse the repository at this point in the history
Support for the `[disabled]` attribute pre-dates this commit, but is
largely untested. Prior to [hotwired/turbo-site#32][] and
[hotwired/turbo-site#36][], there were no mentions of the attribute in
the Turbo [Handbook][] or [Reference][] documentation.

This commit adds functional test-level coverage for the existing
behavior. When an `<a>` or `<form>` element targets a `<turbo-frame
disabled>` element, Turbo skips intercepting and intervening, and
instead navigates the page.

Testing
---

In addition, to avoid conflating `[data-turbo="false"]` and
`<turbo-frame disabled>`, this commit also renames test and test fixture
mentions of "disabled" to more accurately reflect which manner of
skipping behavior is being tested.

[Handbook]: https://github.com/hotwired/turbo-site/blob/52d5e7f1dfc26ac7a6e01c6a715857ccf5ed5081/docs/handbook/03_frames.md
[Reference]: https://github.com/hotwired/turbo-site/blob/52d5e7f1dfc26ac7a6e01c6a715857ccf5ed5081/docs/reference/frames.md
[hotwired/turbo-site#32]: hotwired/turbo-site#32
[hotwired/turbo-site#36]: hotwired/turbo-site#36
  • Loading branch information
seanpdoyle committed Jan 19, 2021
1 parent 178c817 commit d4e9d4c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</form>
</div>
<hr>
<div id="disabled">
<div id="turbo-false">
<form action="/__turbo/redirect" method="post" data-turbo="false">
<input type="hidden" name="path" value="/src/tests/fixtures/one.html">
<input type="submit">
Expand All @@ -72,6 +72,12 @@
</dialog>
</div>
<hr>
<div id="targets-frame">
<form action="/__turbo/redirect" method="post" data-turbo-frame="frame">
<input type="hidden" name="path" value="/src/tests/fixtures/one.html">
<button type="submit">Submit</button>
</form>
</div>
<turbo-frame id="frame">
<h2>Frame: Form</h2>
<form action="/__turbo/redirect" method="post" class="redirect">
Expand Down
3 changes: 3 additions & 0 deletions src/tests/fixtures/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ <h1>Navigation</h1>
<p><a id="same-origin-download-link" href="/intentionally_missing_fake_download.html" download="x.html">Same-origin download link</a></p>
<svg width="600" height="100" viewbox="-300 -50 600 100"><text><a id="same-origin-link-inside-svg-element" href="/src/tests/fixtures/one.html">Same-origin link inside SVG element</a></text></svg>
<svg width="600" height="100" viewbox="-300 -50 600 100"><text><a id="cross-origin-link-inside-svg-element" href="about:blank">Cross-origin link inside SVG element</a></text></svg>
<p><a id="link-to-disabled-frame" href="/src/tests/fixtures/frames/hello.html" data-turbo-frame="hello">Disabled turbo-frame</a></p>
</section>

<turbo-frame id="hello" disabled></turbo-frame>
</body>
</html>
14 changes: 11 additions & 3 deletions src/tests/functional/form_submission_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,16 @@ export class FormSubmissionTests extends TurboDriveTestCase {

async "test form submission with Turbo disabled on the form"() {
this.listenForFormSubmissions()
await this.clickSelector('#disabled form[data-turbo="false"] input[type=submit]')
await this.clickSelector('#turbo-false form[data-turbo="false"] input[type=submit]')
await this.nextBody
await this.querySelector("#element-id")

this.assert.notOk(await this.turboFormSubmitted)
}

async "test form submission with Turbo disabled on the submitter"() {
async "test form submission with [data-turbo=false] on the submitter"() {
this.listenForFormSubmissions()
await this.clickSelector('#disabled form:not([data-turbo]) input[data-turbo="false"]')
await this.clickSelector('#turbo-false form:not([data-turbo]) input[data-turbo="false"]')
await this.nextBody
await this.querySelector("#element-id")

Expand All @@ -167,6 +167,14 @@ export class FormSubmissionTests extends TurboDriveTestCase {
this.assert.notOk(await this.turboFormSubmitted)
}

async "test form submission targets disabled frame"() {
this.remote.execute(() => document.getElementById("frame")?.setAttribute("disabled", ""))
await this.clickSelector('#targets-frame [type="submit"')
await this.nextBody

this.assert.equal(await this.pathname, "/src/tests/fixtures/one.html")
}

listenForFormSubmissions() {
this.remote.execute(() => addEventListener("turbo:submit-start", function eventListener(event) {
removeEventListener("turbo:submit-start", eventListener, false)
Expand Down
7 changes: 7 additions & 0 deletions src/tests/functional/navigation_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export class NavigationTests extends TurboDriveTestCase {
this.assert.equal(await this.pathname, "/src/tests/fixtures/one.html")
this.assert.equal(await this.visitAction, "restore")
}

async "test link targeting a disabled turbo-frame navigates the page"() {
await this.clickSelector("#link-to-disabled-frame")
await this.nextBody

this.assert.equal(await this.pathname, "/src/tests/fixtures/frames/hello.html")
}
}

NavigationTests.registerSuite()

0 comments on commit d4e9d4c

Please sign in to comment.