Skip to content

Commit

Permalink
Move test and apply to Bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Dec 23, 2023
1 parent f6f170b commit 7563b72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions IHP/View/CSSFramework.hs
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ bootstrap4 = def
[hsx|<div class={className}>{message}</div>|]
styledValidationResult _ _ = mempty

styledSubmitButton cssFramework SubmitButton { label, buttonClass } =
styledSubmitButton cssFramework SubmitButton { label, buttonClass, buttonDisabled } =
let className :: Text = cssFramework.styledSubmitButtonClass
in [hsx|<button class={classes [(className, True), (buttonClass, not (null buttonClass))]} type="submit">{label}</button>|]
in [hsx|<button class={classes [(className, True), (buttonClass, not (null buttonClass))]} disabled={buttonDisabled} type="submit">{label}</button>|]

styledPagination :: CSSFramework -> PaginationView -> Blaze.Html
styledPagination _ paginationView =
Expand Down
9 changes: 7 additions & 2 deletions Test/View/CSSFrameworkSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ tests = do
styledFlashMessage cssFramework cssFramework flashMessage `shouldRenderTo` "<div class=\"alert alert-danger\">You have successfully registered for an account</div>"

describe "submit button" do
let submitButton = SubmitButton { label = "Save Project" , buttonClass = "my-custom-button" , cssFramework }
let submitButton = SubmitButton { label = "Save Project" , buttonClass = "my-custom-button" , cssFramework, buttonDisabled = False }
it "should render" do
styledSubmitButton cssFramework cssFramework submitButton `shouldRenderTo` "<button class=\"btn btn-primary my-custom-button\" type=\"submit\">Save Project</button>"

it "should render with empty class" do
styledSubmitButton cssFramework cssFramework (submitButton { buttonClass = "" }) `shouldRenderTo` "<button class=\"btn btn-primary\" type=\"submit\">Save Project</button>"

it "should render with disabled button" do
styledSubmitButton cssFramework cssFramework (submitButton { buttonDisabled = True }) `shouldRenderTo` "<button class=\"btn btn-primary\" disabled=\"disabled\" type=\"submit\">Save Project</button>"

describe "text field" do
let baseTextField = FormField
Expand Down Expand Up @@ -396,13 +398,16 @@ tests = do
styledFlashMessage cssFramework cssFramework flashMessage `shouldRenderTo` "<div class=\"alert alert-danger\">You have successfully registered for an account</div>"

describe "submit button" do
let submitButton = SubmitButton { label = "Save Project" , buttonClass = "my-custom-button" , cssFramework }
let submitButton = SubmitButton { label = "Save Project" , buttonClass = "my-custom-button" , cssFramework, buttonDisabled = False }
it "should render" do
styledSubmitButton cssFramework cssFramework submitButton `shouldRenderTo` "<button class=\"btn btn-primary my-custom-button\" type=\"submit\">Save Project</button>"

it "should render with empty class" do
styledSubmitButton cssFramework cssFramework (submitButton { buttonClass = "" }) `shouldRenderTo` "<button class=\"btn btn-primary\" type=\"submit\">Save Project</button>"

it "should render with disabled button" do
styledSubmitButton cssFramework cssFramework (submitButton { buttonDisabled = True }) `shouldRenderTo` "<button class=\"btn btn-primary\" disabled=\"disabled\" type=\"submit\">Save Project</button>"


describe "text field" do
let baseTextField = FormField
Expand Down
13 changes: 0 additions & 13 deletions Test/View/FormSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ 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 {buttonDisabled = 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 Down

0 comments on commit 7563b72

Please sign in to comment.