Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Selector.all scope #214

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 94 additions & 12 deletions tests/src/Test/Html/SelectorTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Html
import Html.Attributes as Attr
import Test exposing (..)
import Test.Html.Query as Query
import Test.Html.Selector exposing (..)
import Test.Html.Selector as Selector


all : Test
Expand All @@ -17,6 +17,7 @@ all =
[ bug13
, textSelectors
, exactTextSelectors
, selectorAll
]


Expand All @@ -32,14 +33,25 @@ bug13 =
, Html.text "Text2"
]
|> Query.fromHtml
|> Query.has [ text "Text1", text "Text2" ]
|> Query.has
[ Selector.text "Text1"
, Selector.text "Text2"
]
, test "the welcome <h1> says hello!" <|
\() ->
Html.div []
[ Html.h1 [ Attr.title "greeting", Attr.class "me" ] [ Html.text "Hello!" ] ]
[ Html.h1
[ Attr.title "greeting"
, Attr.class "me"
]
[ Html.text "Hello!" ]
]
|> Query.fromHtml
|> Query.find [ attribute (Attr.title "greeting") ]
|> Query.has [ text "Hello!", class "me" ]
|> Query.find [ Selector.attribute (Attr.title "greeting") ]
|> Query.has
[ Selector.text "Hello!"
, Selector.class "me"
]
]


Expand All @@ -56,7 +68,7 @@ textSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.has [ text str ]
|> Query.has [ Selector.text str ]
, fuzz3 (list string) (list string) (list string) "Finds multiple results" <|
\before strings after ->
let
Expand All @@ -67,7 +79,7 @@ textSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.has (List.map text strings)
|> Query.has (List.map Selector.text strings)
, fuzz3 (list string) string (list string) "Finds a submatch" <|
\before str after ->
let
Expand All @@ -78,7 +90,7 @@ textSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.has [ text str ]
|> Query.has [ Selector.text str ]
]


Expand All @@ -100,7 +112,7 @@ exactTextSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.has [ exactText str ]
|> Query.has [ Selector.exactText str ]
, fuzz3 (list string) (list string) (list string) "Finds multiple results" <|
\before strings after ->
let
Expand All @@ -111,7 +123,7 @@ exactTextSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.has (List.map exactText strings)
|> Query.has (List.map Selector.exactText strings)
, fuzz3 (list nonemptyString) nonemptyString (list nonemptyString) "Doesn't find a submatch" <|
\before str after ->
let
Expand All @@ -136,12 +148,82 @@ exactTextSelectors =
in
Html.div [] textNodes
|> Query.fromHtml
|> Query.hasNot [ exactText str2 ]
|> Query.hasNot [ Selector.exactText str2 ]
, test "Trimming is not happening" <|
\() ->
Html.div [] [ Html.text """
We like whitespace
""" ]
|> Query.fromHtml
|> Query.hasNot [ exactText "We like whitespace" ]
|> Query.hasNot [ Selector.exactText "We like whitespace" ]
]


selectorAll : Test
selectorAll =
describe "Selector.all"
[ test "passes if empty" <|
\() ->
Html.fieldset [ Attr.disabled False ]
[ Html.button [ Attr.disabled True ]
[ Html.text "Reply"
]
]
|> Query.fromHtml
|> Query.has [ Selector.all [] ]
, test "passes if single selector matches" <|
\() ->
Html.fieldset [ Attr.disabled False ]
[ Html.button [ Attr.disabled True ]
[ Html.text "Reply"
]
]
|> Query.fromHtml
|> Query.has
[ Selector.all
[ Selector.tag "fieldset"
]
]
, test "passes if all selectors match" <|
\() ->
Html.fieldset [ Attr.disabled False ]
[ Html.button [ Attr.disabled True ]
[ Html.text "Reply"
]
]
|> Query.fromHtml
|> Query.has
[ Selector.all
[ Selector.tag "fieldset"
, Selector.attribute (Attr.disabled False)
]
]
, test "fails if some but not all selectors match (regression for #213)" <|
\() ->
Html.fieldset [ Attr.disabled False ]
[ Html.button [ Attr.disabled True ]
[ Html.text "Reply"
]
]
|> Query.fromHtml
|> Query.hasNot
[ Selector.all
[ Selector.tag "fieldset"
, Selector.attribute (Attr.disabled True)
]
]
, test "fails if no selectors match" <|
\() ->
Html.fieldset [ Attr.disabled False ]
[ Html.button [ Attr.disabled True ]
[ Html.text "Reply"
]
]
|> Query.fromHtml
|> Query.hasNot
[ Selector.all
[ Selector.tag "strong"
, Selector.attribute (Attr.disabled True)
]
]
]