Merge pull request #1545 from NoRedInk/revert-elm-program-test-dep-change

Revert elm dependencies change due to #1526
This commit is contained in:
Casey Webb 2023-09-28 20:25:20 -05:00 committed by GitHub
commit 2039475336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 381 additions and 185 deletions

View File

@ -7,7 +7,9 @@ import Nri.Test.MouseHelpers.V1 as MouseHelpers
import ProgramTest exposing (..)
import Routes exposing (Route)
import Test exposing (..)
import Test.Html.Selector exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector exposing (..)
import TestApp exposing (app)
@ -36,7 +38,20 @@ suite =
switchIt : String -> ProgramTest a b c -> ProgramTest a b c
switchIt name =
MouseHelpers.click
mhConfig
[ attribute Role.switch
, containing [ text name ]
, id "view-switch-example"
]
mhConfig : MouseHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
mhConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_click = Event.click
, event_mouseDown = Event.mouseDown
, event_mouseUp = Event.mouseUp
, event_mouseOver = Event.mouseOver
, event_custom = Event.custom
}

View File

@ -101,7 +101,6 @@
"dependencies": {
"BrianHicks/elm-particle": "1.5.0 <= v < 2.0.0",
"Gizra/elm-keyboard-event": "1.0.1 <= v < 2.0.0",
"avh4/elm-program-test": "4.0.0 <= v < 5.0.0",
"elm/browser": "1.0.2 <= v < 2.0.0",
"elm/core": "1.0.1 <= v < 2.0.0",
"elm/http": "2.0.0 <= v < 3.0.0",
@ -114,7 +113,6 @@
"elm-community/maybe-extra": "5.3.0 <= v < 6.0.0",
"elm-community/random-extra": "3.2.0 <= v < 4.0.0",
"elm-community/string-extra": "4.0.1 <= v < 5.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0",
"pablohirafuji/elm-markdown": "2.0.5 <= v < 3.0.0",
"rtfeldman/elm-css": "17.0.1 <= v < 19.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4 <= v < 2.0.0",
@ -123,7 +121,9 @@
"tesk9/palette": "3.0.1 <= v < 4.0.0"
},
"test-dependencies": {
"avh4/elm-program-test": "4.0.0 <= v < 5.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm-explorations/test": "2.0.0 <= v < 3.0.0",
"tesk9/accessible-html": "5.0.0 <= v < 6.0.0"
}
}

View File

