mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-18 11:11:38 +03:00
cbb7c34225
We make a suite that checks the behavior of both versions. Assuming they have the same API, this should work. If we add another version and it changes the API, we might want to rethink this approach.
62 lines
1.6 KiB
Elm
62 lines
1.6 KiB
Elm
module Spec.Nri.Ui.Select exposing (spec)
|
|
|
|
import Expect exposing (Expectation)
|
|
import Html
|
|
import Html.Attributes as Attr
|
|
import Nri.Ui.Select.V1
|
|
import Nri.Ui.Select.V2
|
|
import Test exposing (..)
|
|
import Test.Html.Query as Query
|
|
import Test.Html.Selector exposing (..)
|
|
|
|
|
|
spec : Test
|
|
spec =
|
|
describe "view"
|
|
[ describe "V1" (viewSuite Nri.Ui.Select.V1.view)
|
|
, describe "V2" (viewSuite Nri.Ui.Select.V2.view)
|
|
]
|
|
|
|
|
|
viewSuite :
|
|
({ choices : List { label : String, value : String }, current : String } -> Html.Html msg)
|
|
-> List Test
|
|
viewSuite view =
|
|
[ test "shows all options" <|
|
|
\() ->
|
|
viewTest
|
|
view
|
|
"Tacos"
|
|
[ "Tacos", "Burritos", "Enchiladas" ]
|
|
|> Query.find [ tag "select" ]
|
|
|> Query.findAll [ tag "option" ]
|
|
|> Query.count (Expect.equal 3)
|
|
, test "selects the current option" <|
|
|
\() ->
|
|
viewTest
|
|
view
|
|
"Burritos"
|
|
[ "Tacos", "Burritos", "Enchiladas" ]
|
|
|> Query.find
|
|
[ tag "option"
|
|
, attribute <| Attr.selected True
|
|
]
|
|
|> Query.has [ text "Burritos" ]
|
|
]
|
|
|
|
|
|
viewTest :
|
|
({ choices : List { label : a, value : a }, current : b } -> Html.Html msg)
|
|
-> b
|
|
-> List a
|
|
-> Query.Single msg
|
|
viewTest view selected items =
|
|
Query.fromHtml
|
|
(Html.div []
|
|
[ view
|
|
{ choices = List.map (\x -> { label = x, value = x }) items
|
|
, current = selected
|
|
}
|
|
]
|
|
)
|