Skip to content

Commit

Permalink
Added some tests for form helpers.
Browse files Browse the repository at this point in the history
Signed-off-by: James Reeves <jreeves@weavejester.com>
  • Loading branch information
budu authored and weavejester committed May 8, 2009
1 parent 8cb7996 commit 7361f9c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/compojure/html/form_helpers.clj
Expand Up @@ -11,20 +11,39 @@
(is (= (text-field :foo)
[:input {:type "text", :id "foo", :name "foo"}])))

(deftest test-password-field
(is (= (password-field "foo")
[:input {:type "password", :id "foo", :name "foo" :value ""}])))

(deftest form-input-attrs
(let [field (text-field {:style "color: red;"} :foo)]
(is (= (attribute field :style) "color: red;"))))

(deftest test-with-params
(is (= (with-params {:foo "bar"} (text-field :foo))
[:input {:type "text", :id "foo", :name "foo", :value "bar"}])))


(deftest test-check-box
(is (= (check-box :foo)
[:input {:type "checkbox"
:id "foo"
:name "foo"
:value "true"
:checked nil}])))

(deftest select-options-with-values
(is (= (select-options [["a" "1"] ["b" "2"] ["c" "3"]])
'([:option {:value "1"} "a"]
[:option {:value "2"} "b"]
[:option {:value "3"} "c"]))))

(deftest drop-down-selected
(is (= (drop-down :foo [["a" "1"] ["b" "2"] ["c" "3"]] "2")
[:select {:id "foo" :name "foo"}
'([:option {:value "1"} "a"]
[:option {:value "2" :selected "selected"} "b"]
[:option {:value "3"} "c"])])))

(deftest test-form-to
(let [form (form-to [:post "action"] [])]
(is (= (attribute form :method) "POST"))))
Expand Down

0 comments on commit 7361f9c

Please sign in to comment.