parent
d9f2cd0c47
commit
d242cc4e37
@ -0,0 +1,29 @@
|
||||
(ns wanijo.framework.form-test
|
||||
(:require [clojure.test :refer :all]
|
||||
[wanijo.framework.form :refer [form-data]]))
|
||||
|
||||
(deftest test-form-data
|
||||
(testing "no from-req is given"
|
||||
(let [def {:fields {:name {:label ""
|
||||
:required false
|
||||
:spec :a}}}]
|
||||
(is (= {:name "a"}
|
||||
(form-data def {:params {:name "a"}})))
|
||||
(is (= {:name nil}
|
||||
(form-data def {:params {}})))))
|
||||
(testing "from-req is called"
|
||||
(let [def {:fields {:name {:label ""
|
||||
:required false
|
||||
:spec :a
|
||||
:from-req #(str "foo" %)}}}]
|
||||
(is (= {:name "foo"}
|
||||
(form-data def {:params {}})))
|
||||
(is (= {:name "fooa"}
|
||||
(form-data def {:params {:name "a"}})))))
|
||||
(testing "type conversion"
|
||||
(let [def {:fields {:name {:label ""
|
||||
:required false
|
||||
:spec :a
|
||||
:from-req bigint}}}]
|
||||
(is (= {:name 5}
|
||||
(form-data def {:params {:name 5}}))))))
|
Loading…
Reference in new issue