diff options
| author | sostler <sbostler@gmail.com> | 2010-02-10 01:08:44 -0500 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-02-10 01:08:44 -0500 |
| commit | d3fcf8d56122514c3dcbac004fcf105a4e899352 (patch) | |
| tree | 484ded214ddba3a6cc44e40d129fe1fc403e91fc /compojure-3.2/test/compojure/html/form_helpers_test.clj | |
| parent | 079e2e9c1d3d5fb0f19515bfb566864565c43213 (diff) | |
Added custom compojure tree
Diffstat (limited to 'compojure-3.2/test/compojure/html/form_helpers_test.clj')
| -rwxr-xr-x | compojure-3.2/test/compojure/html/form_helpers_test.clj | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/compojure-3.2/test/compojure/html/form_helpers_test.clj b/compojure-3.2/test/compojure/html/form_helpers_test.clj new file mode 100755 index 0000000..b01f3ed --- /dev/null +++ b/compojure-3.2/test/compojure/html/form_helpers_test.clj @@ -0,0 +1,118 @@ +(ns compojure.html.form-helpers-test + (:use compojure.html.form-helpers + clojure.contrib.test-is)) + +(defn attribute + "Get an attribute from a tag vector." + [tag key] + ((second tag) key)) + +(deftest test-hidden-field + (testing "passing in only name" + (is (= [:input {:type "hidden", :name "foo", :id "foo"}] + (hidden-field "foo")))) + (testing "passing in name and value" + (is (= [:input {:value "hidden", :type "hidden", :name "foo", :id "foo"}] + (hidden-field "foo" "hidden"))))) + +(deftest test-text-field + (testing "passing in only name" + (is (= [:input {:type "text", :id "foo", :name "foo"}] + (text-field :foo)))) + (testing "passing in name and value" + (is (= [:input {:value :text-field, :type "text", :name "foo", :id "foo"}] + (text-field :foo :text-field))))) + +(deftest test-password-field + (is (= [:input {:type "password", :id "foo", :name "foo" :value ""}] + (password-field "foo")))) + +(deftest test-check-box + (testing "passing in only name" + (is (= [:input {:type "checkbox" :id "foo" :name "foo" :value "true" :checked nil}] + (check-box :foo)))) + (testing "passing in name and checked" + (is (= [:input {:type "checkbox", :name "foo", :id "foo", :value "true", :checked true}] + (check-box :foo true)))) + (testing "passing in name, checked, and value" + (is (= [:input {:type "checkbox", :name "foo", :id "foo", :value "checkbox", :checked false}] + (check-box :foo false "checkbox"))))) + +(deftest test-radio-button + (testing "passing in only name" + (is (= [:input {:type "radio" :id "foo_true" :name "foo" :value "true" :checked nil}] + (radio-button :foo)))) + (testing "passing in name and checked" + (is (= [:input {:type "radio", :name "foo", :id "foo_true", :value "true", :checked true}] + (radio-button :foo true)))) + (testing "passing in name, checked, and value" + (is (= [:input {:type "radio", :name "foo", :id "foo_radio", :value "radio", :checked false}] + (radio-button :foo false "radio"))))) + +(deftest test-select-options + (testing "passing in only options" + (is (= '([:option {:value "1"} "a"] + [:option {:value "2"} "b"] + [:option {:value "3"} "c"]) + (select-options [["a" "1"] ["b" "2"] ["c" "3"]])))) + (testing "passing in options and selected" + (is (= '([:option {:selected "selected" :value "1"} "a"] + [:option {:value "2"} "b"]) + (select-options [["a" "1"] ["b" "2"]] "1"))))) + +(deftest test-drop-down + (testing "passing in name and options" + (is (= [:select {:name "foo", :id "foo"} + '([:option {:value "1"} "a"] + [:option {:value "2"} "b"])] + (drop-down :foo [["a" "1"] ["b" "2"]])))) + (testing "passing in name, options, and selected" + (is (= [:select {:id "foo" :name "foo"} + '([:option {:value "1"} "a"] + [:option {:value "2" :selected "selected"} "b"] + [:option {:value "3"} "c"])] + (drop-down :foo [["a" "1"] ["b" "2"] ["c" "3"]] "2"))))) + +(deftest test-text-area + (testing "passing in only name" + (is (= [:textarea {:name "text", :id "text"} nil] + (text-area "text")))) + (testing "passing in name and value" + (is (= [:textarea {:name "text", :id "text"} "textarea"] + (text-area "text" "textarea"))))) + +(deftest test-label + (is (= [:label {:for "label"} "labeltext"] + (label "label" "labeltext")))) + +(deftest test-submit-button + (is (= [:input {:type "submit", :value "submit"}] + (submit-button "submit")))) + +(deftest test-reset-button + (is (= [:input {:type "reset", :value "reset"}] + (reset-button "reset")))) + +(deftest test-form-to + (let [form (form-to [:post "action"] [])] + (is (= (attribute form :method) "POST")))) + +(deftest test-form-to-update + (let [form (form-to [:update "action"] [])] + (is (= (attribute form :method) "POST")) + (let [hidden (nth form 2)] + (is (= (attribute hidden :value) "UPDATE")) + (is (= (attribute hidden :name) "_method")) + (is (= (attribute hidden :type) "hidden"))))) + +(deftest test-form-to-attrs + (let [form (form-to {:class "class" } [:post "action"] [])] + (is (= (attribute form :class) "class")))) + +(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"}])))
\ No newline at end of file |
