diff options
| author | Asko Nõmm <asko@repl.ee> | 2025-12-07 01:22:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-07 01:22:47 +0200 |
| commit | 46c90c3f3d9e5a3e0883e6e6305dbd958951ac47 (patch) | |
| tree | 6b3a5b79f64ecee3fea4e86a3c8e5a09de14c320 /test/dompa | |
| parent | d78abee5f9c6df199524487f226a1c5498a88ec4 (diff) | |
| parent | 4a242170a0dbc3df30ba56608a581ab1a9fcf61c (diff) | |
Merge pull request #12 from askonomm/11-improve-templating-ergonomics
Improve templating ergonomics (#11)
Diffstat (limited to 'test/dompa')
| -rw-r--r-- | test/dompa/coordinates_test.cljc | 30 | ||||
| -rw-r--r-- | test/dompa/html_test.cljc | 12 | ||||
| -rw-r--r-- | test/dompa/nodes_test.cljc | 91 |
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] |
