Skip to content

Commit

Permalink
Fix quotation marks and brackets on Windows (#56)
Browse files Browse the repository at this point in the history
* Add tests for quotation marks

* Fix windows keycodes for quotes and brackets

* Fix keycodes for Slash
  • Loading branch information
olivercoad committed Jun 11, 2024
1 parent 4cb14b5 commit 55bdc91
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
16 changes: 15 additions & 1 deletion Desktop.Robot.TestApp/KeyboardTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ let tests (window:Window) = testList "Keybard tests" [
do! testBody tb
}

let textboxTest name expectedMessage robotAction = keyboardTest name <| fun tb -> async {
do! robotDoOnThreadpool <| async { do robotAction (Robot()) }
do! pressKeyAndWaitForEvent tb Key.Esc
Expect.equal tb.Text expectedMessage "Should get expected key"
}

keyboardTest "Simple keypess" <| fun tb -> async {
do! pressKeyAndWaitForEvent tb Key.A
Expect.equal tb.Text "a" "Should press A"
Expand Down Expand Up @@ -205,7 +211,15 @@ let tests (window:Window) = testList "Keybard tests" [

testList "Alphabet keys" (List.map regularKeyTest alphabetKeys)
testList "Digit keys" (List.map regularKeyTest digitKeys)
// Dodo: Test more testable sets of keycodes

testList "Some misc keys" [
textboxTest "Single quotation mark" "'" (fun rb -> rb.KeyPress(Key.QuotationMark))
textboxTest "Double quotation mark with shift" "\"" (fun rb -> ignore <| rb.CombineKeys(Key.Shift, Key.QuotationMark))
textboxTest "Brackets" "[]" (fun rb -> ignore <| rb.KeyPress(Key.OpenBracket); rb.KeyPress(Key.CloseBracket))
textboxTest "Forward slash" "/" (fun rb -> rb.KeyPress(Key.Slash))
textboxTest "Question mark" "?"(fun rb -> ignore <| rb.CombineKeys(Key.Shift, Key.Slash))
]
// Todo: Test more testable sets of keycodes

// don't test all keycodes, a bunch are broken anyway and many have different
// behavious (eg. PrintScreen, NumLock, Modifiers etc.)
Expand Down
4 changes: 2 additions & 2 deletions Desktop.Robot.TestApp/MouseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ let tests (window:Window) = testList "Mouse tests" [
let robot = Robot();
robot.AutoDelay <- 100;
let! deltaEvents = attemptUIActionList wheelDeltas <| async {
robot.MouseScroll(100) // scroll down
robot.MouseScroll(-100) // then scroll up
robot.MouseScroll(1) // scroll down
robot.MouseScroll(-1) // then scroll up
}
Expect.hasLength deltaEvents 2 "Should have a wheel event for each mouse scroll"
let xDeltas = deltaEvents |> List.map (fun p -> p.X)
Expand Down
4 changes: 2 additions & 2 deletions Desktop.Robot.TestApp/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ type MainWindow() as this =
this.Title <- "Desktop.Robot test app"
this.Width <- 300.
this.Height <- 200.

let btn = Button()
this.Content <- btn
btn.Content <- "Click to start test"
btn.Width <- 100.
btn.Width <- 150.
btn.Height <- 50.
let runTests () =
this.Content <- null
Expand Down
8 changes: 4 additions & 4 deletions Desktop.Robot/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public enum Key
Dollar,

[Keycode(Platform = "OSX", Keycode = 0x2C)]
[Keycode(Platform = "Windows", Keycode = 0x5A)]
[Keycode(Platform = "Windows", Keycode = 0xBF)]
[Keycode(Platform = "Linux", Keycode = 0x002f)]
Slash,

Expand Down Expand Up @@ -255,7 +255,7 @@ public enum Key
GreaterThan,

[Keycode(Platform = "OSX", Keycode = 0x27)]
[Keycode(Platform = "Windows", Keycode = 0x5A)]
[Keycode(Platform = "Windows", Keycode = 0xDE)]
[Keycode(Platform = "Linux", Keycode = 0x0022)]
QuotationMark,

Expand All @@ -270,12 +270,12 @@ public enum Key
CloseParenthesis,

[Keycode(Platform = "OSX", Keycode = 0x21)]
[Keycode(Platform = "Windows", Keycode = 0x5A)]
[Keycode(Platform = "Windows", Keycode = 0xDB)]
[Keycode(Platform = "Linux", Keycode = 0x005b)]
OpenBracket,

[Keycode(Platform = "OSX", Keycode = 0x1E)]
[Keycode(Platform = "Windows", Keycode = 0x5A)]
[Keycode(Platform = "Windows", Keycode = 0xDD)]
[Keycode(Platform = "Linux", Keycode = 0x005d)]
CloseBracket,

Expand Down

0 comments on commit 55bdc91

Please sign in to comment.