Skip to content

Commit 37b32b0

Browse files
committed
Add test for transparently handling form submits
Closes #302
1 parent 71cd225 commit 37b32b0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test/unit/pjax_fallback.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,22 @@ asyncTest("POST with data string"+s, function() {
357357
})
358358
})
359359

360+
asyncTest("handle form submit"+s, function() {
361+
var frame = this.frame
362+
363+
frame.$(frame.document).on("submit", "form", function(event) {
364+
frame.$.pjax.submit(event, "#main")
365+
})
366+
367+
this.loaded = function() {
368+
var env = JSON.parse(frame.$("#env").text())
369+
var expected = {foo: "1", bar: "2"}
370+
if (!disabled) expected._pjax = "#main"
371+
deepEqual(env['rack.request.query_hash'], expected)
372+
start()
373+
}
374+
375+
frame.$("form").submit()
376+
})
377+
360378
})

test/views/home.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
<li><a href="#main">Main</a></li>
99
</ul>
1010

11+
<form action="env.html" method="GET">
12+
<input name="foo" value="1">
13+
<input name="bar" value="2">
14+
</form>
15+
1116
<div style="width:500px;height:10000px;"></div>
1217

1318
<script type="text/javascript">window.parent.iframeLoad(window)</script>

0 commit comments

Comments
 (0)