From bb8a40c1dfc0c4d8fb66b01a820a308f31b8ac3f Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:12:55 +0100 Subject: [PATCH 01/30] move macros.clj to src/clj --- src/{cljs => clj}/domina/macros.clj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{cljs => clj}/domina/macros.clj (100%) diff --git a/src/cljs/domina/macros.clj b/src/clj/domina/macros.clj similarity index 100% rename from src/cljs/domina/macros.clj rename to src/clj/domina/macros.clj From 811985fbff92d3d5e3ed9f1e69abb26969b3ec5a Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:14:29 +0100 Subject: [PATCH 02/30] upgrade clj to 1.5.1, cljs to 0.0-1847, cljsbuild to 0.3.2, remove unused stuff --- project.clj | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/project.clj b/project.clj index a2d954c..c385ae6 100644 --- a/project.clj +++ b/project.clj @@ -1,12 +1,11 @@ (defproject domina "1.0.3-SNAPSHOT" :description "A DOM manipulation library for ClojureScript inspired by JQuery" - :source-paths ["src/cljs"] - :dependencies [[org.clojure/clojure "1.4.0"]] - :plugins [[lein-cljsbuild "0.3.0"] - [lein-clojars "0.9.1"]] + :source-paths ["src/clj" "src/cljs"] + :dependencies [[org.clojure/clojure "1.5.1"] + [org.clojure/clojurescript "0.0-1847"]] + :plugins [[lein-cljsbuild "0.3.2"]] :hooks [leiningen.cljsbuild] - :cljsbuild {:builds [{:jar true - :compiler {:libs ["goog/dom/query.js"] + :cljsbuild {:builds [{:compiler {:libs ["goog/dom/query.js"] :pretty-print true :output-dir ".cljsbuild/domina" :output-to "public/domina.js"}} @@ -33,15 +32,4 @@ :optimizations :advanced :pretty-print true :output-dir ".cljsbuild/advanced" - :output-to "public/test_advanced.js"}}]} - :repositories {"sonatype-staging" - "https://oss.sonatype.org/content/groups/staging/"}) - -(comment - (do - (require '[cljs.repl :as repl]) - (require '[cljs.repl.browser :as browser]) - (def env (browser/repl-env)) - (repl/repl env)) - - ) + :output-to "public/test_advanced.js"}}]}) From 0ebd401fc30b24e0c075da874606475ad59c911b Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:19:57 +0100 Subject: [PATCH 03/30] remove blank line from the topo --- src/cljs/domina/events.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cljs/domina/events.cljs b/src/cljs/domina/events.cljs index 1db48f3..9dee1ef 100644 --- a/src/cljs/domina/events.cljs +++ b/src/cljs/domina/events.cljs @@ -1,4 +1,3 @@ - (ns domina.events (:require [domina :as domina] [goog.object :as gobj] From 6f96219f5d920970789c62ba7280183511493ec8 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:22:44 +0100 Subject: [PATCH 04/30] remove not existent dispatch-event fn --- test/cljs/domina/test.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cljs/domina/test.cljs b/test/cljs/domina/test.cljs index 0ebe5e1..fd0b136 100644 --- a/test/cljs/domina/test.cljs +++ b/test/cljs/domina/test.cljs @@ -12,7 +12,7 @@ [domina.xpath :only [xpath]] [domina.css :only [sel]] [domina.events :only [listen! capture! listen-once! capture-once! - unlisten! dispatch-event! dispatch! unlisten-by-key! + unlisten! dispatch! unlisten-by-key! get-listeners prevent-default stop-propagation target current-target event-type raw-event]]) (:require [goog.events :as events] From d801e9bb30d339b5810f4527271d7b93b7777062 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:36:01 +0100 Subject: [PATCH 05/30] add clojurescript.test and move testing stuff into the dev profile --- project.clj | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/project.clj b/project.clj index c385ae6..e1cc2c0 100644 --- a/project.clj +++ b/project.clj @@ -8,28 +8,29 @@ :cljsbuild {:builds [{:compiler {:libs ["goog/dom/query.js"] :pretty-print true :output-dir ".cljsbuild/domina" - :output-to "public/domina.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :pretty-print true - :optimizations :none - :output-dir "public/build_no_opt" - :output-to "public/test_no_opt.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :whitespace - :pretty-print true - :output-dir ".cljsbuild/whitespace" - :output-to "public/test_whitespace.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :simple - :pretty-print true - :output-dir ".cljsbuild/simple" - :output-to "public/test_simple.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :advanced - :pretty-print true - :output-dir ".cljsbuild/advanced" - :output-to "public/test_advanced.js"}}]}) + :output-to "public/domina.js"}}]} + :profiles {:dev {:plugins [[com.cemerick/clojurescript.test "0.1.0"]] + :cljsbuild {:builds [{:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :pretty-print true + :optimizations :none + :output-dir "public/build_no_opt" + :output-to "public/test_no_opt.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :whitespace + :pretty-print true + :output-dir ".cljsbuild/whitespace" + :output-to "public/test_whitespace.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :simple + :pretty-print true + :output-dir ".cljsbuild/simple" + :output-to "public/test_simple.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :advanced + :pretty-print true + :output-dir ".cljsbuild/advanced" + :output-to "public/test_advanced.js"}}]}}}) From 864e290849b74ce4f91e528ae4fbd9f87173f269 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:46:27 +0100 Subject: [PATCH 06/30] remove dev profile --- project.clj | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/project.clj b/project.clj index e1cc2c0..3396658 100644 --- a/project.clj +++ b/project.clj @@ -8,29 +8,4 @@ :cljsbuild {:builds [{:compiler {:libs ["goog/dom/query.js"] :pretty-print true :output-dir ".cljsbuild/domina" - :output-to "public/domina.js"}}]} - :profiles {:dev {:plugins [[com.cemerick/clojurescript.test "0.1.0"]] - :cljsbuild {:builds [{:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :pretty-print true - :optimizations :none - :output-dir "public/build_no_opt" - :output-to "public/test_no_opt.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :whitespace - :pretty-print true - :output-dir ".cljsbuild/whitespace" - :output-to "public/test_whitespace.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :simple - :pretty-print true - :output-dir ".cljsbuild/simple" - :output-to "public/test_simple.js"}} - {:source-paths ["test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :advanced - :pretty-print true - :output-dir ".cljsbuild/advanced" - :output-to "public/test_advanced.js"}}]}}}) + :output-to "public/domina.js"}}]}) From bf2c1fc178029b9ff13a91072beb58ad0a8c4afc Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:46:48 +0100 Subject: [PATCH 07/30] add dev profile --- profiles.clj | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 profiles.clj diff --git a/profiles.clj b/profiles.clj new file mode 100644 index 0000000..067356f --- /dev/null +++ b/profiles.clj @@ -0,0 +1,26 @@ +{:dev {:test-paths ["test/cljs"] + :plugins [[com.cemerick/clojurescript.test "0.1.0"]] + :cljsbuild {:builds [{:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :pretty-print true + :optimizations :none + :output-dir "public/build_no_opt" + :output-to "public/test_no_opt.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :whitespace + :pretty-print true + :output-dir ".cljsbuild/whitespace" + :output-to "public/test_whitespace.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :simple + :pretty-print true + :output-dir ".cljsbuild/simple" + :output-to "public/test_simple.js"}} + {:source-paths ["test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :advanced + :pretty-print true + :output-dir ".cljsbuild/advanced" + :output-to "public/test_advanced.js"}}]}}} From ce4cad79a8c032a04c65667936050ba26d0d9e9f Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 11:51:34 +0100 Subject: [PATCH 08/30] move test to temp --- {test => temp/test}/cljs/domina/test.cljs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {test => temp/test}/cljs/domina/test.cljs (100%) diff --git a/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs similarity index 100% rename from test/cljs/domina/test.cljs rename to temp/test/cljs/domina/test.cljs From f31cd0752247c230b9aeea470ecf15ed5badc394 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 12:24:01 +0100 Subject: [PATCH 09/30] move from vector to map, added :source-paths --- project.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 3396658..95b1f71 100644 --- a/project.clj +++ b/project.clj @@ -5,7 +5,9 @@ [org.clojure/clojurescript "0.0-1847"]] :plugins [[lein-cljsbuild "0.3.2"]] :hooks [leiningen.cljsbuild] - :cljsbuild {:builds [{:compiler {:libs ["goog/dom/query.js"] + :cljsbuild {:builds {:deploy + {:source-paths ["src/cljs"] + :compiler {:libs ["goog/dom/query.js"] :pretty-print true :output-dir ".cljsbuild/domina" - :output-to "public/domina.js"}}]}) + :output-to "public/domina.js"}}}}) From 771a14901443bc57f360f2621b49e06c2e3b33bd Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 12:24:37 +0100 Subject: [PATCH 10/30] name builds --- profiles.clj | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/profiles.clj b/profiles.clj index 067356f..9136653 100644 --- a/profiles.clj +++ b/profiles.clj @@ -1,26 +1,30 @@ {:dev {:test-paths ["test/cljs"] :plugins [[com.cemerick/clojurescript.test "0.1.0"]] - :cljsbuild {:builds [{:source-paths ["test/cljs"] + :cljsbuild {:builds {:none + {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :pretty-print true :optimizations :none :output-dir "public/build_no_opt" :output-to "public/test_no_opt.js"}} - {:source-paths ["test/cljs"] + :whitespace + {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :whitespace :pretty-print true :output-dir ".cljsbuild/whitespace" :output-to "public/test_whitespace.js"}} - {:source-paths ["test/cljs"] + :simple + {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :simple :pretty-print true :output-dir ".cljsbuild/simple" :output-to "public/test_simple.js"}} - {:source-paths ["test/cljs"] + :advanced + {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :advanced :pretty-print true :output-dir ".cljsbuild/advanced" - :output-to "public/test_advanced.js"}}]}}} + :output-to "public/test_advanced.js"}}}}}} From 1707a23ac298a4c8a8af3f64d3fb981df82beca3 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 20:10:16 +0100 Subject: [PATCH 11/30] add test-commands, dev-resources, remove :ouput-dir and modify :output-to --- profiles.clj | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/profiles.clj b/profiles.clj index 9136653..620f335 100644 --- a/profiles.clj +++ b/profiles.clj @@ -1,30 +1,35 @@ {:dev {:test-paths ["test/cljs"] + :dependencies [[hiccups "0.2.0"]] :plugins [[com.cemerick/clojurescript.test "0.1.0"]] :cljsbuild {:builds {:none {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :pretty-print true :optimizations :none - :output-dir "public/build_no_opt" - :output-to "public/test_no_opt.js"}} + :output-to "dev-resources/public/js/none.js"}} :whitespace {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :whitespace :pretty-print true - :output-dir ".cljsbuild/whitespace" - :output-to "public/test_whitespace.js"}} + :output-to "dev-resources/public/js/whitespace.js"}} :simple {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :simple :pretty-print true - :output-dir ".cljsbuild/simple" - :output-to "public/test_simple.js"}} + :output-to "dev-resources/public/js/simple.js"}} :advanced {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :advanced :pretty-print true - :output-dir ".cljsbuild/advanced" - :output-to "public/test_advanced.js"}}}}}} + :output-to "dev-resources/public/js/advanced.js"}}} + :test-commands {"whitespace" + ["phantomjs" :runner "dev-resources/public/js/whitespace.js"] + + "simple" + ["phantomjs" :runner "dev-resources/public/js/simple.js"] + + "advanced" + ["phantomjs" :runner "dev-resources/public/js/advanced.js"]}}}} From 93cce00bf08118d571b80584ab74582e542b335e Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 20:11:08 +0100 Subject: [PATCH 12/30] comment test implemented with clojurescript.test --- temp/test/cljs/domina/test.cljs | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/temp/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs index fd0b136..f158747 100644 --- a/temp/test/cljs/domina/test.cljs +++ b/temp/test/cljs/domina/test.cljs @@ -101,10 +101,10 @@ ;;;;;; DOM Manipulation Tests -(add-test "basic xpath selection" - #(do (reset) - (standard-fixture) - (assert (= 3 (count (nodes (xpath "//p"))))))) +add-test "basic xpath selection" +#(do (reset) + (standard-fixture) + (assert (= 3 (count (nodes (xpath "//p")))))) (add-test "basic xpath selection (single node)" #(do (reset) @@ -135,7 +135,7 @@ (standard-fixture) (assert (= 2 (count (nodes (xpath "//p[following-sibling::p[@class='p3']]"))))))) -(add-test "look up node by id" +#_(add-test "look up node by id" #(do (reset) (standard-fixture) (assert (= 1 (count (nodes (by-id "id1"))))))) @@ -149,51 +149,51 @@ (sel "p") (sel "span")))))))) -(add-test "look up nodes by class" +#_(add-test "look up nodes by class" #(do (reset) (standard-fixture) (assert (= 1 (count (nodes (by-class "p3"))))))) -(add-test "look up multiple nodes by class" +#_(add-test "look up multiple nodes by class" #(do (reset) (append! (xpath "//body") "

test1

test2

") (assert (= 2 (count (nodes (by-class "tc"))))))) -(add-test "child selection" +#_(add-test "child selection" #(do (reset) (standard-fixture) (assert (= 3 (count (children (xpath "//div[@class='d1']"))))))) -(add-test "clone a single node" +#_(add-test "clone a single node" #(do (reset) (standard-fixture) (assert (= 1 (count (clone (single-node (xpath "//p")))))))) -(add-test "clone multiple nodes" +#_(add-test "clone multiple nodes" #(do (reset) (standard-fixture) (assert (= 3 (count (clone (nodes (xpath "//p")))))))) -(add-test "append a single child to a single parent" +#_(add-test "append a single child to a single parent" #(do (reset) (append! (xpath "//body") "

test

") (assert (= 1 (count (nodes (xpath "//body/p[@class='appended1']"))))))) -(add-test "append multiple children to a single parent" +#_(add-test "append multiple children to a single parent" #(do (reset) (append! (xpath "//body") "

test2-1

test2-2

") (assert (= 2 (count (nodes (xpath "//body/p[@class='appended2']"))))))) -(add-test "append a single child to multiple parents" +#_(add-test "append a single child to multiple parents" #(do (reset) (standard-fixture) (append! (xpath "//body/div/p") "!!") (assert (= 3 (count (nodes (xpath "//div/p/span"))))))) -(add-test "append multiple children to multiple parents" +#_(add-test "append multiple children to multiple parents" #(do (reset) (standard-fixture) (append! (xpath "//body/div/p") @@ -248,14 +248,14 @@ (assert (= 1 (count (nodes (xpath children "p[@class='i2']/following-sibling::*")))))))) -(add-test "destroy a single node" +#_(add-test "destroy a single node" #(do (reset) (append! (xpath "//body") "

app1

") (assert (= 1 (count (nodes (xpath "//body/p[@class='appended1']"))))) (destroy! (xpath "//body/p[@class='appended1']")) (assert (= 0 (count (nodes (xpath "//body/p[@class='appended1']"))))))) -(add-test "destroy multiple nodes" +#_(add-test "destroy multiple nodes" #(do (reset) (append! (xpath "//body") "

app1

app2

") @@ -263,7 +263,7 @@ (destroy! (xpath "//body/p[@class='appended2']")) (assert (= 0 (count (nodes (xpath "//body/p[@class='appended2']"))))))) -(add-test "detach and reattach a single node" +#_(add-test "detach and reattach a single node" #(do (reset) (standard-fixture) (let [n (detach! (xpath "//p[@class='p3']"))] @@ -271,7 +271,7 @@ (append! (xpath "//div[@class='d1']") n) (assert (= 1 (count (nodes (xpath "//p[@class='p3']")))))))) -(add-test "detach and reattach multiple nodes" +#_(add-test "detach and reattach multiple nodes" #(do (reset) (standard-fixture) (let [n (detach! (xpath "//div[@class='d1']/p"))] @@ -279,7 +279,7 @@ (append! (xpath "//div[@class='d1']") n) (assert (= 3 (count (nodes (xpath "//div[@class='d1']/p")))))))) -(add-test "detach child nodes" +#_(add-test "detach child nodes" #(do (reset) (standard-fixture) (let [parent (xpath "//div[@class='d1']") @@ -287,27 +287,27 @@ (assert (= 0 (count (nodes (xpath "//div[@class='d1']/p"))))) (assert (= 3 (count detached-children)))))) -(add-test "clear a node's contents" +#_(add-test "clear a node's contents" #(do (reset) (standard-fixture) (destroy-children! (xpath "//div[@class='d1']")) (assert (= 1 (count (nodes (xpath "//div[@class='d1']"))))) (assert (= 0 (count (nodes (xpath "//div[@class='d1']/*"))))))) -(add-test "insert-before! with a single reference and single new node" +#_(add-test "insert-before! with a single reference and single new node" #(do (reset) (append! (xpath "//body") "
Some content
") (insert-before! (nodes (by-id "ref")) "

before

") (assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before']"))))))) -(add-test "insert-before! with a single reference and multiple new nodes" +#_(add-test "insert-before! with a single reference and multiple new nodes" #(do (reset) (append! (xpath "//body") "
Some content
") (insert-before! (nodes (by-id "ref")) "

before1

before2

") (assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before2' and position()=1]"))))) (assert (= 1 (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before1' and position()=2]"))))))) -(add-test "insert-before! with multiple reference nodes and a single new node" +#_(add-test "insert-before! with multiple reference nodes and a single new node" #(do (reset) (append! (xpath "//body") "
content1
") (append! (xpath "//body") "
content2
") From c13555d3f8641027490e84f3bc2457c72be5cc5f Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 20:12:49 +0100 Subject: [PATCH 13/30] add unit tests --- test/cljs/domina/css_standard_test.cljs | 31 +++ test/cljs/domina/fixtures.cljs | 22 ++ test/cljs/domina/xpath_standard_test.cljs | 31 +++ test/cljs/domina_edge_test.cljs | 247 ++++++++++++++++++++++ test/cljs/domina_standard_test.cljs | 193 +++++++++++++++++ 5 files changed, 524 insertions(+) create mode 100644 test/cljs/domina/css_standard_test.cljs create mode 100644 test/cljs/domina/fixtures.cljs create mode 100644 test/cljs/domina/xpath_standard_test.cljs create mode 100644 test/cljs/domina_edge_test.cljs create mode 100644 test/cljs/domina_standard_test.cljs diff --git a/test/cljs/domina/css_standard_test.cljs b/test/cljs/domina/css_standard_test.cljs new file mode 100644 index 0000000..acec944 --- /dev/null +++ b/test/cljs/domina/css_standard_test.cljs @@ -0,0 +1,31 @@ +(ns domina.css-standard-test + (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] + [domina.macros :as dm] + [hiccups.core :as hm]) + (:require [cemerick.cljs.test :as t] + [domina :as dom :refer (nodes append!)] + [domina.css :as css :refer (sel)] + [domina.fixtures :as fix :refer (base-fixture)] + [hiccups.runtime :as hrt])) + +(use-fixtures :each base-fixture) + +;;; sel +(deftest sel-test + (testing "Unit Testing for (sel css-expr)\n" + (testing "Standard Cases\n" + (are [expected actual] (= expected actual) + 3 (count (nodes (sel "p"))) + 1 (count (nodes (sel ".d1"))) + 1 (count (nodes (sel "#id1"))) + 3 (count (nodes (-> (sel ".d1") + (sel "p")))) + 3 (count (nodes (sel ".d1 > p"))) + 2 (do (append! (sel "body") + (hm/html [:div + [:p [:span "some text"]] + [:p [:span "more text"]]])) + (count (nodes (-> (sel "body") + (sel "div") + (sel "p") + (sel "span"))))))))) diff --git a/test/cljs/domina/fixtures.cljs b/test/cljs/domina/fixtures.cljs new file mode 100644 index 0000000..e420691 --- /dev/null +++ b/test/cljs/domina/fixtures.cljs @@ -0,0 +1,22 @@ +(ns domina.fixtures + (:require-macros [domina.macros :as dm] + [hiccups.core :as hm]) + (:require [domina :as dom :refer (append! destroy!)] + [hiccups.runtime :as hrt] + [domina.xpath :as css :refer (xpath)] + [domina.events :as de :refer (unlisten!)])) + +(defn- initialize [] + (append! (xpath "//body") + (hm/html [:div.d1 + [:p.p1 "P1"] + [:p.p2 "P2"] + [:p#id1.p3 "P3"]]))) +(defn- reset[] + (destroy! (xpath "//body/*")) + (unlisten! (xpath "//*"))) + +(defn base-fixture [f] + (initialize) + (f) + (reset)) diff --git a/test/cljs/domina/xpath_standard_test.cljs b/test/cljs/domina/xpath_standard_test.cljs new file mode 100644 index 0000000..fbae33f --- /dev/null +++ b/test/cljs/domina/xpath_standard_test.cljs @@ -0,0 +1,31 @@ +(ns domina.xpath-standard-test + (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] + [domina.macros :as dm] + [hiccups.core :as hm]) + (:require [cemerick.cljs.test :as t] + [domina :as dom :refer (nodes single-node append!)] + [domina.xpath :as css :refer (xpath)] + [domina.fixtures :as fix :refer (base-fixture)] + [hiccups.runtime :as hrt])) + +(use-fixtures :each base-fixture) + +;;; xpath +(deftest xpath-test + (testing "Unit Testing for (xpath xpath-expr)\n" + (testing "Standard Cases\n" + (are [expected actual] (= expected actual) + 3 (count (nodes (xpath "//p"))) + false (nil? (single-node (xpath "//p"))) + 1 (count (nodes (xpath "//div[@class='d1']"))) + 3 (count (nodes (-> (xpath "//body/div[@class='d1']") + (xpath "p")))) + 2 (do + (append! (xpath "//body") + (hm/html [:div + [:p [:span "some text"]] + [:p [:span "more text"]]])) + (count (nodes (-> (xpath "//body") + (xpath "./div") + (xpath "./p") + (xpath "./span"))))))))) diff --git a/test/cljs/domina_edge_test.cljs b/test/cljs/domina_edge_test.cljs new file mode 100644 index 0000000..c866a14 --- /dev/null +++ b/test/cljs/domina_edge_test.cljs @@ -0,0 +1,247 @@ +(ns domina-edge-test + (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] + [domina.macros :as dm]) + (:require [cemerick.cljs.test :as t] + [domina :as dom :refer (nodes + single-node + by-class + by-id + append! + prepend! + clone + ancestor? + common-ancestor + children + detach! + destroy! + destroy-children! + has-class? + value)] + [domina.xpath :as xp :refer (xpath)] + [domina.fixtures :as fix :refer (base-fixture)])) + +(use-fixtures :each base-fixture) + +;;; nodes +(deftest nodes-test + (testing "Unit Testing for (nodes content)\n" + (testing "Edge Cases\n" + (testing "(nodes content)" + (are [expected actual] (= expected actual) + () (nodes nil) + false (nil? (nodes "")) + false (nil? (nodes " ")) + false (nil? (nodes (by-id "not-an-existent-id"))) + nil (nodes ()) + nil (nodes []) + nil (nodes {}) + nil (nodes #{})))))) + +;;; single-node +(deftest single-node-test + (testing "Unit Testing for (single-node node)\n" + (testing "Edge Cases\n" + (testing "(single-node node)" + (are [expected actual] (= expected actual) + nil (single-node nil) + false (nil? (single-node "")) + false (nil? (single-node " ")) + true (nil? (single-node (by-class "not-a-class"))) + true (nil? (single-node (by-id "not-an-id"))) + nil (single-node ()) + nil (single-node []) + nil (single-node {}) + nil (single-node #{})))))) + +;;; by-id +(deftest by-id-test + (testing "Unit Testing for (by-id id)\n" + (testing "Edge Cases\n" + (testing "(by-id s)" + (are [expected actual] (= expected actual) + "Error" (try + (by-id nil) + (catch js/Error e + "Error")) + nil (by-id "") + nil (by-id "not-existent-id") + nil (by-id " ")))))) + +;;; by-class +(deftest by-class-test + (testing "Unit Testing for (by-class css-class)\n" + (testing "Edge Cases\n" + (testing "(by-class css-class)" + (are [expected actual] (= expected actual) + "Error" (try + (by-class nil) + (catch js/Error e + "Error")) + ;nil (by-class "") + ;nil (by-class " ") + nil (by-class "not-existent-class")))))) + +;;; append! +(deftest append!-test + (testing "Unit Testing for (append! parent-content child-content)\n" + (testing "Edge Cases\n" + (testing "(append! single-parent single-child)" + (are [expected actual] (= expected actual) + nil (append! nil nil) + () (children (append! (by-id "id1") nil)) + () (children (append! (by-id "id1") "")) + () (children (append! (by-id "id1") " ")) + nil (append! nil "
"))) + (testing "(append! multiple-parent child-content)" + (are [expected actual] (= expected actual) + () (children (append! (by-class "p1") nil)) + () (children (append! (by-class "p1") "")) + () (children (append! (by-class "p1") " ")) + () (children (append! (by-class "p1") ())) + () (children (append! (by-class "p1") [])) + () (children (append! (by-class "p1") {})) + () (children (append! (by-class "p1") #{}))))))) + +;;; detach +(deftest detach!-test + (testing "Unit Testing for (detach! content)\n" + (testing "Edge Cases\n" + (testing "(detach! content)" + (are [expected actual] (= expected actual) + () (detach! nil) + '(nil) (detach! "") + '(nil) (detach! " ") + () (detach! ()) + () (detach! []) + () (detach! {}) + () (detach! #{}) + () (detach! (by-class "not-a-class")) + () (detach! (by-id "not-an-id"))))))) + +;;; children +(deftest children-test + (testing "Unit Testing for (children content)\n" + (testing "Edge Cases\n" + (testing "(children content)" + (are [expected actual] (= expected actual) + () (children nil) + () (children "") + () (children " ") + () (children ()) + () (children []) + () (children {}) + () (children #{}) + () (children "not-existent-parent") + () (children "not existent parent")))))) + +;;; destroy +(deftest destroy!-test + (testing "Unit Testing for (destroy! content)\n" + (testing "Edge Cases\n" + (testing "(destroy! content)" + (are [expected actual] (= expected actual) + nil (destroy! nil) + nil (destroy! "") + nil (destroy! " ") + nil (destroy! "not-a-content") + nil (destroy! "not a content") + nil (destroy! ()) + nil (destroy! []) + nil (destroy! {}) + nil (destroy! #{})))))) + +;;; common-ancestor +(deftest common-ancestor-test + (testing "Unit Testing for (common-ancestor &contents)\n" + (testing "Edge Cases\n" + (testing "(common-ancestor node-a)" + (are [expected actual] (= expected actual) + nil (common-ancestor nil))) + (testing "(common-ancestor node-a node-b)" + (are [expected actual] (= expected actual) + nil (common-ancestor nil nil) + nil (common-ancestor nil (by-id "id1")) + nil (common-ancestor (by-id "id1") nil))) + (testing "(common-ancestor node-a node-b node-c)" + (are [expected actual] (= expected actual) + nil (common-ancestor nil nil nil) + nil (common-ancestor nil (by-id "id1") nil) + nil (common-ancestor nil nil (by-id "id1")) + nil (common-ancestor (by-id "id1") nil nil)))))) + +;;; ancestor? +(deftest ancestor?-test + (testing "Unit Testing for (ancestor? ancestor-node descendant-node)\n" + (testing "Edge Cases\n" + (testing "(ancestor? ancestor descendant)" + (are [expected actual] (= expected actual) + true (ancestor? nil nil) + true (ancestor? nil (by-id "id1")) + false (ancestor? (by-id "id1") nil) + + true (ancestor? () ()) + true (ancestor? nil ()) + true (ancestor? () nil) + + true (ancestor? [] []) + true (ancestor? nil []) + true (ancestor? [] nil) + + true (ancestor? {} {}) + true (ancestor? nil {}) + true (ancestor? {} nil) + + true (ancestor? #{} #{}) + true (ancestor? nil #{}) + true (ancestor? #{} nil)))))) + +;;; clone +(deftest clone-test + (testing "Unit Testing for (clone node)\n" + (testing "Edge Cases\n" + (testing "(clone node)" + (are [expected actual] (= expected actual) + () (clone nil) + () (clone ()) + () (clone []) + () (clone {}) + () (clone #{})))))) + +;;; has-class? +(deftest has-class?-test + (testing "Unit Testing for (has-class? content class)\n" + (testing "Edge Cases\n" + (testing "(has-class? content class)" + (are [expected actual] (= expected actual) + "Error" (try + (has-class? nil nil) + (catch js/Error e + "Error")) + "Error" (try + (has-class? nil "p1") + (catch js/Error e + "Error")) + false (has-class? (by-id "id1") nil)))))) + +;;; value +(deftest value-test + (testing "Unit Testing for (value content)\n" + (testing "Edge Cases\n" + (testing "(value single-node)" + (are [expected actual] (= expected actual) + "Error" (try + (value (by-id nil)) + (catch js/Error e + "Error")) + "Error" (try + (value (by-id "")) + (catch js/Error e + "Error")) + "Error" (try + (value (by-id " ")) + (catch js/Error e + "Error")) + "Error" (try + (value (by-id "not-existent-id")) + (catch js/Error e + "Error"))))))) diff --git a/test/cljs/domina_standard_test.cljs b/test/cljs/domina_standard_test.cljs new file mode 100644 index 0000000..9b3ae44 --- /dev/null +++ b/test/cljs/domina_standard_test.cljs @@ -0,0 +1,193 @@ +(ns domina-standard-test + (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] + [domina.macros :as dm] + [hiccups.core :as hm]) + (:require [cemerick.cljs.test :as t] + [domina :as dom :refer (nodes + single-node + by-id + by-class + append! + clone + detach! + destroy! + destroy-children! + children + insert-before!)] + [domina.fixtures :as fix :refer (base-fixture)] + [domina.xpath :as xp :refer (xpath)] + [hiccups.runtime :as hrt])) + +(use-fixtures :each base-fixture) + +;;; nodes +(deftest nodes-test + (testing "Unit Testing for (nodes content)\n" + (testing "Standard Cases\n" + (testing "(nodes content)" + (are [expected actual] (= expected actual) + 1 (count (nodes (xpath "//body"))) + 1 (count (nodes (xpath "//body/div"))) + 1 (count (nodes (xpath "//div[@class='d1']")))))))) + +;;; single-node +(deftest single-node-test + (testing "Unit Testing for (single-node node)\n" + (testing "Standard Cases\n" + (testing "(single-node node)" + (are [expected actual] (= expected actual) + false (nil? (single-node (xpath "//p"))) + false (nil? (single-node (by-class "p1"))) + false (nil? (single-node (by-id "id1")))))))) + +;;; by-id +(deftest by-id-test + (testing "Unit Testing for (by-id id)\n" + (testing "Standard Cases\n" + (testing "(by-id id)" + (are [expected actual] (= expected actual) + false (nil? (by-id "id1"))))))) + +;;; by-class +(deftest by-class-test + (testing "Unit Testing for (by-class css-class)\n" + (testing "Standard Cases\n" + (testing "(by-class css-class)" + (are [expected actual] (= expected actual) + 1 (count (by-class "p3")) + 2 (do + (append! (xpath "//body") + (hm/html [:p.tc "test1"] + [:p.tc "test2"])) + (count (nodes (by-class "tc"))))))))) + +;;; append! +(deftest append!-test + (testing "Unit Testing for (append! parent-content child-content)\n" + (testing "Standard Cases\n" + (testing "(append! single-parent single-child)" + (are [expected actual] (= expected actual) + 1 (do + (children (append! (xpath "//body") + (hm/html [:p.appended1 "test"]))) + (count (nodes (xpath "//body/p[@class='appended1']")))))) + (testing "Standard Cases\n" + (testing "(append! single-parent children)" + (are [expected actual] (= expected actual) + 2 (do + (append! (xpath "//body") + (hm/html [:p.appended2 "test2-1"] + [:p.appended2 "test2-2"])) + (count (nodes (xpath "//body/p[@class='appended2']")))))) + (testing "(append! multiple-parent single-child)" + (are [expected actual] (= expected actual) + 3 (do + (append! (xpath "//body/div/p") + (hm/html [:span "!!"])) + (count (nodes (xpath "//div/p/span")))))) + (testing "(append! multiple-parent children)" + (are [expected actual] (= expected actual) + 3 (do + (append! (xpath "//body/div/p") + (hm/html ["some " [:span.foo "more"] "text"])) + (count (nodes (xpath "//div/p/span[@class='foo']")))))))))) + +;;; detach! +(deftest detach!-test + (testing "Unit Testing for (detach! content)\n" + (testing "Standard Cases\n" + (testing "(detach! single-node)" + (are [expected actual] (= expected actual) + 0 (do + (detach! (xpath "//p[@class='p3']")) + (count (nodes (xpath "//p[@class='p3']")))))) + (testing "(detach! multiple-nodes)" + (are [expected actual] (= expected actual) + 0 (do + (detach! (xpath "//div[@class='d1']/p")) + (count (nodes (xpath "//div[@class='d1']/p")))) + 0 (do + (detach! (children "//div[@class='d1']")) + (count (children "//div[@class='d1']")))))))) + +;;; children +(deftest children-test + (testing "Unit Testing for (children content)\n" + (testing "Standard Cases\n" + (testing "(children content)" + (are [expected actual] (= expected actual) + 3 (count (children (xpath "//div[@class='d1']")))))))) + +;;; clone +(deftest clone-test + (testing "Unit Testing for (clone single-node)\n" + (testing "Standard Cases\n" + (testing "(clone single-node)" + (are [expected actual] (= expected actual) + 1 (count (clone (single-node (xpath "//p")))))) + (testing "(clone multiple-nodes)" + (are [expected actual] (= expected actual) + 3 (count (clone (nodes (xpath "//p"))))))))) + +;;; destroy! +(deftest destroy!-test + (testing "Unit Testing for (destroy! content)\n" + (testing "Standard Cases\n" + (testing "(destroy! single-node)" + (are [expected actual] (= expected actual) + 0 (do (append! (xpath "//body") + (hm/html [:p.appended1 "app1"])) + (destroy! (xpath "//body/p[@class='appended1']")) + (count (nodes (xpath "//body/p[@class='appended1']")))))) + (testing "(destroy! multiple-nodes)" + (are [expected actual] (= expected actual) + 0 (do (append! (xpath "//body") + (hm/html [:p.appended2 "app1"] + [:p.appended2 "app2"])) + (destroy! (xpath "//body/p[@class='appended2']")) + (count (nodes (xpath "//body/p[@class='appended2']"))))))))) + +;;; destroy-children! +(deftest destroy-children!-test + (testing "Unit Testing for (destroy-children! content)\n" + (testing "Standard Cases\n" + (testing "(destroy-children! single-node)" + (are [expected actual] (= expected actual) + 0 (do + (destroy-children! (xpath "//div[@class='d1']")) + (count (nodes (xpath "//div[@class='d1']/*"))))))))) + +;;; insert-before! +(deftest insert_before!-test + (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n" + (testing "Standard Cases\n" + (testing "(insert-before! single-ref-node single-node)" + (are [expected actual] (= expected actual) + 1 (do + (append! (xpath "//body") + (hm/html [:div#ref "Some Content"])) + (insert-before! (nodes (by-id "ref")) "

before

") + (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before']")))))) + (testing "(insert-before! single-ref-node multiple-nodes)" + (are [expected actual] (= expected actual) + 2 (do (append! (xpath "//body") + (hm/html [:div#ref "some content"])) + (insert-before! (nodes (by-id "ref")) + (hm/html [:p "before1"] + [:p "before2"])) + (+ (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before2' and position()=1]"))) + (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before1' and position()=2]")))))))))) + +;;; insert-before! +(deftest insert_before!!-test + (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n" + (testing "Standard Cases\n" + (testing "(insert-before! multiple-ref-nodes single-node)" + (are [expected actual] (= expected actual) + 5 (do + (append! (xpath "//body") (hm/html [:div#ref1.ref "content1"])) + (append! (xpath "//body") (hm/html [:div#ref2.ref "content2"])) + (insert-before! (nodes (by-class "ref")) (hm/html [:p "before"])) + (+ (count (nodes (xpath "//div[@class='ref']"))) + (count (nodes (xpath "//div[@id='ref1']/preceding-sibling::p"))) + (count (nodes (xpath "//div[@id='ref2']/preceding-sibling::p")))))))))) From 7af612601c8cebd027202a3dc031b8d754ac816b Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Wed, 6 Nov 2013 20:15:50 +0100 Subject: [PATCH 14/30] add more unit tests --- test/cljs/domina/css_edge_test.cljs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/cljs/domina/css_edge_test.cljs diff --git a/test/cljs/domina/css_edge_test.cljs b/test/cljs/domina/css_edge_test.cljs new file mode 100644 index 0000000..8d27fdf --- /dev/null +++ b/test/cljs/domina/css_edge_test.cljs @@ -0,0 +1,22 @@ +(ns domina.css-edge-test + (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] + [domina.macros :as dm]) + (:require [cemerick.cljs.test :as t] + [domina :as dom] + [domina.css :as css] + [domina.fixtures :as fix :refer (base-fixture)])) + +(use-fixtures :each base-fixture) + +;;; sel +#_(deftest sel-test + (testing "Unit Testing for (sel css-expr)\n" + (testing "Edge Cases\n" + (are [expected actual] (= expected actual) + nil (css/sel nil) + nil (css/sel "") + nil (css/sel " ") + 0 (count (dom/nodes (css/sel ".not-existent-css-class"))) + 0 (count (dom/nodes (css/sel "#not-existent-id"))) + 0 (count (dom/nodes (css/sel ".not existent css class"))) + 0 (count (dom/nodes (css/sel "#not existent css id"))))))) From 687331a19db689cc09314544027547ee70a1b8c7 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Wed, 6 Nov 2013 23:08:15 +0100 Subject: [PATCH 15/30] update rules --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1dbeeb3..7ebe1b0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,13 +5,16 @@ public/build_no_opt public/test_*.js public/domina.js domina-tests +.lein-repl-history lib +out +dev-resources/public/js/*.js *.jar .repl pom.xml .lein-plugins .lein-failures -/target +target *.*~ \#*# .#* From dc14db9420d1af66b907878513c5fd08e6151836 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Wed, 6 Nov 2013 23:09:45 +0100 Subject: [PATCH 16/30] update cljs to r1978 and cljsbuild to 1.0.0-alpha1 --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 95b1f71..95f3bdb 100644 --- a/project.clj +++ b/project.clj @@ -2,8 +2,8 @@ :description "A DOM manipulation library for ClojureScript inspired by JQuery" :source-paths ["src/clj" "src/cljs"] :dependencies [[org.clojure/clojure "1.5.1"] - [org.clojure/clojurescript "0.0-1847"]] - :plugins [[lein-cljsbuild "0.3.2"]] + [org.clojure/clojurescript "0.0-1978"]] + :plugins [[lein-cljsbuild "1.0.0-alpha1"]] :hooks [leiningen.cljsbuild] :cljsbuild {:builds {:deploy {:source-paths ["src/cljs"] From dfe37f713a32cd22ba6e1af6ac1d05762cb5f770 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Wed, 6 Nov 2013 23:15:36 +0100 Subject: [PATCH 17/30] update edge unit tests --- test/cljs/domina/css_edge_test.cljs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/test/cljs/domina/css_edge_test.cljs b/test/cljs/domina/css_edge_test.cljs index 8d27fdf..b3c7e13 100644 --- a/test/cljs/domina/css_edge_test.cljs +++ b/test/cljs/domina/css_edge_test.cljs @@ -2,21 +2,19 @@ (:require-macros [cemerick.cljs.test :as m :refer (deftest testing are use-fixtures)] [domina.macros :as dm]) (:require [cemerick.cljs.test :as t] - [domina :as dom] - [domina.css :as css] + [domina :as dom :refer (nodes)] + [domina.css :as css :refer (sel)] [domina.fixtures :as fix :refer (base-fixture)])) (use-fixtures :each base-fixture) ;;; sel -#_(deftest sel-test +(deftest sel-test (testing "Unit Testing for (sel css-expr)\n" (testing "Edge Cases\n" (are [expected actual] (= expected actual) - nil (css/sel nil) - nil (css/sel "") - nil (css/sel " ") - 0 (count (dom/nodes (css/sel ".not-existent-css-class"))) - 0 (count (dom/nodes (css/sel "#not-existent-id"))) - 0 (count (dom/nodes (css/sel ".not existent css class"))) - 0 (count (dom/nodes (css/sel "#not existent css id"))))))) + false (nil? (sel nil)) + false (nil? (sel "")) + false (nil? (sel " ")) + 0 (count (nodes (sel ".not-existent-css-class"))) + 0 (count (nodes (sel "#not-existent-css-id"))))))) From 18d5b5ef903b18ce98c59b0a878d15b9bda01739 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Thu, 7 Nov 2013 11:10:41 +0100 Subject: [PATCH 18/30] update cljs to r2014 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 95f3bdb..7df6ab0 100644 --- a/project.clj +++ b/project.clj @@ -2,7 +2,7 @@ :description "A DOM manipulation library for ClojureScript inspired by JQuery" :source-paths ["src/clj" "src/cljs"] :dependencies [[org.clojure/clojure "1.5.1"] - [org.clojure/clojurescript "0.0-1978"]] + [org.clojure/clojurescript "0.0-2014"]] :plugins [[lein-cljsbuild "1.0.0-alpha1"]] :hooks [leiningen.cljsbuild] :cljsbuild {:builds {:deploy From c6153fb0615b58234d8d14a82af5413e599a069a Mon Sep 17 00:00:00 2001 From: magomimmo Date: Thu, 7 Nov 2013 14:27:47 +0100 Subject: [PATCH 19/30] comment other tests already implemented with clojurescript.test lib --- temp/test/cljs/domina/test.cljs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/temp/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs index f158747..050558c 100644 --- a/temp/test/cljs/domina/test.cljs +++ b/temp/test/cljs/domina/test.cljs @@ -69,28 +69,28 @@ ;;;;;; CSS selection tests -(add-test "basic CSS selection" +#_(add-test "basic CSS selection" #(do (reset) (standard-fixture) (assert (= 3 (count (nodes (sel "p"))))))) -(add-test "basic CSS selection (single node)" +#_(add-test "basic CSS selection (single node)" #(do (reset) (standard-fixture) (assert (not (nil? (single-node (sel "p"))))))) -(add-test "CSS selection with class specification" +#_(add-test "CSS selection with class specification" #(do (reset) (standard-fixture) (assert (= 1 (count (nodes (sel ".d1"))))))) -(add-test "a relative CSS selector" +#_(add-test "a relative CSS selector" #(do (reset) (standard-fixture) (assert (= 3 (count (nodes (-> (sel ".d1") (sel "p")))))))) -(add-test "extended CSS chaining" +#_(add-test "extended CSS chaining" #(do (reset) (append! (sel "body") "

some text

more text

") @@ -101,28 +101,28 @@ ;;;;;; DOM Manipulation Tests -add-test "basic xpath selection" -#(do (reset) - (standard-fixture) - (assert (= 3 (count (nodes (xpath "//p")))))) +#_(add-test "basic xpath selection" + #(do (reset) + (standard-fixture) + (assert (= 3 (count (nodes (xpath "//p"))))))) -(add-test "basic xpath selection (single node)" +#_(add-test "basic xpath selection (single node)" #(do (reset) (standard-fixture) (assert (not (nil? (single-node (xpath "//p"))))))) -(add-test "xpath selection with class specification" +#_(add-test "xpath selection with class specification" #(do (reset) (standard-fixture) (assert (= 1 (count (nodes (xpath "//div[@class='d1']"))))))) -(add-test "a relative xpath expression" +#_(add-test "a relative xpath expression" #(do (reset) (standard-fixture) (assert (= 3 (count (nodes (-> (xpath "//body/div[@class='d1']") (xpath "p")))))))) -(add-test "extended selection chaining" +#_(add-test "extended selection chaining" #(do (reset) (append! (xpath "//body") "

some text

more text

") @@ -130,7 +130,7 @@ add-test "basic xpath selection" (xpath "./div") (xpath "./p") (xpath "./span")))))))) -(add-test "advanced xpath" +#_(add-test "advanced xpath" #(do (reset) (standard-fixture) (assert (= 2 (count (nodes (xpath "//p[following-sibling::p[@class='p3']]"))))))) @@ -140,7 +140,7 @@ add-test "basic xpath selection" (standard-fixture) (assert (= 1 (count (nodes (by-id "id1"))))))) -(add-test "look up node by id with context" +#_(add-test "look up node by id with context" #(do (reset) (append! (sel "body") "

some text

more text

") From 14ae284f3538a313c4b4882fbce26373d8759417 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Thu, 7 Nov 2013 14:28:31 +0100 Subject: [PATCH 20/30] completed xpath standard tests --- test/cljs/domina/xpath_standard_test.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/cljs/domina/xpath_standard_test.cljs b/test/cljs/domina/xpath_standard_test.cljs index fbae33f..8dc64cd 100644 --- a/test/cljs/domina/xpath_standard_test.cljs +++ b/test/cljs/domina/xpath_standard_test.cljs @@ -28,4 +28,5 @@ (count (nodes (-> (xpath "//body") (xpath "./div") (xpath "./p") - (xpath "./span"))))))))) + (xpath "./span"))))) + 2 (count (nodes (xpath "//p[following-sibling::p[@class='p3']]"))))))) From 6822cb3339501f1b24298f1b91b9b6f2f1df80a0 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Thu, 7 Nov 2013 15:07:15 +0100 Subject: [PATCH 21/30] comment prepend! test --- temp/test/cljs/domina/test.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/temp/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs index 050558c..9e8a63d 100644 --- a/temp/test/cljs/domina/test.cljs +++ b/temp/test/cljs/domina/test.cljs @@ -200,7 +200,7 @@ "some more text") (assert (= 3 (count (nodes (xpath "//div/p/span[@class='foo']"))))))) -(add-test "prepend a single child to a single parent" +#_(add-test "prepend a single child to a single parent" #(do (reset) (append! (xpath "//body") "
2
3
") (prepend! (xpath "//body") "
1
") From f5739d9a6884c610e1a4c95553cecb60f855396f Mon Sep 17 00:00:00 2001 From: magomimmo Date: Thu, 7 Nov 2013 15:07:41 +0100 Subject: [PATCH 22/30] add prepend! unit test --- test/cljs/domina_standard_test.cljs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/cljs/domina_standard_test.cljs b/test/cljs/domina_standard_test.cljs index 9b3ae44..e646283 100644 --- a/test/cljs/domina_standard_test.cljs +++ b/test/cljs/domina_standard_test.cljs @@ -13,7 +13,9 @@ destroy! destroy-children! children - insert-before!)] + insert-before! + prepend! + text)] [domina.fixtures :as fix :refer (base-fixture)] [domina.xpath :as xp :refer (xpath)] [hiccups.runtime :as hrt])) @@ -191,3 +193,16 @@ (+ (count (nodes (xpath "//div[@class='ref']"))) (count (nodes (xpath "//div[@id='ref1']/preceding-sibling::p"))) (count (nodes (xpath "//div[@id='ref2']/preceding-sibling::p")))))))))) + +;;; prepend! +(deftest prepend!-test + (testing "Unit Testing for (prepend! parents children)\n" + (testing "Standard Cases\n" + (testing "(prepend! single-parent single-child)" + (are [expected actual] (= expected actual) + 1 (do + (append! (xpath "//body") (hm/html [:div "2"] [:div "3"])) + (prepend! (xpath "//body") (hm/html [:div "1"])) + (count (+ (text (xpath "//body/div[1]")) + #_(text (xpath "//body/div[2]")) + #_(text (xpath "//body/div[3]")))))))))) From 528fac26fffe479440a172217f170d02c9955189 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Thu, 7 Nov 2013 19:01:30 +0100 Subject: [PATCH 23/30] update cljs.test to 0.2.0 --- profiles.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiles.clj b/profiles.clj index 620f335..80cb2d3 100644 --- a/profiles.clj +++ b/profiles.clj @@ -1,6 +1,6 @@ {:dev {:test-paths ["test/cljs"] :dependencies [[hiccups "0.2.0"]] - :plugins [[com.cemerick/clojurescript.test "0.1.0"]] + :plugins [[com.cemerick/clojurescript.test "0.2.0"]] :cljsbuild {:builds {:none {:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] From 52a516b0059973bb932c5618858bc3ef379b4657 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Thu, 7 Nov 2013 19:32:06 +0100 Subject: [PATCH 24/30] comment few more tests --- temp/test/cljs/domina/test.cljs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/temp/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs index 9e8a63d..48dc5e3 100644 --- a/temp/test/cljs/domina/test.cljs +++ b/temp/test/cljs/domina/test.cljs @@ -208,13 +208,13 @@ (assert (= "2" (text (xpath "//body/div[2]")))) (assert (= "3" (text (xpath "//body/div[3]")))))) -(add-test "prepend a single child to multiple parents" +#_(add-test "prepend a single child to multiple parents" #(do (reset) (append! (xpath "//body") "

2

2

") (prepend! (xpath "//body/div") "

1

") (assert (= 2 (count (nodes (xpath "//body/div/p[text()='2']"))))))) -(add-test "Insert a single child to a single parent" +#_(add-test "Insert a single child to a single parent" #(do (reset) (append! (xpath "//body") "
") @@ -316,20 +316,20 @@ (assert (= 1 (count (nodes (xpath "//div[@id='ref1']/preceding-sibling::p"))))) (assert (= 2 (count (nodes (xpath "//div[@id='ref2']/preceding-sibling::p"))))))) -(add-test "insert-after! with a single reference and single new node" +#_(add-test "insert-after! with a single reference and single new node" #(do (reset) (append! (xpath "//body") "
Some content
") (insert-after! (nodes (by-id "ref")) "

after

") (assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after']"))))))) -(add-test "insert-after! with a single reference and multiple new nodes" +#_(add-test "insert-after! with a single reference and multiple new nodes" #(do (reset) (append! (xpath "//body") "
Some content
") (insert-after! (nodes (by-id "ref")) "

after1

after2

") (assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after1' and position()=1]"))))) (assert (= 1 (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after2' and position()=2]"))))))) -(add-test "insert-after! with multiple reference nodes and a single new node" +#_(add-test "insert-after! with multiple reference nodes and a single new node" #(do (reset) (append! (xpath "//body") "
content1
") (append! (xpath "//body") "
content2
") From f830565c6520f817e55eb6051d29941f009c71c9 Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Thu, 7 Nov 2013 19:33:13 +0100 Subject: [PATCH 25/30] add more unit tests --- test/cljs/domina_standard_test.cljs | 74 ++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/test/cljs/domina_standard_test.cljs b/test/cljs/domina_standard_test.cljs index e646283..3eae743 100644 --- a/test/cljs/domina_standard_test.cljs +++ b/test/cljs/domina_standard_test.cljs @@ -14,7 +14,9 @@ destroy-children! children insert-before! + insert-after! prepend! + insert! text)] [domina.fixtures :as fix :refer (base-fixture)] [domina.xpath :as xp :refer (xpath)] @@ -160,7 +162,7 @@ (count (nodes (xpath "//div[@class='d1']/*"))))))))) ;;; insert-before! -(deftest insert_before!-test +(deftest insert-before!-test (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n" (testing "Standard Cases\n" (testing "(insert-before! single-ref-node single-node)" @@ -181,7 +183,7 @@ (count (nodes (xpath "//div[@id='ref']/preceding-sibling::*[text()='before1' and position()=2]")))))))))) ;;; insert-before! -(deftest insert_before!!-test +(deftest insert-before!!-test (testing "Unit Testing for (insert-before! ref-nodes new-nodes)\n" (testing "Standard Cases\n" (testing "(insert-before! multiple-ref-nodes single-node)" @@ -199,10 +201,68 @@ (testing "Unit Testing for (prepend! parents children)\n" (testing "Standard Cases\n" (testing "(prepend! single-parent single-child)" - (are [expected actual] (= expected actual) - 1 (do + (are [expected actual] (= expected actual) + "1" (do (append! (xpath "//body") (hm/html [:div "2"] [:div "3"])) (prepend! (xpath "//body") (hm/html [:div "1"])) - (count (+ (text (xpath "//body/div[1]")) - #_(text (xpath "//body/div[2]")) - #_(text (xpath "//body/div[3]")))))))))) + (text (xpath "//body/div[1]"))))) + (testing "(prepend! parents single-child)" + (are [expected actual] (= expected actual) + 2 (do (append! (xpath "//body") "

2

2

") + (prepend! (xpath "//body/div") "

1

") + (count (nodes (xpath "//body/div/p[text()='2']"))))))))) + +(deftest insert!-test + (testing "Unit Testing for (insert! parents children)\n" + (testing "Standard Cases\n" + (testing "(insert! parent child)" + (are [expected actual] (= expected actual) + 5 (do + (append! (xpath "//body") + (hm/html [:div.testInserts])) + (append! (xpath "//div[@class='testInserts']") + (hm/html [:p.i1])) + (append! (xpath "//div[@class='testInserts']") + (hm/html [:p.i3])) + (insert! (xpath "//div[@class='testInserts']") + (hm/html [:p.i2]) 1) + (+ (count (nodes (xpath "//div[@class='testInserts']/p"))) + (count (nodes (xpath "//p[@class='i2']/preceding-sibling::*"))) + (count (nodes (xpath "//p[@class='i2']/following-sibling::*"))))))) + (testing "(insert! parents single-child)" + (are [expected actual] (= expected actual) + true false))))) + + +(deftest insert-after!-test + (testing "Unit Testing for (insert-after! ref-nodes new-nodes)\n" + (testing "Standard Cases\n" + (testing "(insert-after! single-ref-node single-node)" + (are [expected actual] (= expected actual) + 1 (do + (append! (xpath "//body") + (hm/html [:div#ref "Some content"])) + (insert-after! (nodes (by-id "ref")) + (hm/html [:p "after"])) + (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after']")))))) + (testing "(insert-after! single-ref-node multiple-nodes)" + (are [expected actual] (= expected actual) + 2 (do + (append! (xpath "//body") + (hm/html [:div#ref "Some content"])) + (insert-after! (nodes (by-id "ref")) + (hm/html [:p "after1"] + [:p "after2"])) + (+ (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after1' and position()=1]"))) + (count (nodes (xpath "//div[@id='ref']/following-sibling::*[text()='after2' and position()=2]"))))))) + (testing "(insert-after! multiple-ref-node multiple-nodes)" + (are [expected actual] (= expected actual) + 3 (do + (append! (xpath "//body") + (hm/html [:div#ref1.ref "content1"])) + (append! (xpath "//body") + (hm/html [:div#ref2.ref "content2"])) + (insert-after! (nodes (by-class "ref")) + (hm/html [:p "after"])) + (+ (count (nodes (xpath "//div[@id='ref1']/following-sibling::p"))) + (count (nodes (xpath "//div[@id='ref2']/following-sibling::p")))))))))) From 3b13f9daba07e41198e219effea106930952ef9c Mon Sep 17 00:00:00 2001 From: magomimmo Date: Fri, 8 Nov 2013 00:32:22 +0100 Subject: [PATCH 26/30] comment other 3 tests --- temp/test/cljs/domina/test.cljs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/temp/test/cljs/domina/test.cljs b/temp/test/cljs/domina/test.cljs index 48dc5e3..f5bc46c 100644 --- a/temp/test/cljs/domina/test.cljs +++ b/temp/test/cljs/domina/test.cljs @@ -338,21 +338,21 @@ (assert (= 2 (count (nodes (xpath "//div[@id='ref1']/following-sibling::p"))))) (assert (= 1 (count (nodes (xpath "//div[@id='ref2']/following-sibling::p"))))))) -(add-test "swap-content! with a single reference node and a single new node" +#_(add-test "swap-content! with a single reference node and a single new node" #(do (reset) (append! (xpath "//body") "

TYPO

") (swap-content! (xpath "//p[@id='before']") "

fixed

") (assert (= 0 (count (nodes (xpath "//p[@id='before']"))))) (assert (= 1 (count (nodes (xpath "//p[@id='after']"))))))) -(add-test "swap-content! with a single reference node and multiple new nodes" +#_(add-test "swap-content! with a single reference node and multiple new nodes" #(do (reset) (append! (xpath "//body") "

TYPO

") (swap-content! (xpath "//p[@id='before']") "

fixed1

fixed2

") (assert (= 0 (count (nodes (xpath "//p[@id='before']"))))) (assert (= 2 (count (nodes (xpath "//p[@class='after']"))))))) -(add-test "swap-content! with multiple reference nodes and multiple new nodes" +#_(add-test "swap-content! with multiple reference nodes and multiple new nodes" #(do (reset) (append! (xpath "//body") "

TYPO-1

") (append! (xpath "//body") "

TYPO-2

") From 221f7200452c9d19b434460c7eb3496f8f29a8ad Mon Sep 17 00:00:00 2001 From: magomimmo Date: Fri, 8 Nov 2013 00:33:22 +0100 Subject: [PATCH 27/30] add other unit tests --- test/cljs/domina_standard_test.cljs | 48 +++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/test/cljs/domina_standard_test.cljs b/test/cljs/domina_standard_test.cljs index 3eae743..cae50d0 100644 --- a/test/cljs/domina_standard_test.cljs +++ b/test/cljs/domina_standard_test.cljs @@ -17,6 +17,7 @@ insert-after! prepend! insert! + swap-content! text)] [domina.fixtures :as fix :refer (base-fixture)] [domina.xpath :as xp :refer (xpath)] @@ -208,8 +209,13 @@ (text (xpath "//body/div[1]"))))) (testing "(prepend! parents single-child)" (are [expected actual] (= expected actual) - 2 (do (append! (xpath "//body") "

2

2

") - (prepend! (xpath "//body/div") "

1

") + 2 (do (append! (xpath "//body") + (hm/html [:div [:p "2"]] + [:div [:p "2"]]) + #_"

2

2

") + (prepend! (xpath "//body/div") + (hm/html [:p "1"]) + #_"

1

") (count (nodes (xpath "//body/div/p[text()='2']"))))))))) (deftest insert!-test @@ -233,7 +239,7 @@ (are [expected actual] (= expected actual) true false))))) - +;;; insert-after! (deftest insert-after!-test (testing "Unit Testing for (insert-after! ref-nodes new-nodes)\n" (testing "Standard Cases\n" @@ -266,3 +272,39 @@ (hm/html [:p "after"])) (+ (count (nodes (xpath "//div[@id='ref1']/following-sibling::p"))) (count (nodes (xpath "//div[@id='ref2']/following-sibling::p")))))))))) + +;;; swap-content! +(deftest swap-content!-test + (testing "Unit Testing for (swap-content! old-content new-content)\n" + (testing "Standard Cases\n" + (testing "(swap-content! single-old-node single-new-node)" + (are [expected actual] (= expected actual) + 1 (do + (append! (xpath "//body") + (hm/html [:div [:p#before "TYPO"]])) + (swap-content! (xpath "//p[@id='before']") + (hm/html [:p#after "fixed"])) + (+ (count (nodes (xpath "//p[@id='before']"))) + (count (nodes (xpath "//p[@id='after']"))))))) + (testing "(swap-content! single-ref-node multiple-new-node)" + (are [expected actual] (= expected actual) + 2 (do + (append! (xpath "//body") + (hm/html [:div [:p#before "TYPE"]])) + (swap-content! (xpath "//p[@id='before']") + (hm/html [:p.after "fixed1"] + [:p.after "fixed2"])) + (+ (count (nodes (xpath "//p[@id='before']"))) + (count (nodes (xpath "//p[@class='after']"))))))) + (testing "(swap-content! multiple-ref-nodes multiple-new-node)" + (are [expected actual] (= expected actual) + 4 (do + (append! (xpath "//body") + (hm/html [:div [:p.before1 "TYPO-1"]])) + (append! (xpath "//body") + (hm/html [:div [:p.before1"TYPO-2"]])) + (swap-content! (xpath "//p[@class='before1']") + (hm/html [:p.after1 "fixed1"] + [:p.after1 "fixed2"])) + (+ (count (nodes (xpath "//p[@class='before1']"))) + (count (nodes (xpath "//p[@class='after1']")))))))))) From 3fd5cebfa430f17eaada79c0a475590a9c43f541 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Fri, 8 Nov 2013 00:34:24 +0100 Subject: [PATCH 28/30] comment builds and tests to speedup round trip --- profiles.clj | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/profiles.clj b/profiles.clj index 80cb2d3..3fc4e59 100644 --- a/profiles.clj +++ b/profiles.clj @@ -13,14 +13,14 @@ :optimizations :whitespace :pretty-print true :output-to "dev-resources/public/js/whitespace.js"}} - :simple - {:source-paths ["src/cljs" "test/cljs"] - :compiler {:libs ["goog/dom/query.js"] - :optimizations :simple - :pretty-print true - :output-to "dev-resources/public/js/simple.js"}} - :advanced - {:source-paths ["src/cljs" "test/cljs"] + #_:simple + #_{:source-paths ["src/cljs" "test/cljs"] + :compiler {:libs ["goog/dom/query.js"] + :optimizations :simple + :pretty-print true + :output-to "dev-resources/public/js/simple.js"}} + #_:advanced + #_{:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :optimizations :advanced :pretty-print true @@ -28,8 +28,8 @@ :test-commands {"whitespace" ["phantomjs" :runner "dev-resources/public/js/whitespace.js"] - "simple" - ["phantomjs" :runner "dev-resources/public/js/simple.js"] + #_"simple" + #_["phantomjs" :runner "dev-resources/public/js/simple.js"] - "advanced" - ["phantomjs" :runner "dev-resources/public/js/advanced.js"]}}}} + #_"advanced" + #_["phantomjs" :runner "dev-resources/public/js/advanced.js"]}}}} From 80f0eb64835e26da117bcc75f66b46aa1f380fed Mon Sep 17 00:00:00 2001 From: Mimmmo Cosenza Date: Fri, 8 Nov 2013 15:19:32 +0100 Subject: [PATCH 29/30] commented out :none build and test to speedup lifecycle until the unit tests are completed --- profiles.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiles.clj b/profiles.clj index 3fc4e59..8d0b4e8 100644 --- a/profiles.clj +++ b/profiles.clj @@ -1,8 +1,8 @@ {:dev {:test-paths ["test/cljs"] :dependencies [[hiccups "0.2.0"]] :plugins [[com.cemerick/clojurescript.test "0.2.0"]] - :cljsbuild {:builds {:none - {:source-paths ["src/cljs" "test/cljs"] + :cljsbuild {:builds {#_:none + #_{:source-paths ["src/cljs" "test/cljs"] :compiler {:libs ["goog/dom/query.js"] :pretty-print true :optimizations :none From 7dfb5f5d3d17181e261f233d5f704cba8c705082 Mon Sep 17 00:00:00 2001 From: magomimmo Date: Sat, 9 Nov 2013 13:06:58 +0100 Subject: [PATCH 30/30] update cljs to r2030 --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 7df6ab0..74df297 100644 --- a/project.clj +++ b/project.clj @@ -2,7 +2,7 @@ :description "A DOM manipulation library for ClojureScript inspired by JQuery" :source-paths ["src/clj" "src/cljs"] :dependencies [[org.clojure/clojure "1.5.1"] - [org.clojure/clojurescript "0.0-2014"]] + [org.clojure/clojurescript "0.0-2030"]] :plugins [[lein-cljsbuild "1.0.0-alpha1"]] :hooks [leiningen.cljsbuild] :cljsbuild {:builds {:deploy