0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-20 13:42:59 -05:00

Fix encoding/decoding tests

This commit is contained in:
Andrey Fedorov 2024-12-10 12:01:40 +01:00
parent d0ad149e20
commit 7e8de9aa24
3 changed files with 34 additions and 17 deletions

View file

@ -888,16 +888,16 @@ When `before-set-name` is nil, move set to bottom")
(comp
(filter (partial instance? TokenTheme))
(map (fn [token-theme]
(into {} token-theme))))
(->> token-theme
(into {})
walk/stringify-keys))))
(tree-seq d/ordered-map? vals themes))
themes-set-names (apply clojure.set/union (map :sets themes))
sets (into {} (comp
(filter #(and (instance? TokenSet %)
(contains? themes-set-names (:name %))))
(filter (partial instance? TokenSet))
(map (fn [token-set]
[(:name token-set) (get-dtcg-tokens-tree token-set)])))
(tree-seq d/ordered-map? vals sets))]
(assoc sets :$themes themes)))
(assoc sets "$themes" themes)))
(decode-dtcg-json [_ parsed-json]
(let [;; tokens-studio/plugin will add these meta properties, remove them for now
@ -911,12 +911,7 @@ When `before-set-name` is nil, move set to bottom")
:tokens (flatten-nested-tokens-json tokens ""))))
lib sets-data)]
(reduce
(fn [lib {:strs [name
group
description
is-source
modified-at
sets]}]
(fn [lib {:strs [name group description is-source modified-at sets]}]
(add-theme lib (TokenTheme. name
group
description

View file

@ -796,7 +796,14 @@
}
}
},
"$themes": [],
"$themes": [ {
"name": "theme-1",
"group": "group-1",
"description": null,
"is-source": false,
"modified-at": "2024-01-01T00:00:00.000+00:00",
"sets": [ "light" ]
} ],
"$metadata": {
"tokenSetOrder": ["core", "light", "dark", "theme"]
}

View file

@ -1058,8 +1058,13 @@
get-set-token (fn [set-name token-name]
(some-> (ctob/get-set lib set-name)
(ctob/get-token token-name)
(dissoc :modified-at)))]
(dissoc :modified-at)))
token-theme (ctob/get-theme lib "group-1" "theme-1")]
(t/is (= '("core" "light" "dark" "theme") (ctob/get-ordered-set-names lib)))
(t/testing "set exists in theme"
(t/is (= (:group token-theme) "group-1"))
(t/is (= (:name token-theme) "theme-1"))
(t/is (= (:sets token-theme) #{"light"})))
(t/testing "tokens exist in core set"
(t/is (= (get-set-token "core" "colors.red.600")
{:name "colors.red.600"
@ -1080,7 +1085,8 @@
(t/is (nil? (get-set-token "typography" "H1.Bold"))))))
(t/testing "encode-dtcg-json"
(let [tokens-lib (-> (ctob/make-tokens-lib)
(let [now (dt/now)
tokens-lib (-> (ctob/make-tokens-lib)
(ctob/add-set (ctob/make-token-set :name "core"
:tokens {"colors.red.600"
(ctob/make-token
@ -1097,9 +1103,19 @@
(ctob/make-token
{:name "button.primary.background"
:type :color
:value "{accent.default}"})})))
:value "{accent.default}"})}))
(ctob/add-theme (ctob/make-token-theme :name "theme-1"
:group "group-1"
:modified-at now
:sets #{"core"})))
expected (ctob/encode-dtcg tokens-lib)]
(t/is (= {"core"
(t/is (= {"$themes" [{"description" nil
"group" "group-1"
"is-source" false
"modified-at" now
"name" "theme-1"
"sets" #{"core"}}]
"core"
{"colors" {"red" {"600" {"$value" "#e53e3e"
"$type" "color"}}}
"spacing"
@ -1140,4 +1156,3 @@
(t/is (= @with-prev-tokens-lib @tokens-lib)))
(t/testing "fresh tokens library is also equal"
(= @with-empty-tokens-lib @tokens-lib)))))))