Adds initial keyboard test for right arrow without shift

This commit is contained in:
Tessa Kelly 2022-09-21 10:59:21 -06:00
parent 89c932ee07
commit ffce39d717
2 changed files with 31 additions and 1 deletions

View File

@ -47,3 +47,12 @@ pressEscKey :
-> ProgramTest model msg effect
pressEscKey { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 27, shiftKey = False }
pressRightArrow :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressRightArrow { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 39, shiftKey = False }

View File

@ -8,6 +8,7 @@ import Nri.Ui.Highlightable.V1 as Highlightable exposing (Highlightable)
import Nri.Ui.Highlighter.V1 as Highlighter
import Nri.Ui.HighlighterTool.V1 as Tool exposing (Tool)
import ProgramTest exposing (..)
import Spec.KeyboardHelpers as KeyboardHelpers
import Test exposing (..)
import Test.Html.Query exposing (..)
import Test.Html.Selector exposing (..)
@ -24,10 +25,24 @@ keyboardTests : List Test
keyboardTests =
[ test "has a focusable element when there is one" <|
\() ->
Highlightable.initFragments Nothing "Pothos thrive in indirect light."
Highlightable.initFragments Nothing "Pothos indirect light"
|> program marker
|> ensureFocusOn "Pothos"
|> done
, test "moves focus right on right arrow key" <|
\() ->
Highlightable.initFragments Nothing "Pothos indirect light"
|> program marker
|> ensureFocusOn "Pothos"
|> rightArrow
|> ensureFocusOn "indirect"
|> rightArrow
|> ensureFocusOn "light"
-- once we're on the final element, pressing right arrow again should
-- _not_ wrap the focus. We should stay right where we are!
|> rightArrow
|> ensureFocusOn "light"
|> done
]
@ -41,6 +56,12 @@ ensureFocusOn word textContext =
)
rightArrow : TestContext marker -> TestContext marker
rightArrow =
KeyboardHelpers.pressRightArrow { targetDetails = [] }
[ attribute (Key.tabbable True) ]
marker : Tool ()
marker =
Tool.Marker