|  |  | @ -1,6 +1,9 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | (ns wanijo.framework.form-test |  |  |  | (ns wanijo.framework.form-test | 
			
		
	
		
		
			
				
					
					|  |  |  |   (:require [clojure.test :refer :all] |  |  |  |   (:require [clojure.test :refer :all] | 
			
		
	
		
		
			
				
					
					|  |  |  |             [wanijo.framework.form :refer [form-data valid?]] |  |  |  |             [wanijo.framework.form :refer [form-data | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                            valid? | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                            render-widgets | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                            form-hash]] | 
			
		
	
		
		
			
				
					
					|  |  |  |             [clojure.spec.alpha :as spec])) |  |  |  |             [clojure.spec.alpha :as spec])) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | (deftest test-form-data |  |  |  | (deftest test-form-data | 
			
		
	
	
		
		
			
				
					|  |  | @ -57,3 +60,142 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  |                               :spec string?}}}] |  |  |  |                               :spec string?}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |       (is (= true (valid? def {:params {:foo "5" |  |  |  |       (is (= true (valid? def {:params {:foo "5" | 
			
		
	
		
		
			
				
					
					|  |  |  |                                         :bar "a"}})))))) |  |  |  |                                         :bar "a"}})))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | (deftest test-render-widgets | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "form-hash is rendered" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list [:input {:type "hidden" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :name "__form-hash" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :id "__form-hash" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :value (form-hash def {})}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (rest (render-widgets def {} {})))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "input is rendered correctly" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :input}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:input {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :required nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :type "text" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :value nil}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :required true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :input}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:input {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :required "required" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :type "text" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :value nil}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (testing "input is default" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                    :required true}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:input {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                               :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                               :required "required" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                               :type "text" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                               :value nil}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                  (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                  2))))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "checkbox is rendered correctly" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :checkbox}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:input {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :checked false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :type "checkbox" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :value nil}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :required true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :checkbox}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:input {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :checked false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :type "checkbox" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                             :value nil}]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2)))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "textarea is rendered correctly" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :textarea}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:textarea {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                :required nil} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     ""]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :required true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :textarea}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:textarea {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                :required "required"} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     ""]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2)))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "select is rendered correctly" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :select | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :options [["value1" "key1"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                            ["value2" "key2"]]}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:select {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                              :name "foo-id"} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     (list | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:option {:value "key1" :selected false} "value1"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:option {:value "key2" :selected false} "value2"])]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2)))))) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   (testing "mselect is rendered correctly" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     (let [def {:fields {:foo-id {:label "foo-label" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :widget :mselect | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                  :options [["value1" "key1"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                                            ["value2" "key2"]]}}}] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       (is (= (list nil | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:label {:for "foo-id"} "foo-label"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                    [:select {:id "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                              :name "foo-id" | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                              :size 5 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                              :multiple "multiple"} | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     (list | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:option {:value "key1" :selected false} "value1"] | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                      [:option {:value "key2" :selected false} "value2"])]) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |              (first | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |               (nthrest | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                (render-widgets def {} {}) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                2))))))) | 
			
		
	
	
		
		
			
				
					|  |  | 
 |