1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Keydown comes before the element value is updated

This commit is contained in:
James Croft 2012-08-10 17:24:46 +01:00
parent 339b3b4b91
commit d3d7c8e369
5 changed files with 15 additions and 3 deletions

View file

@ -173,10 +173,10 @@ class PoltergeistAgent.Node
this.trigger('focus') this.trigger('focus')
for char in value for char in value
@element.value += char
keyCode = this.characterToKeyCode(char) keyCode = this.characterToKeyCode(char)
this.keyupdowned('keydown', keyCode) this.keyupdowned('keydown', keyCode)
@element.value += char
this.keypressed(false, false, false, false, char.charCodeAt(0), char.charCodeAt(0)) this.keypressed(false, false, false, false, char.charCodeAt(0), char.charCodeAt(0))
this.keyupdowned('keyup', keyCode) this.keyupdowned('keyup', keyCode)

View file

@ -254,9 +254,9 @@ PoltergeistAgent.Node = (function() {
this.trigger('focus'); this.trigger('focus');
for (_i = 0, _len = value.length; _i < _len; _i++) { for (_i = 0, _len = value.length; _i < _len; _i++) {
char = value[_i]; char = value[_i];
this.element.value += char;
keyCode = this.characterToKeyCode(char); keyCode = this.characterToKeyCode(char);
this.keyupdowned('keydown', keyCode); this.keyupdowned('keydown', keyCode);
this.element.value += char;
this.keypressed(false, false, false, false, char.charCodeAt(0), char.charCodeAt(0)); this.keypressed(false, false, false, false, char.charCodeAt(0), char.charCodeAt(0));
this.keyupdowned('keyup', keyCode); this.keyupdowned('keyup', keyCode);
} }

View file

@ -120,6 +120,14 @@ describe Capybara::Session do
it 'fires the blur event' do it 'fires the blur event' do
@session.find(:css, '#changes_on_blur').text.should == "Blur" @session.find(:css, '#changes_on_blur').text.should == "Blur"
end end
it "fires the keydown event before the value is updated" do
@session.find(:css, '#value_on_keydown').text.should == "Hello"
end
it "fires the keyup event after the value is updated" do
@session.find(:css, '#value_on_keyup').text.should == "Hello!"
end
end end
it 'supports running multiple sessions at once' do it 'supports running multiple sessions at once' do

View file

@ -18,9 +18,11 @@ $(function() {
}) })
.keydown(function(event) { .keydown(function(event) {
$('#changes_on_keydown').text(increment) $('#changes_on_keydown').text(increment)
$('#value_on_keydown').text($(this).val())
}) })
.keyup(function(event) { .keyup(function(event) {
$('#changes_on_keyup').text(increment) $('#changes_on_keyup').text(increment)
$('#value_on_keyup').text($(this).val())
}) })
.keypress(function() { .keypress(function() {
$('#changes_on_keypress').text(increment) $('#changes_on_keypress').text(increment)

View file

@ -24,6 +24,8 @@
<p id="changes_on_focus"></p> <p id="changes_on_focus"></p>
<p id="changes_on_blur"></p> <p id="changes_on_blur"></p>
<p id="changes_on_keypress"></p> <p id="changes_on_keypress"></p>
<p id="value_on_keydown"></p>
<p id="value_on_keyup"></p>
<div id="off-the-left" style="position:absolute; left: -5000px;"><a href="/" id="foo">O hai</a></div> <div id="off-the-left" style="position:absolute; left: -5000px;"><a href="/" id="foo">O hai</a></div>
</body> </body>
</html> </html>