Skip to content

Commit 31c3820

Browse files
committedMar 1, 2023
Add tests for #213
1 parent cda4e92 commit 31c3820

File tree

1 file changed

+94
-12
lines changed

1 file changed

+94
-12
lines changed
 

‎tests/src/Test/Html/SelectorTests.elm

+94-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Html
88
import Html.Attributes as Attr
99
import Test exposing (..)
1010
import Test.Html.Query as Query
11-
import Test.Html.Selector exposing (..)
11+
import Test.Html.Selector as Selector
1212

1313

1414
all : Test
@@ -17,6 +17,7 @@ all =
1717
[ bug13
1818
, textSelectors
1919
, exactTextSelectors
20+
, selectorAll
2021
]
2122

2223

@@ -32,14 +33,25 @@ bug13 =
3233
, Html.text "Text2"
3334
]
3435
|> Query.fromHtml
35-
|> Query.has [ text "Text1", text "Text2" ]
36+
|> Query.has
37+
[ Selector.text "Text1"
38+
, Selector.text "Text2"
39+
]
3640
, test "the welcome <h1> says hello!" <|
3741
\() ->
3842
Html.div []
39-
[ Html.h1 [ Attr.title "greeting", Attr.class "me" ] [ Html.text "Hello!" ] ]
43+
[ Html.h1
44+
[ Attr.title "greeting"
45+
, Attr.class "me"
46+
]
47+
[ Html.text "Hello!" ]
48+
]
4049
|> Query.fromHtml
41-
|> Query.find [ attribute (Attr.title "greeting") ]
42-
|> Query.has [ text "Hello!", class "me" ]
50+
|> Query.find [ Selector.attribute (Attr.title "greeting") ]
51+
|> Query.has
52+
[ Selector.text "Hello!"
53+
, Selector.class "me"
54+
]
4355
]
4456

4557

@@ -56,7 +68,7 @@ textSelectors =
5668
in
5769
Html.div [] textNodes
5870
|> Query.fromHtml
59-
|> Query.has [ text str ]
71+
|> Query.has [ Selector.text str ]
6072
, fuzz3 (list string) (list string) (list string) "Finds multiple results" <|
6173
\before strings after ->
6274
let
@@ -67,7 +79,7 @@ textSelectors =
6779
in
6880
Html.div [] textNodes
6981
|> Query.fromHtml
70-
|> Query.has (List.map text strings)
82+
|> Query.has (List.map Selector.text strings)
7183
, fuzz3 (list string) string (list string) "Finds a submatch" <|
7284
\before str after ->
7385
let
@@ -78,7 +90,7 @@ textSelectors =
7890
in
7991
Html.div [] textNodes
8092
|> Query.fromHtml
81-
|> Query.has [ text str ]
93+
|> Query.has [ Selector.text str ]
8294
]
8395

8496

@@ -100,7 +112,7 @@ exactTextSelectors =
100112
in
101113
Html.div [] textNodes
102114
|> Query.fromHtml
103-
|> Query.has [ exactText str ]
115+
|> Query.has [ Selector.exactText str ]
104116
, fuzz3 (list string) (list string) (list string) "Finds multiple results" <|
105117
\before strings after ->
106118
let
@@ -111,7 +123,7 @@ exactTextSelectors =
111123
in
112124
Html.div [] textNodes
113125
|> Query.fromHtml
114-
|> Query.has (List.map exactText strings)
126+
|> Query.has (List.map Selector.exactText strings)
115127
, fuzz3 (list nonemptyString) nonemptyString (list nonemptyString) "Doesn't find a submatch" <|
116128
\before str after ->
117129
let
@@ -136,12 +148,82 @@ exactTextSelectors =
136148
in
137149
Html.div [] textNodes
138150
|> Query.fromHtml
139-
|> Query.hasNot [ exactText str2 ]
151+
|> Query.hasNot [ Selector.exactText str2 ]
140152
, test "Trimming is not happening" <|
141153
\() ->
142154
Html.div [] [ Html.text """
143155
We like whitespace
144156
""" ]
145157
|> Query.fromHtml
146-
|> Query.hasNot [ exactText "We like whitespace" ]
158+
|> Query.hasNot [ Selector.exactText "We like whitespace" ]
159+
]
160+
161+
162+
selectorAll : Test
163+
selectorAll =
164+
describe "Selector.all"
165+
[ test "passes if empty" <|
166+
\() ->
167+
Html.fieldset [ Attr.disabled False ]
168+
[ Html.button [ Attr.disabled True ]
169+
[ Html.text "Reply"
170+
]
171+
]
172+
|> Query.fromHtml
173+
|> Query.has [ Selector.all [] ]
174+
, test "passes if single selector matches" <|
175+
\() ->
176+
Html.fieldset [ Attr.disabled False ]
177+
[ Html.button [ Attr.disabled True ]
178+
[ Html.text "Reply"
179+
]
180+
]
181+
|> Query.fromHtml
182+
|> Query.has
183+
[ Selector.all
184+
[ Selector.tag "fieldset"
185+
]
186+
]
187+
, test "passes if all selectors match" <|
188+
\() ->
189+
Html.fieldset [ Attr.disabled False ]
190+
[ Html.button [ Attr.disabled True ]
191+
[ Html.text "Reply"
192+
]
193+
]
194+
|> Query.fromHtml
195+
|> Query.has
196+
[ Selector.all
197+
[ Selector.tag "fieldset"
198+
, Selector.attribute (Attr.disabled False)
199+
]
200+
]
201+
, test "fails if some but not all selectors match (regression for #213)" <|
202+
\() ->
203+
Html.fieldset [ Attr.disabled False ]
204+
[ Html.button [ Attr.disabled True ]
205+
[ Html.text "Reply"
206+
]
207+
]
208+
|> Query.fromHtml
209+
|> Query.hasNot
210+
[ Selector.all
211+
[ Selector.tag "fieldset"
212+
, Selector.attribute (Attr.disabled True)
213+
]
214+
]
215+
, test "fails if no selectors match" <|
216+
\() ->
217+
Html.fieldset [ Attr.disabled False ]
218+
[ Html.button [ Attr.disabled True ]
219+
[ Html.text "Reply"
220+
]
221+
]
222+
|> Query.fromHtml
223+
|> Query.hasNot
224+
[ Selector.all
225+
[ Selector.tag "strong"
226+
, Selector.attribute (Attr.disabled True)
227+
]
228+
]
147229
]

0 commit comments

Comments
 (0)
Please sign in to comment.