{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} module Main (main) where import BasePrelude -- Lenses import Lens.Micro.Platform -- Text import qualified Data.Text.All as T import Data.Text.All (Text) -- HTML import Text.HTML.TagSoup hiding (sections) import Lucid (ToHtml, toHtml, renderText) -- Markdown import CMark hiding (Node) import qualified CMark as MD (Node(..)) import CMark.Sections import Data.Tree -- Testing import Test.Hspec -- Local import Markdown -- Tests import qualified WebSpec main :: IO () main = do hspec $ do markdownTests WebSpec.tests {- TODO * noscript tests * test on mobile * test that there are no repetitive searches on the admin page * test that admin CSS hasn't creeped into main CSS and vice-versa * test that the server is throwing no errors whatsoever during the execution of tests * changes to item description must not persist when doing Cancel and then Edit again * test that pages are indeed cached * test that changing some pages doesn't invalidate the entire cache * Markdown tests (e.g. Markdown doesn't work in category names) * test that nothing is messed up by things starting and ending with newlines (the %js bug, see description of 'mustache') -} markdownTests :: Spec markdownTests = describe "Markdown" $ do allMarkdowns $ \convert -> do it "has mdText filled accurately" $ do for_ mdBlockExamples $ \s -> s `shouldBe` fst (convert s) it "only has allowed tags" $ do for_ mdBlockExamples $ \s -> do let html = snd (convert s) let badTags = getTags html \\ (inlineTags ++ blockTags) unless (null badTags) $ expectationFailure $ printf "%s got rendered as %s, but some tags (%s) are disallowed" (show s) (show html) (T.intercalate "," badTags) it "doesn't pass bad HTML through" $ do let s = "" let html = snd (convert s) when ("script" `elem` getTags html) $ expectationFailure $ printf "%s got rendered as %s, but the