Skip to content

Commit e2f2cc1

Browse files
committed
Add tests for keyedLazy
1 parent 86bd904 commit e2f2cc1

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tests/Styled.elm

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ module Styled exposing (all)
33
-- import ReadmeExample
44

55
import Css exposing (..)
6+
import Css.Media as Media
67
import Html.Styled exposing (Html, a, button, div, header, img, nav, text, toUnstyled)
78
import Html.Styled.Attributes exposing (class, css, src)
9+
import Html.Styled.Lazy exposing (keyedLazy)
810
import Test exposing (Test, describe)
911
import Test.Html.Query as Query
1012
import Test.Html.Selector as Selector
@@ -108,6 +110,7 @@ all =
108110
]
109111
)
110112
, bug564
113+
, keyedLazyTests
111114
]
112115

113116

@@ -141,3 +144,49 @@ bug564 =
141144
|> Query.fromHtml
142145
|> Query.has [ Selector.classes [ "_5dc67897", "some-custom-class" ] ]
143146
]
147+
148+
149+
keyedLazyTests : Test
150+
keyedLazyTests =
151+
describe "keyedLazy"
152+
[ Test.test "generates an appropriate selector for the root node" <|
153+
\_ ->
154+
keyedLazy
155+
(\i ->
156+
( "item-" ++ String.fromInt i
157+
, div [ css [ color (rgb 0 0 0) ] ] []
158+
)
159+
)
160+
1
161+
|> toUnstyled
162+
|> Query.fromHtml
163+
|> Query.has [ Selector.text "#item-1._5dc67897" ]
164+
, Test.test "generates an appropriate selector for a descendant node" <|
165+
\_ ->
166+
keyedLazy
167+
(\i ->
168+
( "item-" ++ String.fromInt i
169+
, div []
170+
[ div [ css [ color (rgb 0 0 0) ] ] []
171+
]
172+
)
173+
)
174+
1
175+
|> toUnstyled
176+
|> Query.fromHtml
177+
|> Query.has [ Selector.text "#item-1 ._5dc67897" ]
178+
, Test.test "generates an appropriate selector with media" <|
179+
\_ ->
180+
keyedLazy
181+
(\i ->
182+
( "item-" ++ String.fromInt i
183+
, div []
184+
[ div [ css [ Media.withMedia [ Media.only Media.screen [] ] [ color (rgb 0 0 0) ] ] ] []
185+
]
186+
)
187+
)
188+
1
189+
|> toUnstyled
190+
|> Query.fromHtml
191+
|> Query.has [ Selector.text "#item-1 ._22afe2eb" ]
192+
]

0 commit comments

Comments
 (0)