Adds tests, exposing that the custom attributes aren't appropriately added currently

This commit is contained in:
Tessa Kelly 2023-08-04 16:00:40 -06:00
parent 75c15aed9f
commit 284306fd1f
4 changed files with 55 additions and 10 deletions

9
tests/Spec/Helpers.elm Normal file
View File

@ -0,0 +1,9 @@
module Spec.Helpers exposing (..)
import Html.Attributes as Attributes
import Test.Html.Selector as Selector
nriDescription : String -> Selector.Selector
nriDescription desc =
Selector.attribute (Attributes.attribute "data-nri-description" desc)

View File

@ -7,6 +7,7 @@ import Nri.Ui.ClickableText.V3 as ClickableText
import Nri.Ui.Menu.V4 as Menu
import Nri.Ui.Tooltip.V3 as Tooltip
import ProgramTest exposing (ProgramTest, ensureViewHas, ensureViewHasNot)
import Spec.Helpers exposing (nriDescription)
import Spec.KeyboardHelpers as KeyboardHelpers
import Test exposing (..)
import Test.Html.Event as Event
@ -202,11 +203,6 @@ menuDialogContentSelector content =
]
nriDescription : String -> Selector.Selector
nriDescription desc =
Selector.attribute (Attributes.attribute "data-nri-description" desc)
mouseEnter : List Selector.Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
mouseEnter selectors =
ProgramTest.simulateDomEvent (Query.find selectors) Event.mouseEnter

View File

@ -5,6 +5,9 @@ import Expect exposing (Expectation)
import Html.Attributes as Attributes
import Html.Styled exposing (toUnstyled)
import Nri.Ui.SideNav.V5 as SideNav exposing (Entry)
import Nri.Ui.Svg.V1 as Svg
import Nri.Ui.UiIcon.V1 as UiIcon
import Spec.Helpers exposing (nriDescription)
import Test exposing (..)
import Test.Html.Query as Query
import Test.Html.Selector exposing (..)
@ -14,6 +17,7 @@ spec : Test
spec =
describe "SideNav"
[ describe "tags the current page correctly" currentPageTests
, describe "compactGroup" compactGroupTests
]
@ -102,6 +106,46 @@ mobilePageName =
attribute (Attributes.attribute "data-nri-description" "mobile-current-page-name")
compactGroupTests : List Test
compactGroupTests =
let
view view_ =
viewQuery { currentRoute = "/" } [ view_ ]
in
[ describe "without any children"
[ test "category renders" <|
\() ->
SideNav.compactGroup "Category" [] []
|> view
|> Query.has [ text "Category" ]
, test "icon renders" <|
\() ->
SideNav.compactGroup "Category"
[ SideNav.icon (Svg.withLabel "eyeballs" UiIcon.seeMore)
]
[]
|> view
|> Query.has [ tag "title", containing [ text "eyeballs" ] ]
, test "right icon renders" <|
\() ->
SideNav.compactGroup "Category"
[ SideNav.rightIcon (Svg.withLabel "kebab" UiIcon.kebab)
]
[]
|> view
|> Query.has [ tag "title", containing [ text "kebab" ] ]
, test "custom attributes are attached" <|
\() ->
SideNav.compactGroup "Category"
[ SideNav.nriDescription "eyeball-kebab"
]
[]
|> view
|> Query.has [ nriDescription "eyeball-kebab" ]
]
]
viewQuery :
{ currentRoute : String }
-> List (Entry String ())

View File

@ -5,6 +5,7 @@ import Html.Attributes as Attributes
import Html.Styled as HtmlStyled
import Nri.Ui.Tooltip.V3 as Tooltip
import ProgramTest exposing (ProgramTest, ensureViewHas, ensureViewHasNot)
import Spec.Helpers exposing (nriDescription)
import Test exposing (..)
import Test.Html.Event as Event
import Test.Html.Query as Query
@ -106,11 +107,6 @@ tooltipContentSelector tooltipContent =
]
nriDescription : String -> Selector.Selector
nriDescription desc =
Selector.attribute (Attributes.attribute "data-nri-description" desc)
mouseEnter : List Selector.Selector -> ProgramTest model msg effect -> ProgramTest model msg effect
mouseEnter selectors =
ProgramTest.simulateDomEvent (Query.find selectors) Event.mouseEnter