Hello community, here is the log from the commit of package ghc-yesod-test for openSUSE:Factory checked in at 2017-07-06 00:03:52 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-yesod-test (Old) and /work/SRC/openSUSE:Factory/.ghc-yesod-test.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-yesod-test" Thu Jul 6 00:03:52 2017 rev:4 rq:508046 version:1.5.7 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-yesod-test/ghc-yesod-test.changes 2017-06-21 13:56:55.165674047 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-yesod-test.new/ghc-yesod-test.changes 2017-07-06 00:03:53.474142697 +0200 @@ -1,0 +2,5 @@ +Sun Jun 25 18:41:39 UTC 2017 - [email protected] + +- Update to version 1.5.7. + +------------------------------------------------------------------- Old: ---- yesod-test-1.5.6.tar.gz New: ---- yesod-test-1.5.7.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-yesod-test.spec ++++++ --- /var/tmp/diff_new_pack.o5vATW/_old 2017-07-06 00:03:54.885943805 +0200 +++ /var/tmp/diff_new_pack.o5vATW/_new 2017-07-06 00:03:54.889943242 +0200 @@ -19,7 +19,7 @@ %global pkg_name yesod-test %bcond_with tests Name: ghc-%{pkg_name} -Version: 1.5.6 +Version: 1.5.7 Release: 0 Summary: Integration testing for WAI/Yesod Applications License: MIT ++++++ yesod-test-1.5.6.tar.gz -> yesod-test-1.5.7.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yesod-test-1.5.6/ChangeLog.md new/yesod-test-1.5.7/ChangeLog.md --- old/yesod-test-1.5.6/ChangeLog.md 2017-04-12 09:57:39.000000000 +0200 +++ new/yesod-test-1.5.7/ChangeLog.md 2017-06-22 18:16:04.000000000 +0200 @@ -1,3 +1,8 @@ +## 1.5.7 + +* Add clickOn. +[#1408](https://github.com/yesodweb/yesod/pull/1408) + ## 1.5.6 * Add assertNotEq. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yesod-test-1.5.6/Yesod/Test/TransversingCSS.hs new/yesod-test-1.5.7/Yesod/Test/TransversingCSS.hs --- old/yesod-test-1.5.6/Yesod/Test/TransversingCSS.hs 2017-02-05 13:38:01.000000000 +0100 +++ new/yesod-test-1.5.7/Yesod/Test/TransversingCSS.hs 2017-06-22 18:16:04.000000000 +0200 @@ -10,16 +10,16 @@ Only a subset of the CSS spec is currently supported: * By tag name: /table td a/ - + * By class names: /.container .content/ * By Id: /#oneId/ * By attribute: /[hasIt]/, /[exact=match]/, /[contains*=text]/, /[starts^=with]/, /[ends$=with]/ - + * Union: /a, span, p/ - - * Immediate children: /div > p/ + + * Immediate children: /div > p/ * Get jiggy with it: /div[data-attr=yeah] > .mon, .foo.bar div, #oneThing/ @@ -27,6 +27,7 @@ module Yesod.Test.TransversingCSS ( findBySelector, + findAttributeBySelector, HtmlLBS, Query, -- * For HXT hackers @@ -41,7 +42,7 @@ import Yesod.Test.CssQuery import qualified Data.Text as T -import Control.Applicative ((<$>), (<*>)) +import qualified Control.Applicative import Text.XML import Text.XML.Cursor import qualified Data.ByteString.Lazy as L @@ -58,9 +59,30 @@ -- -- * Right: List of matching Html fragments. findBySelector :: HtmlLBS -> Query -> Either String [String] -findBySelector html query = (\x -> map (renderHtml . toHtml . node) . runQuery x) - Control.Applicative.<$> (Right $ fromDocument $ HD.parseLBS html) - Control.Applicative.<*> parseQuery query +findBySelector html query = + map (renderHtml . toHtml . node) Control.Applicative.<$> findCursorsBySelector html query + +-- | Perform a css 'Query' on 'Html'. Returns Either +-- +-- * Left: Query parse error. +-- +-- * Right: List of matching Cursors +findCursorsBySelector :: HtmlLBS -> Query -> Either String [Cursor] +findCursorsBySelector html query = + runQuery (fromDocument $ HD.parseLBS html) + Control.Applicative.<$> parseQuery query + +-- | Perform a css 'Query' on 'Html'. Returns Either +-- +-- * Left: Query parse error. +-- +-- * Right: List of matching Cursors +-- +-- @since 1.5.7 +findAttributeBySelector :: HtmlLBS -> Query -> T.Text -> Either String [[T.Text]] +findAttributeBySelector html query attr = + map (laxAttribute attr) Control.Applicative.<$> findCursorsBySelector html query + -- Run a compiled query on Html, returning a list of matching Html fragments. runQuery :: Cursor -> [[SelectorGroup]] -> [Cursor] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yesod-test-1.5.6/Yesod/Test.hs new/yesod-test-1.5.7/Yesod/Test.hs --- old/yesod-test-1.5.6/Yesod/Test.hs 2017-04-12 09:57:39.000000000 +0200 +++ new/yesod-test-1.5.7/Yesod/Test.hs 2017-06-22 18:16:04.000000000 +0200 @@ -62,6 +62,7 @@ , setRequestBody , RequestBuilder , setUrl + , clickOn -- *** Adding fields by label -- | Yesod can auto generate field names, so you are never sure what @@ -830,6 +831,25 @@ , rbdGets = rbdGets rbd ++ H.parseQuery (TE.encodeUtf8 urlQuery) } + +-- | Click on a link defined by a CSS query +-- +-- ==== __ Examples__ +-- +-- > get "/foobar" +-- > clickOn "a#idofthelink" +-- +-- @since 1.5.7 +clickOn :: Yesod site => Query -> YesodExample site () +clickOn query = do + withResponse' yedResponse ["Tried to invoke clickOn in order to read HTML of a previous response."] $ \ res -> + case findAttributeBySelector (simpleBody res) query "href" of + Left err -> failure $ query <> " did not parse: " <> T.pack (show err) + Right [[match]] -> get match + Right matches -> failure $ "Expected exactly one match for clickOn: got " <> T.pack (show matches) + + + -- | Simple way to set HTTP request body -- -- ==== __ Examples__ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yesod-test-1.5.6/test/main.hs new/yesod-test-1.5.7/test/main.hs --- old/yesod-test-1.5.6/test/main.hs 2017-02-05 13:38:01.000000000 +0100 +++ new/yesod-test-1.5.7/test/main.hs 2017-06-22 18:16:04.000000000 +0200 @@ -34,6 +34,7 @@ import qualified Data.Map as Map import qualified Text.HTML.DOM as HD import Network.HTTP.Types.Status (status301, status303, unsupportedMediaType415) +import Control.Exception.Lifted(SomeException, try) parseQuery_ :: Text -> [[SelectorGroup]] parseQuery_ = either error id . parseQuery @@ -169,6 +170,16 @@ addToken_ "body" statusIs 200 bodyEquals "12345" + yit "can follow a link via clickOn" $ do + get ("/htmlWithLink" :: Text) + clickOn "a#thelink" + statusIs 200 + bodyEquals "<html><head><title>Hello</title></head><body><p>Hello World</p><p>Hello Moon</p></body></html>" + + get ("/htmlWithLink" :: Text) + (bad :: Either SomeException ()) <- try (clickOn "a#nonexistentlink") + assertEq "bad link" (isLeft bad) True + ydescribe "utf8 paths" $ do yit "from path" $ do @@ -326,6 +337,8 @@ onStatic "html" $ dispatchTo $ return ("<html><head><title>Hello</title></head><body><p>Hello World</p><p>Hello Moon</p></body></html>" :: Text) + onStatic "htmlWithLink" $ dispatchTo $ + return ("<html><head><title>A link</title></head><body><a href=\"/html\" id=\"thelink\">Link!</a></body></html>" :: Text) onStatic "labels" $ dispatchTo $ return ("<html><label><input type='checkbox' name='fooname' id='foobar'>Foo Bar</label></html>" :: Text) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yesod-test-1.5.6/yesod-test.cabal new/yesod-test-1.5.7/yesod-test.cabal --- old/yesod-test-1.5.6/yesod-test.cabal 2017-04-12 09:57:39.000000000 +0200 +++ new/yesod-test-1.5.7/yesod-test.cabal 2017-06-22 18:16:04.000000000 +0200 @@ -1,5 +1,5 @@ name: yesod-test -version: 1.5.6 +version: 1.5.7 license: MIT license-file: LICENSE author: Nubis <[email protected]>
