2018-04-18 17:59:26 +03:00
|
|
|
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
|
2018-11-12 23:25:37 +03:00
|
|
|
import Nri.Ui.Select.V5
|
2018-04-18 17:59:26 +03:00
|
|
|
import Test exposing (..)
|
|
|
|
import Test.Html.Query as Query
|
|
|
|
import Test.Html.Selector exposing (..)
|
|
|
|
|
|
|
|
|
|
|
|
spec : Test
|
|
|
|
spec =
|
|
|
|
describe "view"
|
2018-11-13 02:38:19 +03:00
|
|
|
[ describe "V5"
|
2018-11-12 23:25:37 +03:00
|
|
|
(viewSuite
|
|
|
|
(\config ->
|
|
|
|
{ choices = config.choices, current = config.current, id = Nothing, valueToString = identity }
|
|
|
|
|> Nri.Ui.Select.V5.view
|
|
|
|
|> Html.Styled.toUnstyled
|
|
|
|
)
|
|
|
|
)
|
2018-04-18 17:59:26 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
]
|
|
|
|
)
|