master
Josha von Gizycki 5 years ago
parent 341ce88abe
commit 727478a81b

@ -85,9 +85,9 @@
:type "text"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))
(nthrest
(render-widgets def {} {})
2)))))
(let [def {:fields {:foo-id {:label "foo-label"
:required true
:widget :input}}}]
@ -99,9 +99,9 @@
:type "text"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))
(nthrest
(render-widgets def {} {})
2)))))
(testing "input is default"
(let [def {:fields {:foo-id {:label "foo-label"
:required true}}}]
@ -113,9 +113,9 @@
:type "text"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))))
(nthrest
(render-widgets def {} {})
2)))))))
(testing "checkbox is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :checkbox}}}]
@ -127,9 +127,9 @@
:type "checkbox"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))
(nthrest
(render-widgets def {} {})
2)))))
(let [def {:fields {:foo-id {:label "foo-label"
:required true
:widget :checkbox}}}]
@ -141,9 +141,9 @@
:type "checkbox"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2))))))
(nthrest
(render-widgets def {} {})
2))))))
(testing "textarea is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :textarea}}}]
@ -154,9 +154,9 @@
:required false}
""])
(first
(nthrest
(render-widgets def {} {})
2)))))
(nthrest
(render-widgets def {} {})
2)))))
(let [def {:fields {:foo-id {:label "foo-label"
:required true
:widget :textarea}}}]
@ -167,9 +167,9 @@
:required true}
""])
(first
(nthrest
(render-widgets def {} {})
2))))))
(nthrest
(render-widgets def {} {})
2))))))
(testing "select is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :select
@ -180,12 +180,12 @@
[:select {:id "foo-id"
:name "foo-id"}
(list
[:option {:value "key1" :selected false} "value1"]
[:option {:value "key2" :selected false} "value2"])])
[:option {:value "key1" :selected false} "value1"]
[:option {:value "key2" :selected false} "value2"])])
(first
(nthrest
(render-widgets def {} {})
2))))))
(nthrest
(render-widgets def {} {})
2))))))
(testing "hidden is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :hidden}}}]
@ -196,9 +196,9 @@
:name "foo-id"
:value nil}])
(first
(nthrest
(render-widgets def {} {})
2)))))
(nthrest
(render-widgets def {} {})
2)))))
(let [def {:fields {:foo-id {:label "foo-label"
:widget :hidden}}}]
(is (= (list nil
@ -208,9 +208,9 @@
:name "foo-id"
:value "4711"}])
(first
(nthrest
(render-widgets def {:foo-id "4711"} {})
2))))))
(nthrest
(render-widgets def {:foo-id "4711"} {})
2))))))
(testing "mselect is rendered correctly"
(let [def {:fields {:foo-id {:label "foo-label"
:widget :mselect
@ -223,12 +223,22 @@
:size 5
:multiple "multiple"}
(list
[:option {:value "key1" :selected false} "value1"]
[:option {:value "key2" :selected false} "value2"])])
[:option {:value "key1" :selected false} "value1"]
[:option {:value "key2" :selected false} "value2"])])
(first
(nthrest
(render-widgets def {} {})
2)))))))
(nthrest
(render-widgets def {} {})
2))))))
(testing "input-widget uses :attr"
(let [def {:fields {:foor-id {:attrs {:autofocus true}}}}
rendered-input (-> (render-widgets def {} {})
(nthrest 2)
first
(nthrest 2)
first)
input-attrs (second rendered-input)]
(contains? input-attrs :autofocus)
(is (= true (:autofocus input-attrs))))))
(deftest to-form-is-used
(testing "data passed to fo-form is taken from values"
@ -242,9 +252,9 @@
:required false
:type "text"}])
(first
(nthrest
(render-widgets def {:foo "abc"} {})
2)))))
(nthrest
(render-widgets def {:foo "abc"} {})
2)))))
(let [def {:fields {:foo {:label ""
:to-form (partial str "4711")}}}]
(is (= (list nil
@ -255,9 +265,9 @@
:required false
:type "text"}])
(first
(nthrest
(render-widgets def {:foo "abc"} {:params {:foo "def"}})
2)))))))
(nthrest
(render-widgets def {:foo "abc"} {:params {:foo "def"}})
2)))))))
(deftest form-specs-is-applied
(testing "valid spec"
@ -268,10 +278,10 @@
:id "__form-hash"
:value (form-hash def {})}]
(second
(render-widgets
def
{}
{:params {:__form-hash (form-hash def {})}}))))))
(render-widgets
def
{}
{:params {:__form-hash (form-hash def {})}}))))))
(testing "invalid spec"
(let [def {:fields {}
:form-specs [(fn [req] false)]}]
@ -279,10 +289,10 @@
[:h2.flash__heading--error "Warning"]
[:p "The form must comply to " (name :clojure.spec.alpha/unknown)]]
(first
(render-widgets
def
{}
{:params {:__form-hash (form-hash def {})}})))))))
(render-widgets
def
{}
{:params {:__form-hash (form-hash def {})}})))))))
(deftest html-contents-are-escaped
(testing "mselect"

Loading…
Cancel
Save