noredink-ui/tests/Spec/Nri/Ui/Select.elm

68 lines
1.8 KiB
Elm
Raw Normal View History

module Spec.Nri.Ui.Select exposing (spec)
import Expect exposing (Expectation)
import Html
import Html.Attributes as Attr
2018-07-11 03:55:18 +03:00
import Html.Styled
import Nri.Ui.Select.V5
import Test exposing (..)
import Test.Html.Query as Query
import Test.Html.Selector exposing (..)
spec : Test
spec =
describe "view"
[ describe "V5"
(viewSuite
(\config ->
{ choices = config.choices, current = config.current, id = Nothing, valueToString = identity }
|> Nri.Ui.Select.V5.view
|> Html.Styled.toUnstyled
)
)
]
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
}
]
)