Skip to content
This repository
Browse code

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

  • Loading branch information...
commit f58f4f7939aa251ac3404088197c23e7555e8fb6 1 parent b1a78e1
Assaf Arkin authored
2  CHANGELOG.md
Source Rendered
@@ -7,6 +7,8 @@ zombie.js-changelog(7) -- Changelog
7 7 Now requires Node 0.6.x or later. Also upgraded to CoffeeScript 1.3.1, which
8 8 helped find a couple of skipped tests.
9 9
  10 +Added File object in browser (Ian Young)
  11 +
10 12
11 13 ## Version 0.12.15 2012-02-23
12 14
20 lib/zombie/browser.coffee
@@ -13,14 +13,15 @@ History = require("./history")
13 13 Interact = require("./interact")
14 14 JSDom = require("jsdom")
15 15 Mime = require("mime")
16   -PATH = require("path")
  16 +Path = require("path")
17 17 Resources = require("./resources")
18 18 Storages = require("./storage")
19 19 URL = require("url")
20 20 XHR = require("./xhr")
21 21 WebSocket = require("./websocket")
22 22
23   -FILE_CLASS = ->
  23 +
  24 +class File
24 25
25 26 HTML = JSDom.dom.level3.html
26 27 MOUSE_EVENT_NAMES = ["mousedown", "mousemove", "mouseup"]
@@ -187,7 +188,7 @@ class Browser extends EventEmitter
187 188 @_ws.extend newWindow
188 189 newWindow.screen = new Screen()
189 190 newWindow.JSON = JSON
190   - newWindow.File = FILE_CLASS
  191 + newWindow.File = File
191 192 newWindow.Image = (width, height)->
192 193 img = new HTML.HTMLImageElement(newWindow.document)
193 194 img.width = width
@@ -598,19 +599,20 @@ class Browser extends EventEmitter
598 599 attach: (selector, filename, callback)->
599 600 field = @field(selector)
600 601 if field && field.tagName == "INPUT" && field.type == "file"
601   - FS.stat filename, (e, stat) =>
  602 + if filename
  603 + stat = FS.statSync(filename)
602 604 field.value = filename
603   - file = new FILE_CLASS()
604   - file.name = PATH.basename filename
605   - file.type = Mime.lookup filename
  605 + file = new File()
  606 + file.name = Path.basename(filename)
  607 + file.type = Mime.lookup(filename)
606 608 file.size = stat.size
607 609 field.files ?= []
608 610 field.files.push file
609 611 @fire "change", field, callback
610   - unless callback
611   - return this
612 612 else
613 613 throw new Error("No file INPUT matching '#{selector}'")
  614 + unless callback
  615 + return this
614 616
615 617 # ### browser.select(selector, value, callback) => this
616 618 #
8 spec/forms_spec.coffee
@@ -730,7 +730,7 @@ Vows.describe("Forms").addBatch
730 730
731 731 "file upload with JS":
732 732 topic: ->
733   - brains.get "/forms/upload", (req, res)->
  733 + brains.get "/forms/upload-js", (req, res)->
734 734 res.send """
735 735 <html>
736 736 <head>
@@ -759,10 +759,11 @@ Vows.describe("Forms").addBatch
759 759 """
760 760
761 761 "text":
762   - Browser.wants "http://localhost:3003/forms/upload"
  762 + Browser.wants "http://localhost:3003/forms/upload-js"
763 763 topic: (browser)->
764   - filename = __dirname + "/data/random.txt"
  764 + filename = "#{__dirname}/data/random.txt"
765 765 browser.attach "my_file", filename, @callback
  766 +
766 767 "should call callback": (browser)->
767 768 assert.equal browser.text("title"), "Upload done"
768 769 "should have filename": (browser)->
@@ -774,6 +775,7 @@ Vows.describe("Forms").addBatch
774 775 "should be of type File": (browser)->
775 776 assert.equal browser.text("#is_file"), "true"
776 777
  778 +
777 779 .addBatch
778 780
779 781 "content length":

0 comments on commit f58f4f7

Please sign in to comment.
Something went wrong with that request. Please try again.