2020-12-13 20:09:23 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module XML.Card.Component (
|
|
|
|
test
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Blog (Blog)
|
2021-03-28 23:38:53 +02:00
|
|
|
import Blog.URL (pathRelative)
|
2020-12-13 20:09:23 +01:00
|
|
|
import Control.Monad.IO.Class (MonadIO(..))
|
|
|
|
import Control.Monad.Reader (runReaderT)
|
|
|
|
import Data.Text (Text)
|
|
|
|
import Distribution.TestSuite
|
|
|
|
import DOM.Card (HasCard(..))
|
|
|
|
import Mock.Blog as Blog (simple)
|
|
|
|
import Mock.Article as Article (noDescription, noImage, simple)
|
|
|
|
import Mock.ArticlesList as ArticlesList (
|
|
|
|
longMain, longTesting, shortMain, shortTesting
|
|
|
|
)
|
2021-03-28 23:38:53 +02:00
|
|
|
import Network.URL (URL)
|
2020-12-13 20:09:23 +01:00
|
|
|
import Utils (assertAll, assertEqual, simpleTest, tag)
|
|
|
|
|
2021-03-28 23:38:53 +02:00
|
|
|
check :: HasCard a => IO Blog -> a -> (Text, Text, Maybe URL, String, String) -> IO Progress
|
2020-12-13 20:09:23 +01:00
|
|
|
check getBlog input (expectedCT, expectedD, expectedI, expectedT, expectedU) =
|
|
|
|
getBlog >>= runReaderT (
|
|
|
|
sequence [
|
|
|
|
assertEqual "card types" expectedCT <$> cardType input
|
|
|
|
, assertEqual "descriptions" expectedD <$> description input
|
|
|
|
, assertEqual "images" expectedI <$> image input
|
|
|
|
, assertEqual "titles" expectedT <$> title input
|
|
|
|
, assertEqual "urls" expectedU <$> urlPath input
|
|
|
|
] >>= liftIO . assertAll
|
|
|
|
)
|
|
|
|
|
|
|
|
articleCard :: Test
|
|
|
|
articleCard = tag "article" . testGroup "Article cards" $ simpleTest <$> [
|
|
|
|
("simple article components", check Blog.simple Article.simple (
|
|
|
|
"article"
|
|
|
|
, "It's a test"
|
2021-03-28 23:38:53 +02:00
|
|
|
, Just (pathRelative "test.png")
|
2020-12-13 20:09:23 +01:00
|
|
|
, "Some test"
|
|
|
|
, "articles/test.html"
|
|
|
|
))
|
|
|
|
, ("article components without description", check Blog.simple Article.noDescription (
|
|
|
|
"article"
|
|
|
|
, "A new article on The Test Blog"
|
2021-03-28 23:38:53 +02:00
|
|
|
, Just (pathRelative "test.png")
|
2020-12-13 20:09:23 +01:00
|
|
|
, "Some test"
|
|
|
|
, "articles/test.html"
|
|
|
|
))
|
|
|
|
, ("article components without image", check Blog.simple Article.noImage (
|
|
|
|
"article"
|
|
|
|
, "It's a test"
|
|
|
|
, Nothing
|
|
|
|
, "Some test"
|
|
|
|
, "articles/test.html"
|
|
|
|
))
|
|
|
|
]
|
|
|
|
|
|
|
|
articlesListCard :: Test
|
|
|
|
articlesListCard = tag "articlesList" . testGroup "Articles list cards" $ simpleTest <$> [
|
|
|
|
("short untagged page component", ArticlesList.shortMain >>= (flip (check Blog.simple) (
|
|
|
|
"website"
|
|
|
|
, "Latest articles"
|
|
|
|
, Nothing
|
|
|
|
, "The Test Blog"
|
|
|
|
, "index.html"
|
|
|
|
)))
|
|
|
|
, ("long untagged page component", ArticlesList.longMain >>= (flip (check Blog.simple) (
|
|
|
|
"website"
|
|
|
|
, "All articles"
|
|
|
|
, Nothing
|
|
|
|
, "The Test Blog"
|
|
|
|
, "all.html"
|
|
|
|
)))
|
|
|
|
, ("short tagged page component", ArticlesList.shortTesting >>= (flip (check Blog.simple) (
|
|
|
|
"website"
|
|
|
|
, "Latest articles tagged testing"
|
|
|
|
, Nothing
|
|
|
|
, "The Test Blog - testing"
|
|
|
|
, "testing/index.html"
|
|
|
|
)))
|
|
|
|
, ("long tagged page component", ArticlesList.longTesting >>= (flip (check Blog.simple) (
|
|
|
|
"website"
|
|
|
|
, "All articles tagged testing"
|
|
|
|
, Nothing
|
|
|
|
, "The Test Blog - testing"
|
|
|
|
, "testing/all.html"
|
|
|
|
)))
|
|
|
|
]
|
|
|
|
|
|
|
|
test :: Test
|
|
|
|
test = tag "component" $ testGroup "Cards components" [articleCard, articlesListCard]
|