mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Implemented Node#drag_to
This commit is contained in:
parent
13bbf204fe
commit
0529657fc8
2 changed files with 31 additions and 13 deletions
|
@ -29,7 +29,9 @@ class Capybara::Driver::Webkit
|
||||||
end
|
end
|
||||||
|
|
||||||
def drag_to(element)
|
def drag_to(element)
|
||||||
raise NotImplementedError
|
trigger('mousedown')
|
||||||
|
element.trigger('mousemove')
|
||||||
|
element.trigger('mouseup')
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_name
|
def tag_name
|
||||||
|
|
|
@ -6,15 +6,22 @@ describe Capybara::Driver::Webkit do
|
||||||
lambda do |env|
|
lambda do |env|
|
||||||
body = <<-HTML
|
body = <<-HTML
|
||||||
<html><body>
|
<html><body>
|
||||||
<div id="changeMe">Change me, please</div>
|
<div id="change">Change me</div>
|
||||||
|
<div id="mouseup">Push me</div>
|
||||||
|
<div id="mousedown">Release me</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.write("<p id='greeting'>he" + "llo</p>");
|
document.write("<p id='greeting'>he" + "llo</p>");
|
||||||
var changeMe = document.getElementById("changeMe");
|
document.getElementById("change").
|
||||||
changeMe.addEventListener("mouseup", function () {
|
addEventListener("change", function () {
|
||||||
this.id = "mouseup";
|
this.className = "triggered";
|
||||||
});
|
});
|
||||||
changeMe.addEventListener("change", function () {
|
document.getElementById("mouseup").
|
||||||
this.id = "change";
|
addEventListener("mouseup", function () {
|
||||||
|
this.className = "triggered";
|
||||||
|
});
|
||||||
|
document.getElementById("mousedown").
|
||||||
|
addEventListener("mousedown", function () {
|
||||||
|
this.className = "triggered";
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<a href="/next">Next</a>
|
<a href="/next">Next</a>
|
||||||
|
@ -140,12 +147,21 @@ describe Capybara::Driver::Webkit do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fires a mouse event" do
|
it "fires a mouse event" do
|
||||||
subject.find("//*[@id='changeMe']").first.trigger("mouseup")
|
subject.find("//*[@id='mouseup']").first.trigger("mouseup")
|
||||||
subject.find("//*[@id='mouseup']").should_not be_empty
|
subject.find("//*[@class='triggered']").should_not be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fires a non-mouse event" do
|
it "fires a non-mouse event" do
|
||||||
subject.find("//*[@id='changeMe']").first.trigger("change")
|
subject.find("//*[@id='change']").first.trigger("change")
|
||||||
subject.find("//*[@id='change']").should_not be_empty
|
subject.find("//*[@class='triggered']").should_not be_empty
|
||||||
|
end
|
||||||
|
|
||||||
|
it "fires drag events" do
|
||||||
|
draggable = subject.find("//*[@id='mousedown']").first
|
||||||
|
container = subject.find("//*[@id='mouseup']").first
|
||||||
|
|
||||||
|
draggable.drag_to(container)
|
||||||
|
|
||||||
|
subject.find("//*[@class='triggered']").size.should == 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue