From 5825fa656bec830801d95f3d7563f0cb7f1f8d9d Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 1 Oct 2024 09:56:03 +0200 Subject: [PATCH] Fix tests --- .../token_tests/style_dictionary_test.cljs | 45 ++++++++++--------- frontend/test/token_tests/token_test.cljs | 4 -- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/frontend/test/token_tests/style_dictionary_test.cljs b/frontend/test/token_tests/style_dictionary_test.cljs index 638fa7e3c..07b407e13 100644 --- a/frontend/test/token_tests/style_dictionary_test.cljs +++ b/frontend/test/token_tests/style_dictionary_test.cljs @@ -3,39 +3,42 @@ [app.main.ui.workspace.tokens.style-dictionary :as sd] [cljs.test :as t :include-macros true] [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 - {:id #uuid "8c868278-7c8d-431b-bbc9-7d8f15c8edb9" - :value "12px" + {:value "12px" :name "borderRadius.sm" :type :border-radius}) (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" :type :border-radius}) -(def tokens {(:id border-radius-token) border-radius-token - (:id reference-border-radius-token) reference-border-radius-token}) - +(def tokens (d/ordered-map + (:name border-radius-token) border-radius-token + (:name reference-border-radius-token) reference-border-radius-token)) (t/deftest resolve-tokens-test (t/async done (t/testing "resolves tokens using style-dictionary from a ids map" (-> (sd/resolve-tokens+ tokens) - (p/finally (fn [resolved-tokens] - (let [expected-tokens {"borderRadius.sm" - (assoc border-radius-token - :resolved-value 12 - :resolved-unit "px") - "borderRadius.md-with-dashes" - (assoc reference-border-radius-token - :resolved-value 24 - :resolved-unit "px")}] - (t/is (= expected-tokens resolved-tokens)) - (done)))))))) + (p/finally + (fn [resolved-tokens] + (let [expected-tokens {"borderRadius.sm" + (assoc border-radius-token + :resolved-value 12 + :resolved-unit "px") + "borderRadius.md-with-dashes" + (assoc reference-border-radius-token + :resolved-value 24 + :resolved-unit "px")}] + (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/async @@ -48,10 +51,10 @@ (let [expected-tokens {"borderRadius.sm" (assoc border-radius-token :resolved-value 12 - :resolved-unit "px") + :unit "px") "borderRadius.md-with-dashes" (assoc reference-border-radius-token :resolved-value 24 - :resolved-unit "px")}] + :unit "px")}] (t/is (= expected-tokens resolved-tokens)) (done)))))))) diff --git a/frontend/test/token_tests/token_test.cljs b/frontend/test/token_tests/token_test.cljs index 4b38c889c..0dfaf675d 100644 --- a/frontend/test/token_tests/token_test.cljs +++ b/frontend/test/token_tests/token_test.cljs @@ -50,10 +50,6 @@ (t/testing "doesn't match passed `:token-attributes`" (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/testing "Returns set of matched attributes that fit the applied token" (let [attributes #{:x :y :z}