Skip to content

Commit 02ed37a

Browse files
authored
Merge pull request #41 from olivercoad/mousewheel-test
Mousewheel test
2 parents b378c70 + 82928ce commit 02ed37a

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Desktop.Robot.TestApp/MouseTests.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ let tests (window:Window) = testList "Mouse tests" [
110110
testMouseDownUp RightButton
111111
testMouseDownUp MiddleButton
112112

113+
uiTest "Can scroll vertical" <| async {
114+
let wheelDeltas = window.PointerWheelChanged.Select(fun x -> x.Delta)
115+
116+
let! deltaEvents = attemptUIActionList wheelDeltas <| async {
117+
Robot().MouseScrollVertical(100) // scroll down
118+
Robot().MouseScrollVertical(-100) // then scroll up
119+
}
120+
Expect.hasLength deltaEvents 2 "Should have a wheel event for each mouse scroll"
121+
let xDeltas = deltaEvents |> List.map (fun p -> p.X)
122+
let yDeltas = deltaEvents |> List.map (fun p -> p.Y)
123+
Expect.allEqual xDeltas 0 "Should not scroll horizontally"
124+
Expect.isLessThan yDeltas[0] 0 "Should scroll down first"
125+
Expect.isGreaterThan yDeltas[1] 0 "Should scroll up next"
126+
}
127+
113128
uiTest "Can move to point" <| async {
114129
let toPixelPoint (p:Point) = PixelPoint(int p.X, int p.Y)
115130
let toDrawingPoint (p:PixelPoint) = Drawing.Point(p.X, p.Y)

Desktop.Robot.TestApp/Program.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type MainWindow() as this =
5858
.Subscribe(fun _ -> runTests())
5959
|> ignore
6060

61+
this.PointerWheelChanged.ObserveOn(SynchronizationContext.Current).Subscribe(fun x -> printfn "Wheel %f ... %A" x.Delta.Y x) |> ignore
62+
6163
type App() =
6264
inherit Application()
6365

Desktop.Robot/Linux/Robot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override void MouseScrollVertical(int value)
7474
if (value < 0)
7575
{
7676
click(true, Common.UP_BUTTON);
77-
Thread.Sleep(value);
77+
Thread.Sleep(-value);
7878
click(false, Common.UP_BUTTON);
7979
}
8080
else

0 commit comments

Comments
 (0)