Skip to content

Commit

Permalink
added submit event triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Apr 29, 2014
1 parent 876a77c commit 2906e5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/capybara/poltergeist/client/agent.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class PoltergeistAgent.Node
@EVENTS = {
FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove',
'mouseover', 'mouseout', 'mouseup']
'mouseover', 'mouseout', 'mouseup'],
FORM: ['submit']
}

constructor: (@agent, @element) ->
Expand Down Expand Up @@ -272,13 +273,19 @@ class PoltergeistAgent.Node
false, false, false, false, 0, null
)
else if Node.EVENTS.FOCUS.indexOf(name) != -1
event = document.createEvent('HTMLEvents')
event.initEvent(name, true, true)
event = this.obtainEvent(name)
else if Node.EVENTS.FORM.indexOf(name) != -1
event = this.obtainEvent(name)
else
throw "Unknown event"

@element.dispatchEvent(event)

obtainEvent: (name) ->
event = document.createEvent('HTMLEvents')
event.initEvent(name, true, true)
event

mouseEventTest: (x, y) ->
frameOffset = this.frameOffset()

Expand Down
15 changes: 12 additions & 3 deletions lib/capybara/poltergeist/client/compiled/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ PoltergeistAgent.InvalidSelector = (function() {
PoltergeistAgent.Node = (function() {
Node.EVENTS = {
FOCUS: ['blur', 'focus', 'focusin', 'focusout'],
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup']
MOUSE: ['click', 'dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'mouseover', 'mouseout', 'mouseup'],
FORM: ['submit']
};

function Node(agent, element) {
Expand Down Expand Up @@ -405,14 +406,22 @@ PoltergeistAgent.Node = (function() {
event = document.createEvent('MouseEvent');
event.initMouseEvent(name, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
} else if (Node.EVENTS.FOCUS.indexOf(name) !== -1) {
event = document.createEvent('HTMLEvents');
event.initEvent(name, true, true);
event = this.obtainEvent(name);
} else if (Node.EVENTS.FORM.indexOf(name) !== -1) {
event = this.obtainEvent(name);
} else {
throw "Unknown event";
}
return this.element.dispatchEvent(event);
};

Node.prototype.obtainEvent = function(name) {
var event;
event = document.createEvent('HTMLEvents');
event.initEvent(name, true, true);
return event;
};

Node.prototype.mouseEventTest = function(x, y) {
var el, frameOffset, origEl;
frameOffset = this.frameOffset();
Expand Down
6 changes: 6 additions & 0 deletions spec/integration/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@
expect { @session.find(:xpath, '#remove_me') }.to raise_error(Capybara::Poltergeist::InvalidSelector)
end

it 'should submit form' do
@session.visit('/poltergeist/send_keys')
@session.find(:css, '#without_submit_button').trigger('submit')
expect(@session.find(:css, '#without_submit_button input').value).to eq('Submitted')
end

context 'whitespace stripping tests' do
before do
@session.visit '/poltergeist/filter_text_test'
Expand Down

0 comments on commit 2906e5f

Please sign in to comment.