Permalink
Browse files

Fixed #432, setting multiple contenteditables.

It seems that if something else has the input focus when we call `set`
on a `contenteditable`, the wrong text is deleted. By clicking on the
`contenteditable` first, we ensure we'll delete the right text.
  • Loading branch information...
1 parent 02f63aa commit f6af1d8c4e9d6214a430e74092e73bae25c29e60 @eostrom eostrom committed Dec 18, 2013
Showing with 36 additions and 0 deletions.
  1. +3 −0 CHANGELOG.md
  2. +1 −0 lib/capybara/poltergeist/node.rb
  3. +22 −0 spec/integration/driver_spec.rb
  4. +10 −0 spec/support/views/set.erb
View
@@ -6,6 +6,9 @@
#### Bug fixes ####
+* Fix `set` appending to `contenteditable` instead of replacing its text
+ (Erik Ostrom) [Issue #432]
+
### 1.5.0 ###
#### Features ####
@@ -70,6 +70,7 @@ def set(value)
elsif tag_name == 'textarea'
command :set, value.to_s
elsif self[:contenteditable] == 'true'
+ click
command :delete_text
send_keys(value.to_s)
end
@@ -787,5 +787,27 @@ def create_screenshot(file, *args)
expect(input.value).to eq('S')
end
end
+
+ context "set" do
+ before { @session.visit('/poltergeist/set') }
+
+ it "sets a contenteditable's content" do
+ input = @session.find(:css, '#filled_div')
+ input.set('new text')
+ expect(input.text).to eq('new text')
+ end
+
+ it "sets multiple contenteditables' content" do
+ input = @session.find(:css, '#empty_div')
+ input.set('new text')
+
+ expect(input.text).to eq('new text')
+
+ input = @session.find(:css, '#filled_div')
+ input.set('replacement text')
+
+ expect(input.text).to eq('replacement text')
+ end
+ end
end
end
View
@@ -0,0 +1,10 @@
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
+ </head>
+
+ <body>
+ <div id="empty_div" contenteditable="true"></div>
+ <div id="filled_div" contenteditable="true">Content</div>
+ </body>
+</html>

0 comments on commit f6af1d8

Please sign in to comment.