From ef25c90e9b7d9d432e43cd2e55533a7092155176 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Tue, 17 Jun 2014 08:22:34 +0300 Subject: [PATCH] Handle labels containing inputs #759 --- yesod-test/Yesod/Test.hs | 11 +++++++---- yesod-test/test/main.hs | 11 +++++++++++ yesod-test/yesod-test.cabal | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index c51f6894..1301797d 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -421,10 +421,10 @@ nameFromLabel label = do Just res -> return res let body = simpleBody res - mfor = parseHTML body + mlabel = parseHTML body $// C.element "label" >=> contentContains label - >=> attribute "for" + mfor = mlabel >>= attribute "for" contentContains x c | x `T.isInfixOf` T.concat (c $// content) = [c] @@ -444,8 +444,11 @@ nameFromLabel label = do , " which was not found. " ] name:_ -> return name - _ -> failure $ "More than one input with id " <> for - [] -> failure $ "No label contained: " <> label + [] -> failure $ "No input with id " <> for + [] -> + case filter (/= "") $ mlabel >>= (child >=> C.element "input" >=> attribute "name") of + [] -> failure $ "No label contained: " <> label + name:_ -> return name _ -> failure $ "More than one label contained " <> label (<>) :: T.Text -> T.Text -> T.Text diff --git a/yesod-test/test/main.hs b/yesod-test/test/main.hs index 5e509c09..f53583dc 100644 --- a/yesod-test/test/main.hs +++ b/yesod-test/test/main.hs @@ -132,6 +132,14 @@ main = hspec $ do get ("/dynamic2/שלום" :: Text) statusIs 200 bodyEquals "שלום" + + ydescribe "labels" $ do + yit "can click checkbox" $ do + get ("/labels" :: Text) + request $ do + setMethod "POST" + setUrl ("/labels" :: Text) + byLabel "Foo Bar" "yes" describe "cookies" $ yesodSpec cookieApp $ do yit "should send the cookie #730" $ do get ("/" :: Text) @@ -174,6 +182,9 @@ app = liteApp $ do onStatic "html" $ dispatchTo $ return ("Hello

Hello World

Hello Moon

" :: Text) + onStatic "labels" $ dispatchTo $ + return ("" :: Text) + cookieApp :: LiteApp cookieApp = liteApp $ do diff --git a/yesod-test/yesod-test.cabal b/yesod-test/yesod-test.cabal index acf1426e..db8d469c 100644 --- a/yesod-test/yesod-test.cabal +++ b/yesod-test/yesod-test.cabal @@ -1,5 +1,5 @@ name: yesod-test -version: 1.2.3 +version: 1.2.3.1 license: MIT license-file: LICENSE author: Nubis