forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwipeGestureRecognizerTests.cs
87 lines (72 loc) · 2.18 KB
/
SwipeGestureRecognizerTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using NUnit.Framework;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class SwipeGestureRecognizerTests : BaseTestFixture
{
[Test]
public void Constructor()
{
var swipe = new SwipeGestureRecognizer();
Assert.AreEqual(null, swipe.Command);
Assert.AreEqual(null, swipe.CommandParameter);
Assert.AreEqual(100, swipe.Threshold);
}
[Test]
public void CallbackPassesParameter()
{
var view = new View();
var swipe = new SwipeGestureRecognizer();
swipe.CommandParameter = "Hello";
object result = null;
swipe.Command = new Command(o => result = o);
swipe.SendSwiped(view, SwipeDirection.Left);
Assert.AreEqual(result, swipe.CommandParameter);
}
[Test]
public void SwipedEventDirectionMatchesTotalXTest()
{
var view = new View();
var swipe = new SwipeGestureRecognizer();
SwipeDirection direction = SwipeDirection.Up;
swipe.Swiped += (object sender, SwipedEventArgs e) =>
{
direction = e.Direction;
};
((ISwipeGestureController)swipe).SendSwipe(view, totalX: -150, totalY: 10);
((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Left);
Assert.AreEqual(SwipeDirection.Left, direction);
}
[Test]
public void SwipedEventDirectionMatchesTotalYTest()
{
var view = new View();
var swipe = new SwipeGestureRecognizer();
SwipeDirection direction = SwipeDirection.Left;
swipe.Swiped += (object sender, SwipedEventArgs e) =>
{
direction = e.Direction;
};
((ISwipeGestureController)swipe).SendSwipe(view, totalX: 10, totalY: -150);
((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Up);
Assert.AreEqual(SwipeDirection.Up, direction);
}
[Test]
public void SwipeIgnoredIfBelowThresholdTest()
{
var view = new View();
var swipe = new SwipeGestureRecognizer();
// Specify a custom threshold for the test.
swipe.Threshold = 200;
bool detected = false;
swipe.Swiped += (object sender, SwipedEventArgs e) =>
{
detected = true;
};
((ISwipeGestureController)swipe).SendSwipe(view, totalX: 0, totalY: -175);
((ISwipeGestureController)swipe).DetectSwipe(view, SwipeDirection.Up);
Assert.IsFalse(detected);
}
}
}