purescript-puppeteer/test/Puppeteer.Selector.Spec.purs

54 lines
1.5 KiB
Haskell
Raw Permalink Normal View History

2023-09-29 22:32:24 +00:00
module Puppeteer.Selector.Spec where
import Prelude
import Data.Foldable (fold)
import Data.Identity (Identity)
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
import Puppeteer.Selector as S
import Test.Spec (SpecT, describe)
import Test.Spec.Assertions (shouldEqual)
import Test.Util (test)
import Web.HTML (HTMLButtonElement)
spec :: SpecT Aff Unit Identity Unit
spec = describe "Selector" do
test "toCSS" do
let isButton = identity :: forall s. S.Selector s HTMLButtonElement => s -> s
let
s = S.toCSS
$ isButton
2023-09-30 03:33:55 +00:00
$
S.button
2023-09-29 22:32:24 +00:00
`S.hasId` "foo"
`S.hasClass` "bar"
`S.hasAttr` "disabled"
`S.hasAttrContaining` ("ident" /\ "abc")
`S.hasAttrListContaining` ("feet" /\ "left_foot")
`S.hasAttrStartsWith` ("name" /\ "frank")
`S.hasAttrEndsWith` ("name" /\ "johnson")
`S.isDescendantOf` S.body
`S.isChildOf` S.html
2023-09-30 03:33:55 +00:00
`S.not` (S.enabled S.none)
`S.has` (S.div `S.isChildOf` S.none)
# S.focus
# S.disabled
# S.active
2023-09-29 22:32:24 +00:00
let
expected = fold
[ "html > body button"
, "#foo.bar"
2023-09-30 03:33:55 +00:00
, """[disabled]"""
, """[ident *= "abc"]"""
, """[feet ~= "left_foot"]"""
, """[name ^= "frank"]"""
, """[name $= "johnson"]"""
, ":not(:enabled)"
, ":has( > div)"
, ":focus"
, ":disabled"
, ":active"
2023-09-29 22:32:24 +00:00
]
s `shouldEqual` expected