From 303040e405134d19170ab40f327324be7d10410d Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Tue, 12 Apr 2022 11:05:17 -0700 Subject: [PATCH] Adds basic test per Derek's question --- tests/Spec/Nri/Ui/Switch.elm | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/Spec/Nri/Ui/Switch.elm diff --git a/tests/Spec/Nri/Ui/Switch.elm b/tests/Spec/Nri/Ui/Switch.elm new file mode 100644 index 00000000..d8451ba3 --- /dev/null +++ b/tests/Spec/Nri/Ui/Switch.elm @@ -0,0 +1,45 @@ +module Spec.Nri.Ui.Switch exposing (spec) + +import Accessibility.Widget as Widget +import Html.Styled as HtmlStyled +import Nri.Ui.Switch.V1 as Switch +import ProgramTest exposing (..) +import Test exposing (..) +import Test.Html.Selector as Selector + + +spec : Test +spec = + describe "Nri.Ui.Switch.V1" + [ test "it works" <| + \() -> + program + [ Switch.label (HtmlStyled.text "Switch") + , Switch.onSwitch identity + , Switch.id "switch" + ] + True + -- switch starts with aria-checked=true and displays the label + |> ensureViewHas + [ Selector.attribute (Widget.checked (Just True)) + , Selector.text "Switch" + ] + -- user can click the first switch + |> check "switch" "Switch" False + -- the switch now has aria-checked=false + |> ensureViewHas + [ Selector.attribute (Widget.checked (Just False)) + , Selector.text "Switch" + ] + |> done + ] + + +program : List (Switch.Attribute Bool) -> Bool -> ProgramTest Bool Bool () +program attributes init = + ProgramTest.createSandbox + { init = init + , update = \msg model -> msg + , view = \isOpen -> Switch.view attributes isOpen |> HtmlStyled.toUnstyled + } + |> ProgramTest.start ()