summaryrefslogtreecommitdiff
path: root/test/dompa
diff options
context:
space:
mode:
Diffstat (limited to 'test/dompa')
-rw-r--r--test/dompa/coordinates_test.cljc30
-rw-r--r--test/dompa/html_test.cljc12
-rw-r--r--test/dompa/nodes_test.cljc91
3 files changed, 104 insertions, 29 deletions
diff --git a/test/dompa/coordinates_test.cljc b/test/dompa/coordinates_test.cljc
index 9b05826..9d145b0 100644
--- a/test/dompa/coordinates_test.cljc
+++ b/test/dompa/coordinates_test.cljc
@@ -1,8 +1,12 @@
(ns dompa.coordinates-test
- #?(:clj (:require [clojure.test :refer [deftest testing is]]
- [dompa.coordinates :as coordinates]))
- #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]]
- [dompa.coordinates :as coordinates])))
+ #?(:clj
+ (:require
+ [clojure.test :refer [deftest testing is]]
+ [dompa.coordinates :as coordinates]))
+ #?(:cljs
+ (:require
+ [cljs.test :refer-macros [deftest testing is]]
+ [dompa.coordinates :as coordinates])))
(deftest compose-test
(testing "Create coordinates"
@@ -107,7 +111,7 @@
coordinates/compose
coordinates/unify
coordinates/->nodes))))
-
+
(testing "Create nodes from self-closing tags"
(is (= [{:node/name :hr
:node/attrs {}}]
@@ -115,16 +119,16 @@
coordinates/compose
coordinates/unify
coordinates/->nodes))))
-
+
(testing "Parse attributes with forward slashes in them"
- (is (= [{:node/name :meta,
- :node/attrs {:name "route-pattern",
- :content "/:user_id/:repository",
+ (is (= [{:node/name :meta,
+ :node/attrs {:name "route-pattern",
+ :content "/:user_id/:repository",
:data-turbo-transient true}}]
- (-> "<meta name=\"route-pattern\" content=\"/:user_id/:repository\" data-turbo-transient>"
- coordinates/compose
- coordinates/unify
- coordinates/->nodes))))
+ (-> "<meta name=\"route-pattern\" content=\"/:user_id/:repository\" data-turbo-transient>"
+ coordinates/compose
+ coordinates/unify
+ coordinates/->nodes))))
(testing "Create nodes with attributes"
(is (= [{:node/name :div
diff --git a/test/dompa/html_test.cljc b/test/dompa/html_test.cljc
index 77107d1..5b620ba 100644
--- a/test/dompa/html_test.cljc
+++ b/test/dompa/html_test.cljc
@@ -1,8 +1,12 @@
(ns dompa.html-test
- #?(:clj (:require [clojure.test :refer [deftest is testing]]
- [dompa.html :as html]))
- #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]]
- [dompa.html :as html])))
+ #?(:clj
+ (:require
+ [clojure.test :refer [deftest is testing]]
+ [dompa.html :as html]))
+ #?(:cljs
+ (:require
+ [cljs.test :refer-macros [deftest testing is]]
+ [dompa.html :as html])))
(deftest coordinates-test
(testing "HTML to coordinates"
diff --git a/test/dompa/nodes_test.cljc b/test/dompa/nodes_test.cljc
index ca8d483..53e502a 100644
--- a/test/dompa/nodes_test.cljc
+++ b/test/dompa/nodes_test.cljc
@@ -1,13 +1,16 @@
(ns dompa.nodes-test
- #?(:clj (:require
- [clojure.test :refer [deftest is testing]]
- [clojure.zip :as zip]
- [dompa.html :as html]
- [dompa.nodes :as nodes :refer [$ defhtml]]))
- #?(:cljs (:require [cljs.test :refer-macros [deftest testing is]]
- [clojure.zip :as zip]
- [dompa.nodes :as nodes :refer [$] :refer-macros [defhtml]]
- [dompa.html :as html])))
+ #?(:clj
+ (:require
+ [clojure.test :refer [deftest is testing]]
+ [clojure.zip :as zip]
+ [dompa.html :as html]
+ [dompa.nodes :as nodes :refer [$ defhtml]]))
+ #?(:cljs
+ (:require
+ [cljs.test :refer-macros [deftest testing is]]
+ [clojure.zip :as zip]
+ [dompa.nodes :as nodes :refer [$] :refer-macros [defhtml]]
+ [dompa.html :as html])))
(defhtml hello [who]
($ :div
@@ -21,7 +24,7 @@
($ :ul
(->> items
(map (fn [item]
- ($ :li ($ item))))
+ ($ :li item)))
(into []))))
(deftest list-items-test
@@ -33,7 +36,7 @@
(is (= {:node/name :div
:node/children [{:node/name :dompa/text
:node/value "hello world"}]}
- ($ :div ($ "hello world")))))
+ ($ :div "hello world"))))
(testing "a fragment node"
(is (= {:node/name :<>
@@ -47,7 +50,71 @@
($ :span
($ "hello"))
($ :span
- ($ "world")))))))
+ ($ "world"))))))
+
+ (testing "a nil node"
+ (is (= nil
+ ($ nil))))
+
+ (testing "a string node"
+ (is (= {:node/name :dompa/text
+ :node/value "hello world"}
+ ($ "hello world"))))
+
+ (testing "a node of multiple sub-nodes"
+ (is (= {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "hello"}
+ {:node/name :dompa/text
+ :node/value "12345"}
+ {:node/name :dompa/text
+ :node/value "123.3"}
+ {:node/name :dompa/text
+ :node/value "world"}]}
+ ($ "hello" 12345 nil 123.3 "world")))
+
+ (is (= {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "hello"}
+ {:node/name :dompa/text
+ :node/value "12345"}
+ {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "w"}
+ {:node/name :dompa/text
+ :node/value "o"}
+ {:node/name :dompa/text
+ :node/value "r"}
+ {:node/name :dompa/text
+ :node/value "l"}
+ {:node/name :dompa/text
+ :node/value "d"}]}]}
+ ($ "hello" 12345 (map #($ %) ["w" "o" "r" "l" "d"]))))
+
+ (is (= {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "hello"}
+ {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "w"}
+ {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "o"}
+ {:node/name :dompa/text
+ :node/value "r"}
+ {:node/name :<>
+ :node/children [{:node/name :dompa/text
+ :node/value "l"}
+ {:node/name :dompa/text
+ :node/value "d"}]}]}]}]}
+ ($ "hello"
+ (map (fn [x]
+ ($ x))
+ ["w" (map (fn [x]
+ ($ x))
+ ["o" "r" (map (fn [x]
+ ($ x))
+ ["l" "d"])])]))))))
(deftest traverse-test
(let [traverser-fn (fn [node]