-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With calabash 162, swipe can be done in many ways. It can take a optional "force" argument, "swipe-delta" etc. This commit adds support for these options
- Loading branch information
Showing
7 changed files
with
220 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package calabash.java; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package calabash.java; | ||
|
||
/** | ||
* Options for Swipe action | ||
* | ||
*/ | ||
public class SwipeOptions { | ||
|
||
private Force force; | ||
private SwipeDelta swipeDelta; | ||
|
||
public SwipeOptions(Force force, SwipeDelta swipeDelta) { | ||
this.force = force; | ||
this.swipeDelta = swipeDelta; | ||
} | ||
|
||
public SwipeOptions(Force force) { | ||
this.force = force; | ||
} | ||
|
||
public SwipeOptions(SwipeDelta swipeDelta) { | ||
this.swipeDelta = swipeDelta; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuffer result = new StringBuffer("{"); | ||
if (force != null) | ||
result.append(force.toString()); | ||
|
||
if (swipeDelta != null) { | ||
if (!result.toString().endsWith("{")) | ||
result.append(", "); | ||
result.append(swipeDelta.toString()); | ||
} | ||
|
||
result.append("}"); | ||
|
||
return result.toString(); | ||
} | ||
|
||
public static class SwipeDelta { | ||
private Offset horizontal; | ||
private Offset vertical; | ||
|
||
public SwipeDelta(Offset horizontal, Offset vertical) { | ||
this.horizontal = horizontal; | ||
this.vertical = vertical; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuffer result = new StringBuffer(); | ||
result.append("'swipe-delta' => {"); | ||
if (horizontal != null) { | ||
result.append(String.format( | ||
":horizontal => {:dx => %d, :dy => %d}", | ||
horizontal.getX(), horizontal.getY())); | ||
} | ||
|
||
if (vertical != null) { | ||
if (horizontal != null) | ||
result.append(", "); | ||
result.append(String.format( | ||
":vertical => {:dx => %d, :dy => %d}", vertical.getX(), | ||
vertical.getY())); | ||
} | ||
result.append("}"); | ||
return result.toString(); | ||
} | ||
} | ||
|
||
public static enum Force { | ||
|
||
Strong("strong"), Normal("normal"), Light("light"); | ||
|
||
private String name; | ||
|
||
Force(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format(":force => :%s", name); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package calabash.java; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
import calabash.java.SwipeOptions.Force; | ||
import calabash.java.SwipeOptions.SwipeDelta; | ||
|
||
public class SwipeOptionsTest { | ||
|
||
@Test | ||
public void swipeOptionsWithForce() { | ||
SwipeOptions swipeOptions = new SwipeOptions(Force.Strong, null); | ||
assertEquals("{:force => :strong}", swipeOptions.toString()); | ||
} | ||
|
||
@Test | ||
public void swipeOptionsWithSwipeDeltaHorizontal() { | ||
SwipeOptions swipeOptions = new SwipeOptions(null, new SwipeDelta( | ||
new Offset(10, 20), null)); | ||
assertEquals( | ||
"{'swipe-delta' => {:horizontal => {:dx => 10, :dy => 20}}}", | ||
swipeOptions.toString()); | ||
} | ||
|
||
@Test | ||
public void swipeOptionsWithSwipeDeltaVertical() { | ||
SwipeOptions swipeOptions = new SwipeOptions(null, new SwipeDelta(null, | ||
new Offset(10, 20))); | ||
assertEquals( | ||
"{'swipe-delta' => {:vertical => {:dx => 10, :dy => 20}}}", | ||
swipeOptions.toString()); | ||
} | ||
|
||
@Test | ||
public void swipeOptionsWithSwipeDeltaHorizontalAndVertical() { | ||
SwipeOptions swipeOptions = new SwipeOptions(null, new SwipeDelta( | ||
new Offset(10, 20), new Offset(10, 20))); | ||
assertEquals( | ||
"{'swipe-delta' => {:horizontal => {:dx => 10, :dy => 20}, :vertical => {:dx => 10, :dy => 20}}}", | ||
swipeOptions.toString()); | ||
} | ||
|
||
@Test | ||
public void swipeOptionsWithForceAndSwipeDeltaHorizontalAndVertical() { | ||
SwipeOptions swipeOptions = new SwipeOptions(Force.Normal, | ||
new SwipeDelta(new Offset(10, 20), new Offset(10, 20))); | ||
assertEquals( | ||
"{:force => :normal, 'swipe-delta' => {:horizontal => {:dx => 10, :dy => 20}, :vertical => {:dx => 10, :dy => 20}}}", | ||
swipeOptions.toString()); | ||
} | ||
|
||
} |