Skip to content

Commit

Permalink
Try to add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Dec 23, 2023
1 parent 935c32e commit abe950a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Test/View/FormSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tests = do
{submitButton}
|]
form `shouldRenderTo` "<form method=\"POST\" action=\"/CreateProject\" id=\"\" class=\"new-form\" data-disable-javascript-submission=\"false\"><div class=\"mb-3\" id=\"form-group-project_title\"><label class=\"form-label\" for=\"project_title\">Title</label><input type=\"text\" name=\"title\" placeholder=\"\" id=\"project_title\" class=\"form-control\"> </div> <button class=\"btn btn-primary\" type=\"submit\">Create Project</button></form>"

it "should render a form with a GET method" do
context <- createControllerContext
let ?context = context
Expand All @@ -42,6 +42,19 @@ tests = do
|]
form `shouldRenderTo` "<form method=\"GET\" action=\"/CreateProject\" id=\"\" class=\"new-form\" data-disable-javascript-submission=\"false\"><div class=\"mb-3\" id=\"form-group-project_title\"><label class=\"form-label\" for=\"project_title\">Title</label><input type=\"text\" name=\"title\" placeholder=\"\" id=\"project_title\" class=\"form-control\"> </div> <button class=\"btn btn-primary\" type=\"submit\">Create Project</button></form>"

it "should render a form with disabled button" do
context <- createControllerContext
let ?context = context

let options formContext = formContext |> set #formMethod "GET"

let form = formForWithOptions project options [hsx|
{textField #title}
{submitButton {disabled = True}}
|]
form `shouldRenderTo` "<form method=\"GET\" action=\"/CreateProject\" id=\"\" class=\"new-form\" data-disable-javascript-submission=\"false\"><div class=\"mb-3\" id=\"form-group-project_title\"><label class=\"form-label\" for=\"project_title\">Title</label><input type=\"text\" name=\"title\" placeholder=\"\" id=\"project_title\" class=\"form-control\"> </div> <button class=\"btn btn-primary\" disabled=\"disabled\" type=\"submit\">Create Project</button></form>"


shouldRenderTo renderFunction expectedHtml = Blaze.renderMarkup renderFunction `shouldBe` expectedHtml

createControllerContext :: IO ControllerContext
Expand All @@ -54,7 +67,7 @@ createControllerContext = do

data Project' = Project {id :: (Id' "projects"), title :: Text, meta :: MetaBag} deriving (Eq, Show)
instance InputValue Project where inputValue = IHP.ModelSupport.recordToInputValue
type Project = Project'
type Project = Project'

type instance GetTableName (Project' ) = "projects"
type instance GetModelByTableName "projects" = Project
Expand Down

0 comments on commit abe950a

Please sign in to comment.