0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 07:50:43 -05:00

Fix tests

This commit is contained in:
Florian Schroedl 2024-10-01 09:56:03 +02:00
parent 993df23624
commit 5825fa656b
2 changed files with 24 additions and 25 deletions

View file

@ -3,39 +3,42 @@
[app.main.ui.workspace.tokens.style-dictionary :as sd] [app.main.ui.workspace.tokens.style-dictionary :as sd]
[cljs.test :as t :include-macros true] [cljs.test :as t :include-macros true]
[promesa.core :as p] [promesa.core :as p]
[app.main.ui.workspace.tokens.token :as wtt])) [app.main.ui.workspace.tokens.token :as wtt]
[app.common.data :as d]))
(def border-radius-token (def border-radius-token
{:id #uuid "8c868278-7c8d-431b-bbc9-7d8f15c8edb9" {:value "12px"
:value "12px"
:name "borderRadius.sm" :name "borderRadius.sm"
:type :border-radius}) :type :border-radius})
(def reference-border-radius-token (def reference-border-radius-token
{:id #uuid "b9448d78-fd5b-4e3d-aa32-445904063f5b" {:value "{borderRadius.sm} * 2"
:value "{borderRadius.sm} * 2"
:name "borderRadius.md-with-dashes" :name "borderRadius.md-with-dashes"
:type :border-radius}) :type :border-radius})
(def tokens {(:id border-radius-token) border-radius-token (def tokens (d/ordered-map
(:id reference-border-radius-token) reference-border-radius-token}) (:name border-radius-token) border-radius-token
(:name reference-border-radius-token) reference-border-radius-token))
(t/deftest resolve-tokens-test (t/deftest resolve-tokens-test
(t/async (t/async
done done
(t/testing "resolves tokens using style-dictionary from a ids map" (t/testing "resolves tokens using style-dictionary from a ids map"
(-> (sd/resolve-tokens+ tokens) (-> (sd/resolve-tokens+ tokens)
(p/finally (fn [resolved-tokens] (p/finally
(let [expected-tokens {"borderRadius.sm" (fn [resolved-tokens]
(assoc border-radius-token (let [expected-tokens {"borderRadius.sm"
:resolved-value 12 (assoc border-radius-token
:resolved-unit "px") :resolved-value 12
"borderRadius.md-with-dashes" :resolved-unit "px")
(assoc reference-border-radius-token "borderRadius.md-with-dashes"
:resolved-value 24 (assoc reference-border-radius-token
:resolved-unit "px")}] :resolved-value 24
(t/is (= expected-tokens resolved-tokens)) :resolved-unit "px")}]
(done)))))))) (t/is (= 12 (get-in resolved-tokens ["borderRadius.sm" :resolved-value])))
(t/is (= "px" (get-in resolved-tokens ["borderRadius.sm" :unit])))
(t/is (= 24 (get-in resolved-tokens ["borderRadius.md-with-dashes" :resolved-value])))
(t/is (= "px" (get-in resolved-tokens ["borderRadius.md-with-dashes" :unit])))
(done))))))))
(t/deftest resolve-tokens-names-map-test (t/deftest resolve-tokens-names-map-test
(t/async (t/async
@ -48,10 +51,10 @@
(let [expected-tokens {"borderRadius.sm" (let [expected-tokens {"borderRadius.sm"
(assoc border-radius-token (assoc border-radius-token
:resolved-value 12 :resolved-value 12
:resolved-unit "px") :unit "px")
"borderRadius.md-with-dashes" "borderRadius.md-with-dashes"
(assoc reference-border-radius-token (assoc reference-border-radius-token
:resolved-value 24 :resolved-value 24
:resolved-unit "px")}] :unit "px")}]
(t/is (= expected-tokens resolved-tokens)) (t/is (= expected-tokens resolved-tokens))
(done)))))))) (done))))))))

View file

@ -50,10 +50,6 @@
(t/testing "doesn't match passed `:token-attributes`" (t/testing "doesn't match passed `:token-attributes`"
(t/is (nil? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:y}))))) (t/is (nil? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:y})))))
(t/deftest token-applied-attributes
(t/is (= #{:x} (wtt/token-applied-attributes {:name "a"}
{:applied-tokens {:x "a" :y "b"}}
#{:x :missing}))))
(t/deftest shapes-ids-by-applied-attributes (t/deftest shapes-ids-by-applied-attributes
(t/testing "Returns set of matched attributes that fit the applied token" (t/testing "Returns set of matched attributes that fit the applied token"
(let [attributes #{:x :y :z} (let [attributes #{:x :y :z}