wasp/waspc/test/Parser/PageTest.hs
2020-02-20 12:30:58 +01:00

34 lines
1.2 KiB
Haskell

module Parser.PageTest where
import Test.Tasty.Hspec
import Data.Either (isLeft)
import Parser.Common (runWaspParser)
import Parser.Page (page)
import qualified Wasp
spec_parsePage :: Spec
spec_parsePage =
describe "Parsing page wasp" $ do
let parsePage input = runWaspParser page input
it "When given valid page wasp declaration, returns correct Wasp.Page" $ do
let testPageName = "Landing"
let testPageRoute = "/someRoute"
let testPageContent = "<span/>"
parsePage (
"page " ++ testPageName ++ " { " ++
"route: \"" ++ testPageRoute ++ "\"," ++
"content: {=jsx " ++ testPageContent ++ " jsx=}" ++
"}")
`shouldBe` Right (Wasp.Page
{ Wasp.pageName = testPageName
, Wasp.pageRoute = testPageRoute
, Wasp.pageContent = testPageContent
, Wasp.pageStyle = Nothing
})
it "When given page wasp declaration without 'page', should return Left" $ do
isLeft (parsePage "Landing { route: someRoute }") `shouldBe` True