-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup testing and implement two sort-of integration tests. For #6.
- Loading branch information
Showing
5 changed files
with
281 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/target | ||
/classes | ||
/out | ||
/checkouts | ||
pom.xml | ||
pom.xml.asc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
;;;; Copyright © 2015 2016 José Pablo Fernández Silva All rights reserved. | ||
|
||
(ns free-form.core-test | ||
(:require [clojure.test :refer [deftest testing is]] | ||
[clojure.walk :refer [prewalk]] | ||
[free-form.core :as free-form])) | ||
|
||
(defn- hide-on-change [form] | ||
(prewalk (fn [node] (if (contains? node :on-change) | ||
(assoc node :on-change :was-function) | ||
node)) | ||
form)) | ||
|
||
(deftest a-test | ||
(let [plain-reagent-form-template [:form {:noValidate true} | ||
[:div.errors {:free-form/error-message {:key :-general}} [:p.error]] | ||
[:div.field {:free-form/error-class {:key :text :error "validation-errors"}} | ||
[:label {:for :text} "Text"] | ||
[:input.form-control {:free-form/input {:key :text} | ||
:type :text | ||
:id :text | ||
:placeholder "placeholder"}] | ||
[:div.errors {:free-form/error-message {:key :text}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :email :error "validation-errors"}} | ||
[:label {:for :email} "Email"] | ||
[:input.form-control {:free-form/input {:key :email} | ||
:type :email | ||
:id :email | ||
:placeholder "[email protected]"}] | ||
[:div.errors {:free-form/error-message {:key :email}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :password :error "validation-errors"}} | ||
[:label {:for :password} "Password"] | ||
[:input.form-control {:free-form/input {:key :password} | ||
:type :password | ||
:id :password}] | ||
[:div.errors {:free-form/error-message {:key :password}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :select :error "validation-errors"}} | ||
[:label {:for :select} "Select"] | ||
[:select.form-control {:free-form/input {:key :select} | ||
:type :select | ||
:id :select} | ||
[:option] | ||
[:option {:value :dog} "Dog"] | ||
[:option {:value :cat} "Cat"] | ||
[:option {:value :squirrel} "Squirrel"] | ||
[:option {:value :giraffe} "Giraffe"]] | ||
[:div.errors {:free-form/error-message {:key :select}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :select-with-group :error "validation-errors"}} | ||
[:label {:for :select} "Select with groups"] | ||
[:select.form-control {:free-form/input {:key :select-with-group} | ||
:type :select | ||
:id :select-with-group} | ||
[:option] | ||
[:optgroup {:label "Numbers"} | ||
[:option {:value :one} "One"] | ||
[:option {:value :two} "Two"] | ||
[:option {:value :three} "Three"] | ||
[:option {:value :four} "Four"]] | ||
[:optgroup {:label "Leters"} | ||
[:option {:value :a} "A"] | ||
[:option {:value :b} "B"] | ||
[:option {:value :c} "C"] | ||
[:option {:value :d} "D"]]] | ||
[:div.errors {:free-form/error-message {:key :select-with-group}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :textarea :error "validation-errors"}} | ||
[:label {:for :text-area} "Text area"] | ||
[:textarea.form-control {:free-form/input {:key :textarea} | ||
:id :textarea}] | ||
[:div.errors {:free-form/error-message {:key :textarea}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key [:t :e :x :t] :error "validation-errors"}} | ||
[:label {:for :text} "Text with deep keys"] | ||
[:input.form-control {:free-form/input {:keys [:t :e :x :t]} | ||
:type :text | ||
:id :text | ||
:placeholder "placeholder"}] | ||
[:div.errors {:free-form/error-message {:keys [:t :e :x :t]}} [:p.error]]] | ||
[:div.field {:free-form/error-class {:key :text-with-extra-validation-errors :error "validation-errors" | ||
:extra-keys [[:text] [:-general]]}} | ||
[:label {:for :text-with-extra-validation-errors} "Text with extra validation errors"] | ||
[:input.form-control {:free-form/input {:key :text-with-extra-validation-errors} | ||
:type :text | ||
:id :text-with-extra-validation-errors | ||
:placeholder "This will be marked as a validation error also when Text and General have validation errors."}] | ||
[:div.errors {:free-form/error-message {:key :text-with-extra-validation-errors}} [:p.error]]] | ||
[:button "Button"]]] | ||
|
||
(testing "simple generation" | ||
(let [generated-input (hide-on-change | ||
(free-form/form {} {} (fn [_keys _value]) | ||
plain-reagent-form-template))] | ||
(is (= generated-input | ||
[:form {:noValidate true} | ||
[:div.errors {:free-form/error-message {:key :-general}} [:p.error]] | ||
[:div.field {} | ||
[:label {:for :text} "Text"] | ||
[:input.form-control {:type :text | ||
:id :text | ||
:placeholder "placeholder" | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :text}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :email} "Email"] | ||
[:input.form-control {:type :email | ||
:id :email | ||
:placeholder "[email protected]" | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :email}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :password} "Password"] | ||
[:input.form-control {:type :password | ||
:id :password | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :password}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :select} "Select"] | ||
[:select.form-control {:type :select | ||
:id :select | ||
:default-value nil | ||
:on-change :was-function} | ||
[:option] | ||
[:option {:value :dog} "Dog"] | ||
[:option {:value :cat} "Cat"] | ||
[:option {:value :squirrel} "Squirrel"] | ||
[:option {:value :giraffe} "Giraffe"]] | ||
[:div.errors {:free-form/error-message {:key :select}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :select} "Select with groups"] | ||
[:select.form-control {:type :select | ||
:id :select-with-group | ||
:default-value nil | ||
:on-change :was-function} | ||
[:option] | ||
[:optgroup {:label "Numbers"} | ||
[:option {:value :one} "One"] | ||
[:option {:value :two} "Two"] | ||
[:option {:value :three} "Three"] | ||
[:option {:value :four} "Four"]] | ||
[:optgroup {:label "Leters"} | ||
[:option {:value :a} "A"] | ||
[:option {:value :b} "B"] | ||
[:option {:value :c} "C"] | ||
[:option {:value :d} "D"]]] | ||
[:div.errors {:free-form/error-message {:key :select-with-group}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text-area} "Text area"] | ||
[:textarea.form-control {:id :textarea | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :textarea}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text} "Text with deep keys"] | ||
[:input.form-control {:type :text | ||
:id :text | ||
:placeholder "placeholder" | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:keys [:t :e :x :t]}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text-with-extra-validation-errors} "Text with extra validation errors"] | ||
[:input.form-control {:type :text | ||
:id :text-with-extra-validation-errors | ||
:placeholder "This will be marked as a validation error also when Text and General have validation errors." | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :text-with-extra-validation-errors}} [:p.error]]] | ||
[:button "Button"]])))) | ||
|
||
(testing "generation with initial data" | ||
(let [generated-input (hide-on-change | ||
(free-form/form {:text "Text value" | ||
:email "Email value" | ||
:password "Password value" | ||
;:select "cat" ; TODO: enable this and fix generation, as it's broken right now. | ||
;:select-with-group "two" ; TODO: enable this and fix generation, as it's broken right now. | ||
:textarea "Textarea value" | ||
:t {:e {:x {:t "Text with deep keys value"}}} | ||
} {} (fn [_keys _value]) | ||
plain-reagent-form-template))] | ||
(is (= generated-input | ||
[:form {:noValidate true} | ||
[:div.errors {:free-form/error-message {:key :-general}} [:p.error]] | ||
[:div.field {} | ||
[:label {:for :text} "Text"] | ||
[:input.form-control {:type :text | ||
:id :text | ||
:placeholder "placeholder" | ||
:default-value "Text value" | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :text}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :email} "Email"] | ||
[:input.form-control {:type :email | ||
:id :email | ||
:placeholder "[email protected]" | ||
:default-value "Email value" | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :email}} [:p.error]]] | ||
[:div.field {} [:label {:for :password} "Password"] | ||
[:input.form-control {:type :password | ||
:id :password | ||
:default-value "Password value" | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :password}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :select} "Select"] | ||
[:select.form-control {:type :select | ||
:id :select | ||
:default-value nil | ||
:on-change :was-function} | ||
[:option] | ||
[:option {:value :dog} "Dog"] | ||
[:option {:value :cat} "Cat"] | ||
[:option {:value :squirrel} "Squirrel"] | ||
[:option {:value :giraffe} "Giraffe"]] | ||
[:div.errors {:free-form/error-message {:key :select}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :select} "Select with groups"] | ||
[:select.form-control {:type :select | ||
:id :select-with-group | ||
:default-value nil | ||
:on-change :was-function} | ||
[:option] | ||
[:optgroup {:label "Numbers"} | ||
[:option {:value :one} "One"] | ||
[:option {:value :two} "Two"] | ||
[:option {:value :three} "Three"] | ||
[:option {:value :four} "Four"]] | ||
[:optgroup {:label "Leters"} | ||
[:option {:value :a} "A"] | ||
[:option {:value :b} "B"] | ||
[:option {:value :c} "C"] | ||
[:option {:value :d} "D"]]] | ||
[:div.errors {:free-form/error-message {:key :select-with-group}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text-area} "Text area"] | ||
[:textarea.form-control {:id :textarea | ||
:default-value "Textarea value" | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :textarea}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text} "Text with deep keys"] | ||
[:input.form-control {:type :text | ||
:id :text | ||
:placeholder "placeholder" | ||
:default-value "Text with deep keys value" | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:keys [:t :e :x :t]}} [:p.error]]] | ||
[:div.field {} | ||
[:label {:for :text-with-extra-validation-errors} "Text with extra validation errors"] | ||
[:input.form-control {:type :text | ||
:id :text-with-extra-validation-errors | ||
:placeholder "This will be marked as a validation error also when Text and General have validation errors." | ||
:default-value nil | ||
:on-change :was-function}] | ||
[:div.errors {:free-form/error-message {:key :text-with-extra-validation-errors}} [:p.error]]] | ||
[:button "Button"]])))))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
;;;; Copyright © 2016 José Pablo Fernández Silva, All rights reserved. | ||
|
||
(ns free-form.runner | ||
(:require [doo.runner :refer-macros [doo-tests]] | ||
[free-form.core-test])) | ||
|
||
(doo-tests 'free-form.core-test) |