@ -1,6 +1,7 @@
module Nri.Test.KeyboardHelpers.V1 exposing
( pressKey, releaseKey
, pressTab, pressTabBack, pressEsc, pressSpace, pressDownArrow, pressRightArrow, pressLeftArrow, pressShiftRight, pressShiftLeft, releaseRightArrow, releaseLeftArrow, releaseShiftRight, releaseShiftLeft
, Config
)
{-| `KeyboardHelpers` provides a set of functions to simulate keyboard events for testing Elm programs.
@ -15,29 +16,41 @@ module Nri.Test.KeyboardHelpers.V1 exposing
@docs pressTab, pressTabBack, pressEsc, pressSpace, pressDownArrow, pressRightArrow, pressLeftArrow, pressShiftRight, pressShiftLeft, releaseRightArrow, releaseLeftArrow, releaseShiftRight, releaseShiftLeft
# Config
@docs Config
-}
import Json.Encode as Encode
import ProgramTest exposing (ProgramTest)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector exposing (Selector)
{-| A `Config` allow us to not depend strictly on elm-explorations/test and avh4/elm-program-test packages.
-}
type alias Config programTest selector querySingle =
{ programTest_simulateDomEvent : (querySingle -> querySingle) -> ( String, Encode.Value ) -> programTest -> programTest
, query_find : List selector -> querySingle -> querySingle
, event_custom : String -> Encode.Value -> ( String, Encode.Value )
}
{-| Simulate a "keydown" event on the given element.
-}
pressKey :
{ targetDetails : List ( String, Encode.Value )
, keyCode : Int
, shiftKey : Bool
}
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressKey { targetDetails, keyCode, shiftKey } selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
(Event.custom
Config programTest selector querySingle
->
{ targetDetails : List ( String, Encode.Value )
, keyCode : Int
, shiftKey : Bool
}
-> List selector
-> programTest
-> programTest
pressKey config { targetDetails, keyCode, shiftKey } selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
(config.event_custom
"keydown"
(Encode.object
[ ( "keyCode", Encode.int keyCode )
@ -53,17 +66,19 @@ pressKey { targetDetails, keyCode, shiftKey } selectors =
{-| Simulate a "keyup" event on the given element.
-}
releaseKey :
{ targetDetails : List ( String, Encode.Value )
, keyCode : Int
, shiftKey : Bool
}
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
releaseKey { targetDetails, keyCode, shiftKey } selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
(Event.custom
Config programTest selector querySingle
->
{ targetDetails : List ( String, Encode.Value )
, keyCode : Int
, shiftKey : Bool
}
-> List selector
-> programTest
-> programTest
releaseKey config { targetDetails, keyCode, shiftKey } selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
(config.event_custom
"keyup"
(Encode.object
[ ( "keyCode", Encode.int keyCode )
@ -79,141 +94,154 @@ releaseKey { targetDetails, keyCode, shiftKey } selectors =
{-| Simulate a tab key press on the given element.
-}
pressTab :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressTab { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 9, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressTab config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 9, shiftKey = False }
{-| Simulate a shift-tab key press on the given element.
-}
pressTabBack :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressTabBack { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 9, shiftKey = True }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressTabBack config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 9, shiftKey = True }
{-| Simulate an escape key press on the given element.
-}
pressEsc :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressEsc { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 27, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressEsc config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 27, shiftKey = False }
{-| Simulate a spacebar key press on the given element.
-}
pressSpace :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressSpace { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 32, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressSpace config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 32, shiftKey = False }
{-| Simulate a down arrow key press on the given element.
-}
pressDownArrow :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressDownArrow { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 40, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressDownArrow config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 40, shiftKey = False }
{-| Simulate a right arrow key press on the given element.
-}
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 }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressRightArrow config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 39, shiftKey = False }
{-| Simulate a left arrow key press on the given element.
-}
pressLeftArrow :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressLeftArrow { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 37, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressLeftArrow config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 37, shiftKey = False }
{-| Simulate a right arrow key press with the shift key held down on the given element.
-}
pressShiftRight :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressShiftRight { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 39, shiftKey = True }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressShiftRight config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 39, shiftKey = True }
{-| Simulate a left arrow key press with the shift key held down on the given element.
-}
pressShiftLeft :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
pressShiftLeft { targetDetails } =
pressKey { targetDetails = targetDetails, keyCode = 37, shiftKey = True }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
pressShiftLeft config { targetDetails } =
pressKey config { targetDetails = targetDetails, keyCode = 37, shiftKey = True }
{-| Simulate a right arrow key release on the given element.
-}
releaseRightArrow :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
releaseRightArrow { targetDetails } =
releaseKey { targetDetails = targetDetails, keyCode = 39, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
releaseRightArrow config { targetDetails } =
releaseKey config { targetDetails = targetDetails, keyCode = 39, shiftKey = False }
{-| Simulate a left arrow key release on the given element.
-}
releaseLeftArrow :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
releaseLeftArrow { targetDetails } =
releaseKey { targetDetails = targetDetails, keyCode = 37, shiftKey = False }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
releaseLeftArrow config { targetDetails } =
releaseKey config { targetDetails = targetDetails, keyCode = 37, shiftKey = False }
{-| Simulate a right arrow key release with the shift key held down on the given element.
-}
releaseShiftRight :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
releaseShiftRight { targetDetails } =
releaseKey { targetDetails = targetDetails, keyCode = 39, shiftKey = True }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
releaseShiftRight config { targetDetails } =
releaseKey config { targetDetails = targetDetails, keyCode = 39, shiftKey = True }
{-| Simulate a left arrow key release with the shift key held down on the given element.
-}
releaseShiftLeft :
{ targetDetails : List ( String, Encode.Value ) }
-> List Selector
-> ProgramTest model msg effect
-> ProgramTest model msg effect
releaseShiftLeft { targetDetails } =
releaseKey { targetDetails = targetDetails, keyCode = 37, shiftKey = True }
Config programTest selector querySingle
-> { targetDetails : List ( String, Encode.Value ) }
-> List selector
-> programTest
-> programTest
releaseShiftLeft config { targetDetails } =
releaseKey config { targetDetails = targetDetails, keyCode = 37, shiftKey = True }

View File

@ -1,6 +1,7 @@
module Nri.Test.MouseHelpers.V1 exposing
( click, mouseDown, mouseUp, mouseOver
, cancelableMouseDown, cancelableMouseUp, cancelableMouseOver
, Config
)
{-| `MouseHelpers` provides a set of functions to simulate mouse events for testing Elm programs.
@ -15,58 +16,72 @@ module Nri.Test.MouseHelpers.V1 exposing
@docs cancelableMouseDown, cancelableMouseUp, cancelableMouseOver
# Config
@docs Config
-}
import Json.Encode as Encode
import ProgramTest exposing (ProgramTest)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector exposing (Selector)
{-| A `Config` allow us to not depend strictly on elm-explorations/test and avh4/elm-program-test packages.
-}
type alias Config programTest selector querySingle =
{ programTest_simulateDomEvent : (querySingle -> querySingle) -> ( String, Encode.Value ) -> programTest -> programTest
, query_find : List selector -> querySingle -> querySingle
, event_click : ( String, Encode.Value )
, event_mouseDown : ( String, Encode.Value )
, event_mouseUp : ( String, Encode.Value )
, event_mouseOver : ( String, Encode.Value )
, event_custom : String -> Encode.Value -> ( String, Encode.Value )
}
{-| Simulate a click event on elements that match the given selectors.
-}
click : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
click selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
Event.click
click : Config programTest selector querySingle -> List selector -> programTest -> programTest
click config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
config.event_click
{-| Simulate a mouse down event on elements that match the given selectors.
-}
mouseDown : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
mouseDown selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
Event.mouseDown
mouseDown : Config programTest selector querySingle -> List selector -> programTest -> programTest
mouseDown config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
config.event_mouseDown
{-| Simulate a mouse up event on elements that match the given selectors.
-}
mouseUp : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
mouseUp selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
Event.mouseUp
mouseUp : Config programTest selector querySingle -> List selector -> programTest -> programTest
mouseUp config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
config.event_mouseUp
{-| Simulate a mouse over event on elements that match the given selectors.
-}
mouseOver : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
mouseOver selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
Event.mouseOver
mouseOver : Config programTest selector querySingle -> List selector -> programTest -> programTest
mouseOver config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
config.event_mouseOver
{-| Simulate a cancelable mouse down event on elements that match the given selectors.
-}
cancelableMouseDown : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
cancelableMouseDown selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
(Event.custom
cancelableMouseDown : Config programTest selector querySingle -> List selector -> programTest -> programTest
cancelableMouseDown config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
(config.event_custom
"mousedown"
(Encode.object [ ( "cancelable", Encode.bool True ) ])
)
@ -74,11 +89,11 @@ cancelableMouseDown selectors =
{-| Simulate a cancelable mouse up event on elements that match the given selectors.
-}
cancelableMouseUp : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
cancelableMouseUp selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
(Event.custom
cancelableMouseUp : Config programTest selector querySingle -> List selector -> programTest -> programTest
cancelableMouseUp config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
(config.event_custom
"mouseup"
(Encode.object [ ( "cancelable", Encode.bool True ) ])
)
@ -86,11 +101,11 @@ cancelableMouseUp selectors =
{-| Simulate a cancelable mouse over event on elements that match the given selectors.
-}
cancelableMouseOver : List Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
cancelableMouseOver selectors =
ProgramTest.simulateDomEvent
(Query.find selectors)
(Event.custom
cancelableMouseOver : Config programTest selector querySingle -> List selector -> programTest -> programTest
cancelableMouseOver config selectors =
config.programTest_simulateDomEvent
(config.query_find selectors)
(config.event_custom
"mouseover"
(Encode.object [ ( "cancelable", Encode.bool True ) ])
)

View File

@ -11,7 +11,7 @@ import Spec.Helpers exposing (expectFailure)
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector exposing (..)
import Test.Html.Selector as Selector exposing (..)
spec : Test
@ -124,7 +124,7 @@ helpfullyDisabledCheckbox =
pressSpace : TestContext -> TestContext
pressSpace =
KeyboardHelpers.pressSpace { targetDetails = [] } checkbox
KeyboardHelpers.pressSpace khConfig { targetDetails = [] } checkbox
clickIt : TestContext -> TestContext
@ -188,3 +188,11 @@ program attributes =
, view = view attributes >> toUnstyled
}
|> ProgramTest.start ()
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -3,10 +3,12 @@ module Spec.Nri.Ui.FocusLoop exposing (spec)
import Accessibility.Styled.Key as Key exposing (Event)
import Expect
import Html.Styled as Html exposing (Html)
import Nri.Test.KeyboardHelpers.V1 exposing (pressLeftArrow, pressRightArrow)
import Nri.Test.KeyboardHelpers.V1 as KeyboardHelpers
import Nri.Ui.FocusLoop.V1 as FocusLoop
import ProgramTest exposing (..)
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector
@ -182,7 +184,8 @@ viewSpec =
[ test "moves focus right on right arrow" <|
\() ->
program
|> pressRightArrow { targetDetails = [] }
|> KeyboardHelpers.pressRightArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -194,7 +197,8 @@ viewSpec =
, test "moves focus left on left arrow" <|
\() ->
program
|> pressLeftArrow { targetDetails = [] }
|> KeyboardHelpers.pressLeftArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -206,7 +210,8 @@ viewSpec =
, test "loops to end" <|
\() ->
program
|> pressLeftArrow { targetDetails = [] }
|> KeyboardHelpers.pressLeftArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -218,7 +223,8 @@ viewSpec =
, test "loops to beginning" <|
\() ->
program
|> pressRightArrow { targetDetails = [] }
|> KeyboardHelpers.pressRightArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -274,3 +280,11 @@ program =
, view = view >> Html.div [] >> Html.toUnstyled
}
|> ProgramTest.start ()
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -9,10 +9,12 @@ module Spec.Nri.Ui.FocusLoopLazy exposing (spec)
import Accessibility.Styled.Key as Key
import Expect
import Html.Styled as Html exposing (Html)
import Nri.Test.KeyboardHelpers.V1 exposing (pressLeftArrow, pressRightArrow)
import Nri.Test.KeyboardHelpers.V1 as KeyboardHelpers
import Nri.Ui.FocusLoop.Lazy.V1 as FocusLoop
import ProgramTest exposing (..)
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector
@ -29,7 +31,8 @@ viewSpec =
[ test "moves focus right on right arrow" <|
\() ->
program
|> pressRightArrow { targetDetails = [] }
|> KeyboardHelpers.pressRightArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -41,7 +44,8 @@ viewSpec =
, test "moves focus left on left arrow" <|
\() ->
program
|> pressLeftArrow { targetDetails = [] }
|> KeyboardHelpers.pressLeftArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -53,7 +57,8 @@ viewSpec =
, test "loops to end" <|
\() ->
program
|> pressLeftArrow { targetDetails = [] }
|> KeyboardHelpers.pressLeftArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -65,7 +70,8 @@ viewSpec =
, test "loops to beginning" <|
\() ->
program
|> pressRightArrow { targetDetails = [] }
|> KeyboardHelpers.pressRightArrow khConfig
{ targetDetails = [] }
[ Selector.all
[ Selector.tag "button"
, Selector.containing
@ -122,3 +128,11 @@ program =
, view = view >> Html.div [] >> Html.toUnstyled
}
|> ProgramTest.start ()
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -15,6 +15,7 @@ import ProgramTest exposing (..)
import Sort
import Spec.PseudoElements exposing (..)
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector exposing (Selector)
@ -519,54 +520,61 @@ highlightable index selector =
space : TestContext -> TestContext
space =
KeyboardHelpers.pressSpace { targetDetails = [] }
KeyboardHelpers.pressSpace khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
rightArrow : TestContext -> TestContext
rightArrow =
KeyboardHelpers.pressRightArrow { targetDetails = [] }
KeyboardHelpers.pressRightArrow khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
leftArrow : TestContext -> TestContext
leftArrow =
KeyboardHelpers.pressLeftArrow { targetDetails = [] }
KeyboardHelpers.pressLeftArrow khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
shiftRight : TestContext -> TestContext
shiftRight =
KeyboardHelpers.pressShiftRight { targetDetails = [] }
KeyboardHelpers.pressShiftRight khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
shiftLeft : TestContext -> TestContext
shiftLeft =
KeyboardHelpers.pressShiftLeft { targetDetails = [] }
KeyboardHelpers.pressShiftLeft khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
releaseShiftRight : TestContext -> TestContext
releaseShiftRight =
KeyboardHelpers.releaseShiftRight { targetDetails = [] }
KeyboardHelpers.releaseShiftRight khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
releaseShiftLeft : TestContext -> TestContext
releaseShiftLeft =
KeyboardHelpers.releaseShiftLeft { targetDetails = [] }
KeyboardHelpers.releaseShiftLeft khConfig
{ targetDetails = [] }
[ Selector.attribute (Key.tabbable True) ]
mouseDown : String -> TestContext -> TestContext
mouseDown word =
MouseHelpers.cancelableMouseDown [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
MouseHelpers.cancelableMouseDown mhConfig [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
mouseUp : String -> TestContext -> TestContext
mouseUp word =
MouseHelpers.cancelableMouseUp [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
MouseHelpers.cancelableMouseUp mhConfig [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
click : String -> TestContext -> TestContext
@ -576,7 +584,7 @@ click word =
mouseOver : String -> TestContext -> TestContext
mouseOver word =
MouseHelpers.cancelableMouseOver [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
MouseHelpers.cancelableMouseOver mhConfig [ Selector.tag "span", Selector.containing [ Selector.text word ] ]
markerModel : Maybe String -> Tool String
@ -930,3 +938,23 @@ overlappingHighlightTests =
in
[ describe "viewWithOverlappingHighlights" (staticAssertions Highlighter.viewWithOverlappingHighlights)
]
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}
mhConfig : MouseHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
mhConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_click = Event.click
, event_mouseDown = Event.mouseDown
, event_mouseUp = Event.mouseUp
, event_mouseOver = Event.mouseOver
, event_custom = Event.custom
}

View File

@ -57,14 +57,16 @@ spec =
, test "Opens on down arrow" <|
\() ->
program []
|> KeyboardHelpers.pressDownArrow { targetDetails = targetDetails "hello-button" }
|> KeyboardHelpers.pressDownArrow khConfig
{ targetDetails = targetDetails "hello-button" }
[ Selector.tag "button", Selector.id "hello-button" ]
|> ensureViewHas (menuContentSelector menuContent)
|> ProgramTest.done
, test "Opens on down arrow when there's a tooltip attached" <|
\() ->
program [ Menu.withTooltip [ Tooltip.onToggle ToggleTooltip ] ]
|> KeyboardHelpers.pressDownArrow { targetDetails = targetDetails "hello-button" }
|> KeyboardHelpers.pressDownArrow khConfig
{ targetDetails = targetDetails "hello-button" }
[ Selector.tag "button", Selector.id "hello-button" ]
|> ensureViewHas (menuContentSelector menuContent)
|> ProgramTest.done
@ -225,20 +227,28 @@ targetDetails targetId =
pressTab : { targetId : String } -> ProgramTest model msg effect -> ProgramTest model msg effect
pressTab { targetId } =
KeyboardHelpers.pressTab
KeyboardHelpers.pressTab khConfig
{ targetDetails = targetDetails targetId }
[ Selector.class "Container" ]
pressTabBack : { targetId : String } -> ProgramTest model msg effect -> ProgramTest model msg effect
pressTabBack { targetId } =
KeyboardHelpers.pressTabBack
KeyboardHelpers.pressTabBack khConfig
{ targetDetails = targetDetails targetId }
[ Selector.class "Container" ]
pressEsc : { targetId : String } -> ProgramTest model msg effect -> ProgramTest model msg effect
pressEsc { targetId } =
KeyboardHelpers.pressEsc
KeyboardHelpers.pressEsc khConfig
{ targetDetails = targetDetails targetId }
[ Selector.class "Container" ]
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -7,12 +7,14 @@ import Html.Styled as Html exposing (Html, toUnstyled)
import Html.Styled.Attributes as Attributes
import Html.Styled.Events as Events
import Json.Encode as Encode
import Nri.Test.KeyboardHelpers.V1 exposing (pressTab, pressTabBack)
import Nri.Test.KeyboardHelpers.V1 as KeyboardHelpers
import Nri.Ui.Modal.V12 as Modal
import ProgramTest exposing (..)
import SimulatedEffect.Cmd
import Test exposing (..)
import Test.Html.Selector exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector exposing (..)
spec : Test
@ -81,12 +83,12 @@ focusTests =
tabBackWithinModal : String -> ProgramTest a b c -> ProgramTest a b c
tabBackWithinModal onElementId =
pressTabBack { targetDetails = [ ( "id", Encode.string onElementId ) ] } focusTrapNode
KeyboardHelpers.pressTabBack khConfig { targetDetails = [ ( "id", Encode.string onElementId ) ] } focusTrapNode
tabForwardWithinModal : String -> ProgramTest a b c -> ProgramTest a b c
tabForwardWithinModal onElementId =
pressTab { targetDetails = [ ( "id", Encode.string onElementId ) ] } focusTrapNode
KeyboardHelpers.pressTab khConfig { targetDetails = [ ( "id", Encode.string onElementId ) ] } focusTrapNode
focusTrapNode : List Selector
@ -197,3 +199,11 @@ modalTitle =
ensureFocused : String -> ProgramTest a b Effect -> ProgramTest a b Effect
ensureFocused id =
ensureLastEffect (Expect.equal (FocusOn id))
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -10,6 +10,7 @@ import Nri.Ui.SegmentedControl.V14 as SegmentedControl
import ProgramTest exposing (..)
import Task
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector
@ -155,13 +156,15 @@ ensureOnlyOneTabInSequence tabs testContext =
releaseRightArrow : TestContext -> TestContext
releaseRightArrow =
KeyboardHelpers.releaseRightArrow { targetDetails = [] }
KeyboardHelpers.releaseRightArrow khConfig
{ targetDetails = [] }
[ Selector.attribute Role.tab, Selector.attribute (Key.tabbable True) ]
releaseLeftArrow : TestContext -> TestContext
releaseLeftArrow =
KeyboardHelpers.releaseLeftArrow { targetDetails = [] }
KeyboardHelpers.releaseLeftArrow khConfig
{ targetDetails = [] }
[ Selector.attribute Role.tab, Selector.attribute (Key.tabbable True) ]
@ -246,3 +249,11 @@ program =
, view = view >> Html.toUnstyled
}
|> ProgramTest.start ()
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -9,7 +9,9 @@ import Nri.Ui.Switch.V3 as Switch
import ProgramTest exposing (..)
import Spec.Helpers exposing (expectFailure)
import Test exposing (..)
import Test.Html.Selector exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector exposing (..)
spec : Test
@ -74,12 +76,12 @@ helpfullyDisabledSwitch =
pressSpace : TestContext -> TestContext
pressSpace =
KeyboardHelpers.pressSpace { targetDetails = [] } switch
KeyboardHelpers.pressSpace khConfig { targetDetails = [] } switch
click : TestContext -> TestContext
click =
MouseHelpers.click switch
MouseHelpers.click mhConfig switch
switch : List Selector
@ -132,3 +134,23 @@ program attributes =
, view = view attributes >> toUnstyled
}
|> ProgramTest.start ()
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}
mhConfig : MouseHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
mhConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_click = Event.click
, event_mouseDown = Event.mouseDown
, event_mouseUp = Event.mouseUp
, event_mouseOver = Event.mouseOver
, event_custom = Event.custom
}

View File

@ -155,7 +155,8 @@ spec =
, Tooltip.onTriggerKeyDown
[ Key.space SpaceKeyPressed ]
]
|> KeyboardHelpers.pressSpace { targetDetails = [] }
|> KeyboardHelpers.pressSpace khConfig
{ targetDetails = [] }
[ Selector.id triggerId
]
|> ProgramTest.expectModel (\model -> Expect.equal (Just SpaceKeyPressed) model.lastMsg)
@ -238,3 +239,11 @@ clickButtonByLabel label =
]
)
Event.click
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -7,6 +7,7 @@ import Expect
import Html.Styled exposing (..)
import Nri.Test.KeyboardHelpers.V1 as KeyboardHelpers
import ProgramTest exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
import Test.Html.Selector as Selector
@ -86,11 +87,21 @@ ensureOnlyOneTabInSequence tabs testContext =
releaseRightArrow : ProgramTest model msg effect -> ProgramTest model msg effect
releaseRightArrow =
KeyboardHelpers.releaseRightArrow { targetDetails = [] }
KeyboardHelpers.releaseRightArrow khConfig
{ targetDetails = [] }
[ Selector.attribute Role.tab, Selector.attribute (Key.tabbable True) ]
releaseLeftArrow : ProgramTest model msg effect -> ProgramTest model msg effect
releaseLeftArrow =
KeyboardHelpers.releaseLeftArrow { targetDetails = [] }
KeyboardHelpers.releaseLeftArrow khConfig
{ targetDetails = [] }
[ Selector.attribute Role.tab, Selector.attribute (Key.tabbable True) ]
khConfig : KeyboardHelpers.Config (ProgramTest model msg effect) Selector.Selector (Query.Single msg)
khConfig =
{ programTest_simulateDomEvent = ProgramTest.simulateDomEvent
, query_find = Query.find
, event_custom = Event.custom
}

View File

@ -4,6 +4,7 @@
"Browser.Events.Extra",
"Nri.Test.KeyboardHelpers.V1",
"Nri.Test.MouseHelpers.V1",
"Nri.Ui",
"Nri.Ui.Accordion.V3",
"Nri.Ui.AnimatedIcon.V1",
"Nri.Ui.AssignmentIcon.V2",