diff --git a/Test/IDE/CodeGeneration/ViewGenerator.hs b/Test/IDE/CodeGeneration/ViewGenerator.hs index c229172f9..4c96bbdfd 100644 --- a/Test/IDE/CodeGeneration/ViewGenerator.hs +++ b/Test/IDE/CodeGeneration/ViewGenerator.hs @@ -35,7 +35,8 @@ tests = do } ] it "should build a view with name \"EditView\"" do - let viewName = "EditView" + let rawViewName = "EditView" + let viewName = tableNameToViewName rawViewName let rawControllerName = "Pages" let controllerName = tableNameToControllerName rawControllerName let modelName = tableNameToModelName rawControllerName @@ -50,8 +51,41 @@ tests = do + it "should build a view with name \"edit_view\"" do + let rawViewName = "edit_view" + let viewName = tableNameToViewName rawViewName + let rawControllerName = "Pages" + let controllerName = tableNameToControllerName rawControllerName + let modelName = tableNameToModelName rawControllerName + let applicationName = "Web" + let paginationEnabled = False + let config = ViewGenerator.ViewConfig { .. } + let builtPlan = ViewGenerator.buildPlan' schema config + + builtPlan `shouldBe` + [ EnsureDirectory {directory = "Web/View/Pages"},CreateFile {filePath = "Web/View/Pages/Edit.hs", fileContent = "module Web.View.Pages.Edit where\nimport Web.View.Prelude\n\ndata EditView = EditView { page :: Page }\n\ninstance View EditView where\n html EditView { .. } = [hsx|\n {breadcrumb}\n

Edit Page

\n {renderForm page}\n |]\n where\n breadcrumb = renderBreadcrumb\n [ breadcrumbLink \"Pages\" PagesAction\n , breadcrumbText \"Edit Page\"\n ]\n\nrenderForm :: Page -> Html\nrenderForm page = formFor page [hsx|\n \n {submitButton}\n\n|]"},AddImport {filePath = "Web/Controller/Pages.hs", fileContent = "import Web.View.Pages.Edit"} + ] + + + it "should build a view with name \"editView\"" do + let rawViewName = "editView" + let viewName = tableNameToViewName rawViewName + let rawControllerName = "Pages" + let controllerName = tableNameToControllerName rawControllerName + let modelName = tableNameToModelName rawControllerName + let applicationName = "Web" + let paginationEnabled = False + let config = ViewGenerator.ViewConfig { .. } + let builtPlan = ViewGenerator.buildPlan' schema config + + builtPlan `shouldBe` + [ EnsureDirectory {directory = "Web/View/Pages"},CreateFile {filePath = "Web/View/Pages/Edit.hs", fileContent = "module Web.View.Pages.Edit where\nimport Web.View.Prelude\n\ndata EditView = EditView { page :: Page }\n\ninstance View EditView where\n html EditView { .. } = [hsx|\n {breadcrumb}\n

Edit Page

\n {renderForm page}\n |]\n where\n breadcrumb = renderBreadcrumb\n [ breadcrumbLink \"Pages\" PagesAction\n , breadcrumbText \"Edit Page\"\n ]\n\nrenderForm :: Page -> Html\nrenderForm page = formFor page [hsx|\n \n {submitButton}\n\n|]"},AddImport {filePath = "Web/Controller/Pages.hs", fileContent = "import Web.View.Pages.Edit"} + ] + + it "should build a view with name \"Edit\"" do - let viewName = "Edit" + let rawViewName = "Edit" + let viewName = tableNameToViewName rawViewName let rawControllerName = "Pages" let controllerName = tableNameToControllerName rawControllerName let modelName = tableNameToModelName rawControllerName @@ -66,7 +100,8 @@ tests = do it "should build a view with name \"Test\"" do - let viewName = "Test" + let rawViewName = "Test" + let viewName = tableNameToViewName rawViewName let rawControllerName = "Pages" let controllerName = tableNameToControllerName rawControllerName let modelName = tableNameToModelName rawControllerName @@ -76,5 +111,5 @@ tests = do let builtPlan = ViewGenerator.buildPlan' schema config builtPlan `shouldBe` - [ EnsureDirectory {directory = "Web/View/Pages"},CreateFile {filePath = "Web/View/Pages/Test.hs", fileContent = "module Web.View.Pages.Test where\nimport Web.View.Prelude\ndata TestView = {TestView}\n\ninstance View TestView where\n html TestView { .. } = [hsx|\n {breadcrumb}\n

TestView

\n |]\n where\n breadcrumb = renderBreadcrumb\n [ breadcrumbLink \"Tests\" PagesAction\n , breadcrumbText \"TestView\"\n ]"},AddImport {filePath = "Web/Controller/Pages.hs", fileContent = "import Web.View.Pages.Test"} + [ EnsureDirectory {directory = "Web/View/Pages"},CreateFile {filePath = "Web/View/Pages/Test.hs", fileContent = "module Web.View.Pages.Test where\nimport Web.View.Prelude\ndata TestView = TestView\n\ninstance View TestView where\n html TestView { .. } = [hsx|\n {breadcrumb}\n

TestView

\n |]\n where\n breadcrumb = renderBreadcrumb\n [ breadcrumbLink \"Tests\" PagesAction\n , breadcrumbText \"TestView\"\n ]"},AddImport {filePath = "Web/Controller/Pages.hs", fileContent = "import Web.View.Pages.Test"} ] \ No newline at end of file diff --git a/ihp-ide/IHP/IDE/CodeGen/ViewGenerator.hs b/ihp-ide/IHP/IDE/CodeGen/ViewGenerator.hs index dd32eb8e1..3cecdae59 100644 --- a/ihp-ide/IHP/IDE/CodeGen/ViewGenerator.hs +++ b/ihp-ide/IHP/IDE/CodeGen/ViewGenerator.hs @@ -81,7 +81,7 @@ buildPlan' schema config = genericView = [trimming| ${viewHeader} - data ${nameWithSuffix} = {${nameWithSuffix}} + data ${nameWithSuffix} = ${nameWithSuffix} instance View ${nameWithSuffix} where html ${nameWithSuffix} { .. } = [hsx|