diff options
Diffstat (limited to 'compojure-3.2/test/compojure/html')
| -rwxr-xr-x | compojure-3.2/test/compojure/html/form_helpers_test.clj | 118 | ||||
| -rwxr-xr-x | compojure-3.2/test/compojure/html/gen_test.clj | 93 | ||||
| -rwxr-xr-x | compojure-3.2/test/compojure/html/page_helpers_test.clj | 71 |
3 files changed, 282 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 diff --git a/compojure-3.2/test/compojure/html/gen_test.clj b/compojure-3.2/test/compojure/html/gen_test.clj new file mode 100755 index 0000000..5d64b7c --- /dev/null +++ b/compojure-3.2/test/compojure/html/gen_test.clj @@ -0,0 +1,93 @@ +(ns compojure.html.gen-test + (:use compojure.html.gen + clojure.contrib.test-is)) + +(deftest tag-text + (is (= (html [:text "Lorem Ipsum"]) "<text>Lorem Ipsum</text>"))) + +(deftest empty-tags + (is (= (html [:text]) "<text />"))) + +(deftest empty-block-tags + (is (= (html [:div]) "<div></div>")) + (is (= (html [:h1]) "<h1></h1>")) + (is (= (html [:script]) "<script></script>"))) + +(deftest empty-links-tag + (is (= (html [:a]) "<a></a>"))) + +(deftest tags-can-be-strs + (is (= (html ["div"] "<div></div>")))) + +(deftest tags-can-be-symbols + (is (= (html ['div] "<div></div>")))) + +(deftest tag-concatenation + (is (= (html [:body "foo" "bar"]) "<body>foobar</body>")) + (is (= (html [:body [:p] [:br]])) "<body><p /><br /></body>")) + +(deftest tag-seq-expand + (is (= (html [:body (list "foo" "bar")]) + "<body>foobar</body>"))) + +(deftest html-seq-expand + (is (= (html (list [:p "a"] [:p "b"])) + "<p>a</p><p>b</p>"))) + +(deftest nested-tags + (is (= (html [:div [:p]] "<div><p /></div>"))) + (is (= (html [:div [:b]] "<div><b></b></div>"))) + (is (= (html [:p [:span [:a "foo"]]]) + "<p><span><a>foo</a></span></p>"))) + +(deftest attribute-maps + (is (= (html [:xml {:a "1", :b "2"}]) + "<xml a=\"1\" b=\"2\" />"))) + +(deftest blank-attribute-map + (is (= (html [:xml {}]) "<xml />"))) + +(deftest escaped-chars + (is (= (escape-html "\"") """)) + (is (= (escape-html "<") "<")) + (is (= (escape-html ">") ">")) + (is (= (escape-html "&") "&"))) + +(deftest escaped-attrs + (is (= (html [:div {:id "\""}]) + "<div id=\""\"></div>"))) + +(deftest attrs-can-be-strs + (is (= (html [:img {"id" "foo"}]) "<img id=\"foo\" />"))) + +(deftest attrs-can-be-symbols + (is (= (html [:img {'id "foo"}]) "<img id=\"foo\" />"))) + +(deftest attr-keys-different-types + (is (= (html [:xml {:a "1", 'b "2", "c" "3"}]) + "<xml a=\"1\" b=\"2\" c=\"3\" />"))) + +(deftest tag-class-sugar + (is (= (html [:div.foo]) "<div class=\"foo\"></div>"))) + +(deftest tag-many-class-sugar + (is (= (html [:div.a.b]) "<div class=\"a b\"></div>")) + (is (= (html [:div.a.b.c]) "<div class=\"a b c\"></div>"))) + +(deftest tag-id-sugar + (is (= (html [:div#foo]) "<div id=\"foo\"></div>"))) + +(deftest tag-id-and-classes + (is (= (html [:div#foo.bar.baz]) + "<div class=\"bar baz\" id=\"foo\"></div>"))) + +(deftest html-not-indented + (is (= (html [:p "Lorem\nIpsum"]) "<p>Lorem\nIpsum</p>"))) + +(deftest attrs-bool-true + (is (= (html [:input {:type "checkbox" :checked true}]) + "<input checked=\"checked\" type=\"checkbox\" />"))) + +(deftest attrs-bool-false + (is (= (html [:input {:type "checkbox" :checked false}]) + "<input type=\"checkbox\" />"))) diff --git a/compojure-3.2/test/compojure/html/page_helpers_test.clj b/compojure-3.2/test/compojure/html/page_helpers_test.clj new file mode 100755 index 0000000..fe29481 --- /dev/null +++ b/compojure-3.2/test/compojure/html/page_helpers_test.clj @@ -0,0 +1,71 @@ +(ns compojure.html.page-helpers-test + (:use compojure.html.page-helpers + clojure.contrib.test-is)) + +(deftest test-doctype + (testing "html4" + (is (= (doctype :html4) + (str "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" " + "\"http://www.w3.org/TR/html4/strict.dtd\">\n")))) + (testing "xhtml-strict" + (is (= (doctype :xhtml-strict) + (str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")))) + (testing "html5" + (is (= (doctype :html5) + (str "<!DOCTYPE html>")))) + (testing "xhtml-transitional" + (is (= (doctype :xhtml-transitional) + (str "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"))))) + +(deftest test-xhtml-tag + (is (= (xhtml-tag "test") + [:html {:xmlns "http://www.w3.org/1999/xhtml", "xml:lang" "test", :lang "test"} nil]))) + +(deftest test-include-js + (testing "one" + (is (= (include-js "foo.js") + '([:script {:type "text/javascript", :src "foo.js"}])))) + (testing "many" + (is (= (include-js "foo.js" "bar.js" "baz.js") + '([:script {:type "text/javascript", :src "foo.js"}] + [:script {:type "text/javascript", :src "bar.js"}] + [:script {:type "text/javascript", :src "baz.js"}]))))) + +(deftest test-include-css + (testing "one" + (is (= (include-css "foo.css") + '([:link {:type "text/css" :href "foo.css" :rel "stylesheet"}])))) + (testing "many" + (is (= (include-css "foo.css" "bar.css" "baz.css") + '([:link {:type "text/css", :href "foo.css", :rel "stylesheet"}] + [:link {:type "text/css", :href "bar.css", :rel "stylesheet"}] + [:link {:type "text/css", :href "baz.css", :rel "stylesheet"}]))))) + +(deftest test-javascript-tag + (is (= (javascript-tag "alert('hi');") + [:script {:type "text/javascript"} + (str "//<![CDATA[\n" "alert('hi');" "\n//]]>")]))) + +(deftest test-link-to + (is (= (link-to "http://compojure.org") + [:a {:href "http://compojure.org"} nil]))) + +(deftest test-url-encode + (is (= (url-encode "foo&bar*/baz.net") + (str "foo%26bar*%2Fbaz.net")))) + +(deftest test-url-params + (is (= (url-params "http://example.com" {:lang "en", :offset 10}) + "http://example.com?lang=en&offset=10"))) + +(deftest test-unordered-list + (is (= (unordered-list ["a" "b"]) + [:ul {} + '([:li "a"] [:li "b"])]))) + +(deftest test-ordered-list + (is (= (ordered-list ["b" "a"]) + [:ol {} + '([:li "b"] [:li "a"])])))
\ No newline at end of file |
