From 06b199e3ffd2f1d1d9b2c452da0cb7f25bac6379 Mon Sep 17 00:00:00 2001 From: Artyom Date: Fri, 26 Aug 2016 20:27:11 +0300 Subject: [PATCH] [tests] Add helpers + test category emptiness --- tests/WebSpec.hs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/WebSpec.hs b/tests/WebSpec.hs index 7d132e5..5533b3c 100644 --- a/tests/WebSpec.hs +++ b/tests/WebSpec.hs @@ -107,8 +107,9 @@ categoryTests = session "categories" $ using Firefox $ do changesURL $ click e do u <- getCurrentURL u `shouldBe` catURL - -- TODO: test that the feed button is present and that the feed is - -- generated properly + wd "is initially empty" $ do + checkPresent ".items" + checkNotPresent (".items" :// Not ".dummy") describe "category properties" $ do describe "title" $ do wd "is present" $ do @@ -160,6 +161,14 @@ categoryTests = session "categories" $ using Firefox $ do catLink <- select (ByLinkText "Cat 2") groupHeader <- select ((".category-group" : a -> b -> ComplexSelector -- | Or (:|) :: (CanSelect a, CanSelect b) => a -> b -> ComplexSelector + -- | Not + Not :: CanSelect a => a -> ComplexSelector -- | Elements with specific text WithText :: Text -> ComplexSelector -- | Elements that contain specific text @@ -293,14 +301,19 @@ instance CanSelect ComplexSelector where bs <- Set.fromList <$> selectAll b return (Set.toList (as `Set.union` bs)) Take n a -> take n <$> selectAll a + -- + Not a -> defSelectAll (Not a) WithText t -> defSelectAll (WithText t) ContainsText t -> defSelectAll (ContainsText t) filterElems s es = case s of + Not a -> (es \\) <$> filterElems a es WithText t -> filterM (fmap (== t) . getText) es ContainsText t -> filterM (fmap (t `T.isInfixOf`) . getText) es _ -> defFilterElems s es anyElem s es = case s of - WithText t -> anyM (fmap (== t) . getText) es + Not a -> (== length es) . length <$> filterElems a es + WithText t -> anyM (fmap (== t) . getText) es + ContainsText t -> anyM (fmap (t `T.isInfixOf`) . getText) es _ -> defAnyElem s es class ToSelector a where @@ -426,6 +439,13 @@ run ts = do bracket prepare finalise $ \_ -> do hspec ts +_site :: IO () +_site = run $ do + session "_" $ using Firefox $ do + wd "_" $ do + openGuidePage "/" + _pause + expectationFailure :: MonadIO m => String -> m a expectationFailure s = do liftIO (Hspec.expectationFailure s)