2019-04-11 00:15:52 +03:00
|
|
|
module Generator.GeneratorsTest where
|
|
|
|
|
|
|
|
import Test.Tasty.Hspec
|
|
|
|
|
2020-01-21 16:55:49 +03:00
|
|
|
import System.FilePath ((</>), (<.>))
|
2020-01-20 13:51:13 +03:00
|
|
|
import Path (absdir)
|
2020-01-21 16:55:49 +03:00
|
|
|
import qualified Path
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2019-05-20 20:30:35 +03:00
|
|
|
import Util
|
2019-12-17 23:40:05 +03:00
|
|
|
import qualified CompileOptions
|
2019-04-11 00:15:52 +03:00
|
|
|
import Generator.Generators
|
|
|
|
import Generator.FileDraft
|
2020-01-21 16:55:49 +03:00
|
|
|
import qualified Generator.FileDraft.TemplateFileDraft as TmplFD
|
|
|
|
import qualified Generator.FileDraft.CopyFileDraft as CopyFD
|
|
|
|
import qualified Generator.FileDraft.TextFileDraft as TextFD
|
2020-01-14 01:25:36 +03:00
|
|
|
import qualified Generator.Common as Common
|
2019-04-11 00:15:52 +03:00
|
|
|
import Wasp
|
|
|
|
|
2019-04-22 13:58:31 +03:00
|
|
|
-- TODO(martin): We could define Arbitrary instance for Wasp, define properties over
|
|
|
|
-- generator functions and then do property testing on them, that would be cool.
|
2019-04-11 00:15:52 +03:00
|
|
|
|
|
|
|
spec_Generators :: Spec
|
|
|
|
spec_Generators = do
|
2019-04-22 13:58:31 +03:00
|
|
|
let testApp = (App "TestApp" "Test App")
|
2019-07-02 21:47:16 +03:00
|
|
|
let testPage = (Page "TestPage" "/test-page" "<div>Test Page</div>" Nothing)
|
2019-05-20 20:30:35 +03:00
|
|
|
let testEntity = (Entity "TestEntity" [EntityField "testField" EftString])
|
|
|
|
let testWasp = (fromApp testApp) `addPage` testPage `addEntity` testEntity
|
2019-12-17 23:40:05 +03:00
|
|
|
let testCompileOptions = CompileOptions.CompileOptions
|
2020-01-20 13:51:13 +03:00
|
|
|
{ CompileOptions.externalCodeDirPath = [absdir|/test/src|]
|
2019-12-17 23:40:05 +03:00
|
|
|
}
|
2019-04-22 13:58:31 +03:00
|
|
|
|
2019-04-11 00:15:52 +03:00
|
|
|
describe "generateWebApp" $ do
|
|
|
|
-- NOTE: This test does not (for now) check that content of files is correct or
|
|
|
|
-- that they will successfully be written, it checks only that their
|
|
|
|
-- destinations are correct.
|
2019-04-22 13:58:31 +03:00
|
|
|
it "Given a simple Wasp, creates file drafts at expected destinations" $ do
|
2019-12-17 23:40:05 +03:00
|
|
|
let fileDrafts = generateWebApp testWasp testCompileOptions
|
2019-05-20 20:30:35 +03:00
|
|
|
let testEntityDstDirInSrc
|
|
|
|
= "entities" </> (Util.camelToKebabCase (entityName testEntity))
|
2019-04-22 13:58:31 +03:00
|
|
|
let expectedFileDraftDstPaths = concat $
|
2019-04-11 00:15:52 +03:00
|
|
|
[ [ "README.md"
|
|
|
|
, "package.json"
|
|
|
|
, ".gitignore"
|
|
|
|
]
|
|
|
|
, map ("public" </>)
|
|
|
|
[ "favicon.ico"
|
|
|
|
, "index.html"
|
|
|
|
, "manifest.json"
|
|
|
|
]
|
2020-01-21 16:55:49 +03:00
|
|
|
, map ((Path.toFilePath Common.srcDirPath) </>)
|
2019-04-11 00:15:52 +03:00
|
|
|
[ "logo.png"
|
|
|
|
, "index.css"
|
|
|
|
, "index.js"
|
2019-05-12 14:45:08 +03:00
|
|
|
, "reducers.js"
|
2019-04-22 13:58:31 +03:00
|
|
|
, "router.js"
|
2019-04-11 00:15:52 +03:00
|
|
|
, "serviceWorker.js"
|
2019-04-22 13:58:31 +03:00
|
|
|
, (pageName testPage <.> "js")
|
2019-05-12 14:45:08 +03:00
|
|
|
, "store/index.js"
|
|
|
|
, "store/middleware/logger.js"
|
2019-05-20 20:30:35 +03:00
|
|
|
, testEntityDstDirInSrc </> "actions.js"
|
|
|
|
, testEntityDstDirInSrc </> "actionTypes.js"
|
|
|
|
, testEntityDstDirInSrc </> "state.js"
|
2019-04-11 00:15:52 +03:00
|
|
|
]
|
|
|
|
]
|
2019-12-17 23:40:05 +03:00
|
|
|
|
2019-04-11 00:15:52 +03:00
|
|
|
mapM_
|
|
|
|
-- NOTE(martin): I added fd to the pair here in order to have it
|
|
|
|
-- printed when shouldBe fails, otherwise I could not know which
|
|
|
|
-- file draft failed.
|
2019-04-22 13:58:31 +03:00
|
|
|
(\dstPath -> (dstPath, existsFdWithDst fileDrafts dstPath)
|
|
|
|
`shouldBe` (dstPath, True))
|
|
|
|
expectedFileDraftDstPaths
|
2019-04-11 00:15:52 +03:00
|
|
|
|
|
|
|
|
2019-04-22 13:58:31 +03:00
|
|
|
existsFdWithDst :: [FileDraft] -> FilePath -> Bool
|
|
|
|
existsFdWithDst fds dstPath = any ((== dstPath) . getFileDraftDstPath) fds
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2020-01-15 15:08:13 +03:00
|
|
|
-- TODO(martin): This should really become part of the Writeable typeclass,
|
2019-07-02 21:47:16 +03:00
|
|
|
-- since it is smth we want to do for all file drafts.
|
2019-04-11 00:15:52 +03:00
|
|
|
getFileDraftDstPath :: FileDraft -> FilePath
|
2020-01-21 16:55:49 +03:00
|
|
|
getFileDraftDstPath (FileDraftTemplateFd fd) = Path.toFilePath $ TmplFD._dstPath fd
|
|
|
|
getFileDraftDstPath (FileDraftCopyFd fd) = Path.toFilePath $ CopyFD._dstPath fd
|
|
|
|
getFileDraftDstPath (FileDraftTextFd fd) = Path.toFilePath $ TextFD._dstPath fd
|