Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit tests for "complex" defkeyframes forms #20

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions test/spade/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
composed-factory$
composed-list-factory$
composed-attrs-factory$
parameterized-key-frames-factory$)
parameterized-key-frames-factory$
complex-keyframes-factory$
multi-complex-keyframes-factory$)

(defclass computed-key [color]
^{:key (str/upper-case color)}
Expand Down Expand Up @@ -123,6 +125,29 @@
:opacity ::*from*}]
[:to {:opacity 1}])

(defkeyframes complex-keyframes [from]
(let [k (* 2 from)]
^{:key k}
; NOTE: This :& form is not *really* supported by garden's
; (at-keyframes) function, but it is a familiar syntax for
; the other def* forms, so let's make it work here so we can
; support complex forms with a shared computation.
[:&
[:from {::*from* from
:opacity ::*from*}]
[:to {:opacity 1}]]))

(defkeyframes multi-complex-keyframes [from]
(let [k (* 2 from)]
^{:key k}
; NOTE: This :& form is not *really* supported by garden's
; (at-keyframes) function, but it is a familiar syntax for
; the other def* forms, so let's make it work here so we can
; support complex forms with a shared computation.
[:from {::*from* from
:opacity ::*from*}])
[:to {:opacity 1}])

(deftest defkeyframes-test
(testing "Return keyframes name from defkeyframes"
(is (fn? key-frames))
Expand All @@ -134,6 +159,14 @@
(is (= (str "spade-core-test-parameterized-key-frames_" (hash [0]))
(parameterized-key-frames 0))))

(testing "Return dynamic name for complex defkeyframes"
(is (fn? complex-keyframes))
(is (fn? multi-complex-keyframes))
(is (= (str "spade-core-test-complex-keyframes_84")
(complex-keyframes 42)))
(is (= (str "spade-core-test-multi-complex-keyframes_84")
(multi-complex-keyframes 42))))

(testing "CSS var declaration and usage"
(let [generated (-> (parameterized-key-frames-factory$
"with-vars" [42])
Expand All @@ -147,7 +180,28 @@
" }")))
(is (str/includes?
generated
(str "to { opacity: 1; }"))))))
(str "to { opacity: 1; }")))))

(testing "CSS var declaration and usage within a block"
; NOTE: The styles generated should be identical to above
(let [generated (-> (complex-keyframes-factory$
"with-vars" [42])
:css
(str/replace #"\s+" " "))
multi-generated (-> (multi-complex-keyframes-factory$
"with-vars" [42])
:css
(str/replace #"\s+" " "))]
(is (str/includes?
generated
(str "from {"
" --spade-core-test--from: 42;"
" opacity: var(--spade-core-test--from);"
" }")))
(is (str/includes?
generated
(str "to { opacity: 1; }")))
(is (= generated multi-generated)))))

(defclass composed [color]
^{:key color}
Expand Down
Loading