Skip to content

Commit

Permalink
Testing that Zombie.js can handle jQuery live form submit event. Yes …
Browse files Browse the repository at this point in the history
…it can!
  • Loading branch information
assaf committed Dec 28, 2010
1 parent 3101e7d commit b91e7a8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,12 @@ Added debugging to help you figure out what's happening when tests run:
- Call `browser.debug` with a function to print the result of that
function call.

Testing that Zombie.js can handle jQuery live form submit event. Yes it
can!

185 Tests
1.8 sec to complete


## Version 0.7.2 2010-12-27

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "zombie",
"version": "0.7.2",
"version": "0.7.3",
"description": "Insanely fast, full-stack, headless testing using node.js",
"homepage": "http://zombie.labnotes.org/",
"author": "Assaf Arkin <assaf@labnotes.org> (http://labnotes.org/)",
Expand Down
36 changes: 23 additions & 13 deletions spec/browser-spec.coffee
Expand Up @@ -25,27 +25,29 @@ brains.get "/living", (req, res)-> res.send """
<script src="/app.js"></script>
</head>
<body>
<div id="main"></div>
<a href="/dead">Kill</a>
<form>
<label>Name <input type="text" name="name" id="field-name"></label>
<label for="field-email">Email</label>
<input type="text" name="email" id="field-email"></label>
<textarea name="likes" id="field-likes"></textarea>
<input type="password" name="password" id="field-password">
</form>
<div id="main">
<a href="/dead">Kill</a>
<form action="#/dead" method="post">
<label>Email <input type="text" name="email"></label>
<label>Password <input type="password" name="password"></label>
<button>Sign Me Up</button>
</form>
</div>
<div class="now">Walking Aimlessly</div>
</body>
</html>
"""
brains.get "/app.js", (req, res)-> res.send """
Sammy("#main", function(app) {
app.get("#/", function(context) {
context.swap("The Living");
document.title = "The Living";
});
app.get("#/dead", function(context) {
context.swap("The Living Dead");
});
app.post("#/dead", function(context) {
document.title = "Signed up";
});
});
$(function() { Sammy("#main").run("#/") });
"""
Expand Down Expand Up @@ -76,7 +78,7 @@ vows.describe("Browser").addBatch(

"run app":
zombie.wants "http://localhost:3003/living"
"should execute route": (browser)-> assert.equal browser.text("#main"), "The Living"
"should execute route": (browser)-> assert.equal browser.document.title, "The Living"
"should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/"
"move around":
topic: (browser)->
Expand Down Expand Up @@ -115,13 +117,13 @@ vows.describe("Browser").addBatch(
"should query from document": (browser)-> assert.equal browser.text(".now"), "Walking Aimlessly"
"should query from context": (browser)-> assert.equal browser.text(".now", browser.body), "Walking Aimlessly"
"should query from context": (browser)-> assert.equal browser.text(".now", browser.querySelector("#main")), ""
"should combine multiple elements": (browser)-> assert.equal browser.text("form label"), "Name Email"
"should combine multiple elements": (browser)-> assert.equal browser.text("form label"), "Email Password "
"query html":
topic: (browser)-> browser
"should query from document": (browser)-> assert.equal browser.html(".now"), "<div class=\"now\">Walking Aimlessly</div>"
"should query from context": (browser)-> assert.equal browser.html(".now", browser.body), "Walking Aimlessly"
"should query from context": (browser)-> assert.equal browser.html(".now", browser.querySelector("#main")), ""
"should combine multiple elements": (browser)-> assert.equal browser.html("#main, a"), "<div id=\"main\">The Living</div><a href=\"/dead\">Kill</a>"
"should combine multiple elements": (browser)-> assert.equal browser.html("title, #main a"), "<title>The Living</title><a href=\"/dead\">Kill</a>"

"click link":
zombie.wants "http://localhost:3003/living"
Expand All @@ -130,4 +132,12 @@ vows.describe("Browser").addBatch(
"should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/dead"
"should run all events": (browser)-> assert.equal browser.document.title, "The Dead"

"live events":
zombie.wants "http://localhost:3003/living"
topic: (browser)->
browser.fill("Email", "armbiter@zombies").fill("Password", "br41nz").
pressButton "Sign Me Up", @callback
"should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/living#/"
"should process event": (browser)-> assert.equal browser.document.title, "Signed up"

).export(module)
7 changes: 7 additions & 0 deletions src/zombie/forms.coffee
Expand Up @@ -48,6 +48,13 @@ core.HTMLFormElement.prototype._eventDefault = (event)->
# Buttons
# -------

# Default type for buttons is submit.
core.Document.prototype._elementBuilders["button"] = (doc, s)->
button = new core.HTMLButtonElement(doc, s)
button.type ||= "submit"
return button


# Default behavior for clicking on reset/submit buttons.
core.HTMLInputElement.prototype._eventDefault = (event)->
return if @getAttribute("disabled")
Expand Down
4 changes: 3 additions & 1 deletion src/zombie/history.coffee
Expand Up @@ -43,7 +43,9 @@ class History

# Make a request to external resource. We use this to fetch pages and
# submit forms, see _loadPage and _submit.
resource = (url, method = "GET", data, enctype)=>
resource = (url, method, data, enctype)=>
method = (method || "GET").toUpperCase()
browser.debug "#{method} #{URL.format(url)}"
throw new Error("Cannot load resource: #{URL.format(url)}") unless url.protocol && url.hostname
window = browser.window
window = browser.open() if browser.window.document
Expand Down

0 comments on commit b91e7a8

Please sign in to comment.