mirror of
https://github.com/penpot/penpot.git
synced 2026-04-04 18:32:29 +02:00
🐛 Normalize token set name on creating token-set instance
This commit is contained in:
@@ -327,11 +327,11 @@
|
||||
|
||||
If `relative-to` is provided, the normalized name will preserve the same group prefix as reference name."
|
||||
([name]
|
||||
(-> (split-set-name name)
|
||||
(-> (split-set-name (str name))
|
||||
(cpn/join-path :separator set-separator :with-spaces? false)))
|
||||
([name relative-to]
|
||||
(-> (concat (butlast (split-set-name relative-to))
|
||||
(split-set-name name))
|
||||
(split-set-name (str name)))
|
||||
(cpn/join-path :separator set-separator :with-spaces? false))))
|
||||
|
||||
(defn token-set?
|
||||
@@ -404,6 +404,7 @@
|
||||
(update :modified-at #(or % (ct/now)))
|
||||
(update :tokens #(into (d/ordered-map) %))
|
||||
(update :description d/nilv "")
|
||||
(update :name normalize-set-name)
|
||||
(check-token-set-attrs)
|
||||
(map->token-set)))
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#?(:clj [app.common.test-helpers.tokens :as tht])
|
||||
#?(:clj [clojure.datafy :refer [datafy]])
|
||||
[app.common.data :as d]
|
||||
[app.common.path-names :as cpn]
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.time :as ct]
|
||||
[app.common.transit :as tr]
|
||||
@@ -2034,3 +2033,31 @@
|
||||
(t/is (true? (ctob/token-name-path-exists? "border-radius.sm.x" {"border-radius" {:name "sm"}})))
|
||||
(t/is (false? (ctob/token-name-path-exists? "other" {"border-radius" {:name "sm"}})))
|
||||
(t/is (false? (ctob/token-name-path-exists? "dark.border-radius.md" {"dark" {"border-radius" {"sm" {:name "sm"}}}}))))
|
||||
|
||||
#?(:clj
|
||||
(t/deftest token-set-encode-decode-roundtrip-with-invalid-set-name
|
||||
(binding [ct/*clock* (ct/tick-millis-clock)]
|
||||
(let [tokens-lib
|
||||
(-> (ctob/make-tokens-lib)
|
||||
(ctob/add-set
|
||||
(ctob/map->token-set
|
||||
{:id (thi/new-id! :test-token-set)
|
||||
:name "foo / bar"
|
||||
:modified-at (ct/now)
|
||||
:description ""}))
|
||||
(ctob/add-token
|
||||
(thi/id :test-token-set)
|
||||
(ctob/make-token :name "test-token-1"
|
||||
:type :boolean
|
||||
:value true)))
|
||||
|
||||
encoded-tokens-lib
|
||||
(fres/encode tokens-lib)
|
||||
|
||||
decoded-tokens-lib
|
||||
(fres/decode encoded-tokens-lib)]
|
||||
|
||||
(let [tset-a (ctob/get-set tokens-lib (thi/id :test-token-set))
|
||||
tset-b (ctob/get-set decoded-tokens-lib (thi/id :test-token-set))]
|
||||
(t/is (= (ctob/get-name tset-a) "foo / bar"))
|
||||
(t/is (= (ctob/get-name tset-b) "foo/bar")))))))
|
||||
|
||||
Reference in New Issue
Block a user