0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00
penpot/frontend/test/token_tests/style_dictionary_test.cljs

58 lines
2.5 KiB
Text
Raw Normal View History

2024-08-15 10:03:25 +02:00
(ns token-tests.style-dictionary-test
(:require
[app.main.ui.workspace.tokens.style-dictionary :as sd]
[cljs.test :as t :include-macros true]
2024-08-21 14:42:39 +02:00
[promesa.core :as p]
[app.main.ui.workspace.tokens.token :as wtt]))
2024-08-15 10:03:25 +02:00
(def border-radius-token
{:id #uuid "8c868278-7c8d-431b-bbc9-7d8f15c8edb9"
2024-08-15 10:07:12 +02:00
:value "12px"
2024-08-15 10:03:25 +02:00
:name "borderRadius.sm"
:type :border-radius})
(def reference-border-radius-token
{:id #uuid "b9448d78-fd5b-4e3d-aa32-445904063f5b"
: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})
(t/deftest resolve-tokens-test
(t/async
done
2024-08-22 10:59:40 +02:00
(t/testing "resolves tokens using style-dictionary from a ids map"
2024-08-15 10:03:25 +02:00
(-> (sd/resolve-tokens+ tokens)
(p/finally (fn [resolved-tokens]
(let [expected-tokens {"borderRadius.sm"
(assoc border-radius-token
:resolved-value 12
2024-08-15 10:07:12 +02:00
:resolved-unit "px")
2024-08-15 10:03:25 +02:00
"borderRadius.md-with-dashes"
(assoc reference-border-radius-token
:resolved-value 24
2024-08-15 10:07:12 +02:00
:resolved-unit "px")}]
2024-08-15 10:03:25 +02:00
(t/is (= expected-tokens resolved-tokens))
(done))))))))
2024-08-21 14:42:39 +02:00
2024-08-22 10:58:31 +02:00
(t/deftest resolve-tokens-names-map-test
2024-08-21 14:42:39 +02:00
(t/async
done
2024-08-22 10:59:40 +02:00
(t/testing "resolves tokens using style-dictionary from a names map"
2024-08-21 14:42:39 +02:00
(-> (vals tokens)
(wtt/token-names-map)
(sd/resolve-tokens+ {:names-map? true})
(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))))))))