Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #465 from dmauro/master
Browse files Browse the repository at this point in the history
Keyup, keydown and keypress events when using browser.fill
  • Loading branch information
assaf committed Jan 4, 2013
2 parents a74d519 + 99bd6f7 commit 5457e38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
7 changes: 6 additions & 1 deletion lib/zombie/browser.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -669,8 +669,13 @@ class Browser extends EventEmitter
if field.getAttribute("readonly") if field.getAttribute("readonly")
throw new Error("This INPUT field is readonly") throw new Error("This INPUT field is readonly")
field.focus() field.focus()
start_value = field.value
field.value = value field.value = value
@fire(field, "change") if start_value != value
@fire(field, "change")
@fire(field, "keydown")
@fire(field, "keyup")
@fire(field, "keypress")
return this return this


_setCheckbox: (selector, value)-> _setCheckbox: (selector, value)->
Expand Down
29 changes: 21 additions & 8 deletions test/forms_test.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -155,18 +155,31 @@ describe "Forms", ->
describe "fill field", -> describe "fill field", ->
before (done)-> before (done)->
browser.visit "/forms/form", => browser.visit "/forms/form", =>
fill_events = ["change", "keydown", "keyup", "keypress"]
count = fill_events.length
browser.on "event", (event, target)=> browser.on "event", (event, target)=>
if event.type == "change" if event.type in fill_events
@changed = target count -= 1
if count == 0
@changed = target
count = fill_events.length
else
count = fill_events.length
done() done()


describe "fill input with same the same value", ->
before ->
browser.fill("Name", "")
it "should not fire change and key events", ->
assert.equal @change, undefined

describe "text input enclosed in label", -> describe "text input enclosed in label", ->
before -> before ->
browser.fill("Name", "ArmBiter") browser.fill("Name", "ArmBiter")


it "should set text field", -> it "should set text field", ->
browser.assert.input "#field-name", "ArmBiter" browser.assert.input "#field-name", "ArmBiter"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-name" assert.equal @changed.id, "field-name"


describe "email input referenced from label", -> describe "email input referenced from label", ->
Expand All @@ -175,7 +188,7 @@ describe "Forms", ->


it "should set email field", -> it "should set email field", ->
browser.assert.input "#field-email", "armbiter@example.com" browser.assert.input "#field-email", "armbiter@example.com"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-email" assert.equal @changed.id, "field-email"


describe "textarea by field name", -> describe "textarea by field name", ->
Expand All @@ -184,7 +197,7 @@ describe "Forms", ->


it "should set textarea", -> it "should set textarea", ->
browser.assert.input "#field-likes", "Arm Biting" browser.assert.input "#field-likes", "Arm Biting"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-likes" assert.equal @changed.id, "field-likes"


describe "password input by selector", -> describe "password input by selector", ->
Expand All @@ -193,7 +206,7 @@ describe "Forms", ->


it "should set password", -> it "should set password", ->
browser.assert.input "#field-password", "b100d" browser.assert.input "#field-password", "b100d"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-password" assert.equal @changed.id, "field-password"


describe "input without a valid type", -> describe "input without a valid type", ->
Expand All @@ -202,7 +215,7 @@ describe "Forms", ->


it "should set value", -> it "should set value", ->
browser.assert.input "#field-invalidtype", "some value" browser.assert.input "#field-invalidtype", "some value"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-invalidtype" assert.equal @changed.id, "field-invalidtype"


describe "email2 input by node", -> describe "email2 input by node", ->
Expand All @@ -211,7 +224,7 @@ describe "Forms", ->


it "should set email2 field", -> it "should set email2 field", ->
browser.assert.input "#field-email2", "headchomper@example.com" browser.assert.input "#field-email2", "headchomper@example.com"
it "should fire change event", -> it "should fire change and key events", ->
assert.equal @changed.id, "field-email2" assert.equal @changed.id, "field-email2"


describe "disabled input can not be modified", -> describe "disabled input can not be modified", ->
Expand Down

0 comments on commit 5457e38

Please sign in to comment.