Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix tests for file upload, brought implementation up to coding standard.

  • Loading branch information...
commit f58f4f7939aa251ac3404088197c23e7555e8fb6 1 parent b1a78e1
Assaf Arkin authored
Showing with 18 additions and 12 deletions.
  1. +2 −0  CHANGELOG.md
  2. +11 −9 lib/zombie/browser.coffee
  3. +5 −3 spec/forms_spec.coffee
2  CHANGELOG.md
View
@@ -7,6 +7,8 @@ zombie.js-changelog(7) -- Changelog
Now requires Node 0.6.x or later. Also upgraded to CoffeeScript 1.3.1, which
helped find a couple of skipped tests.
+Added File object in browser (Ian Young)
+
## Version 0.12.15 2012-02-23
20 lib/zombie/browser.coffee
View
@@ -13,14 +13,15 @@ History = require("./history")
Interact = require("./interact")
JSDom = require("jsdom")
Mime = require("mime")
-PATH = require("path")
+Path = require("path")
Resources = require("./resources")
Storages = require("./storage")
URL = require("url")
XHR = require("./xhr")
WebSocket = require("./websocket")
-FILE_CLASS = ->
+
+class File
HTML = JSDom.dom.level3.html
MOUSE_EVENT_NAMES = ["mousedown", "mousemove", "mouseup"]
@@ -187,7 +188,7 @@ class Browser extends EventEmitter
@_ws.extend newWindow
newWindow.screen = new Screen()
newWindow.JSON = JSON
- newWindow.File = FILE_CLASS
+ newWindow.File = File
newWindow.Image = (width, height)->
img = new HTML.HTMLImageElement(newWindow.document)
img.width = width
@@ -598,19 +599,20 @@ class Browser extends EventEmitter
attach: (selector, filename, callback)->
field = @field(selector)
if field && field.tagName == "INPUT" && field.type == "file"
- FS.stat filename, (e, stat) =>
+ if filename
+ stat = FS.statSync(filename)
field.value = filename
- file = new FILE_CLASS()
- file.name = PATH.basename filename
- file.type = Mime.lookup filename
+ file = new File()
+ file.name = Path.basename(filename)
+ file.type = Mime.lookup(filename)
file.size = stat.size
field.files ?= []
field.files.push file
@fire "change", field, callback
- unless callback
- return this
else
throw new Error("No file INPUT matching '#{selector}'")
+ unless callback
+ return this
# ### browser.select(selector, value, callback) => this
#
8 spec/forms_spec.coffee
View
@@ -730,7 +730,7 @@ Vows.describe("Forms").addBatch
"file upload with JS":
topic: ->
- brains.get "/forms/upload", (req, res)->
+ brains.get "/forms/upload-js", (req, res)->
res.send """
<html>
<head>
@@ -759,10 +759,11 @@ Vows.describe("Forms").addBatch
"""
"text":
- Browser.wants "http://localhost:3003/forms/upload"
+ Browser.wants "http://localhost:3003/forms/upload-js"
topic: (browser)->
- filename = __dirname + "/data/random.txt"
+ filename = "#{__dirname}/data/random.txt"
browser.attach "my_file", filename, @callback
+
"should call callback": (browser)->
assert.equal browser.text("title"), "Upload done"
"should have filename": (browser)->
@@ -774,6 +775,7 @@ Vows.describe("Forms").addBatch
"should be of type File": (browser)->
assert.equal browser.text("#is_file"), "true"
+
.addBatch
"content length":
Please sign in to comment.
Something went wrong with that request. Please try again.