2019-05-05 18:54:51 +03:00
|
|
|
module Parser.PageTest where
|
|
|
|
|
|
|
|
import Test.Tasty.Hspec
|
|
|
|
|
2019-05-09 23:05:59 +03:00
|
|
|
import Data.Either (isLeft)
|
2019-05-05 18:54:51 +03:00
|
|
|
|
2019-05-09 23:05:59 +03:00
|
|
|
import Parser.Common (runWaspParser)
|
|
|
|
import Parser.Page (page)
|
|
|
|
import qualified Wasp
|
2019-05-05 18:54:51 +03:00
|
|
|
|
|
|
|
spec_parsePage :: Spec
|
|
|
|
spec_parsePage =
|
|
|
|
describe "Parsing page wasp" $ do
|
2019-05-09 23:05:59 +03:00
|
|
|
let parsePage input = runWaspParser page input
|
|
|
|
|
2019-05-05 18:54:51 +03:00
|
|
|
it "When given valid page wasp declaration, returns correct Wasp.Page" $ do
|
|
|
|
let testPageName = "Landing"
|
|
|
|
let testPageRoute = "/someRoute"
|
|
|
|
let testPageContent = "<span/>"
|
|
|
|
parsePage (
|
|
|
|
"page " ++ testPageName ++ " { " ++
|
2020-01-28 21:41:14 +03:00
|
|
|
"route: \"" ++ testPageRoute ++ "\"," ++
|
|
|
|
"content: {=jsx " ++ testPageContent ++ " jsx=}" ++
|
2019-05-05 18:54:51 +03:00
|
|
|
"}")
|
2019-05-09 23:05:59 +03:00
|
|
|
`shouldBe` Right (Wasp.Page
|
|
|
|
{ Wasp.pageName = testPageName
|
|
|
|
, Wasp.pageRoute = testPageRoute
|
|
|
|
, Wasp.pageContent = testPageContent
|
2019-07-02 21:47:16 +03:00
|
|
|
, Wasp.pageStyle = Nothing
|
2019-05-05 18:54:51 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it "When given page wasp declaration without 'page', should return Left" $ do
|
2019-05-24 01:18:37 +03:00
|
|
|
isLeft (parsePage "Landing { route: someRoute }") `shouldBe` True
|