mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 21:48:29 +02:00
Use :name as the token identifier [*]
[*] Using uuid as the token identiefier for :applied-tokens is not correct as we want to merge all sets together by their name, to get the final values.
This commit is contained in:
parent
d8621974c2
commit
252797183c
6 changed files with 82 additions and 73 deletions
|
@ -15,8 +15,8 @@
|
|||
(defn apply-token-to-shape [file shape-label token-label attributes]
|
||||
(let [first-page-id (get-in file [:data :pages 0])
|
||||
shape-id (thi/id shape-label)
|
||||
token-id (thi/id token-label)
|
||||
applied-attributes (wtt/attributes-map attributes token-id)]
|
||||
token (get-token file token-label)
|
||||
applied-attributes (wtt/attributes-map attributes token)]
|
||||
(update-in file [:data
|
||||
:pages-index first-page-id
|
||||
:objects shape-id
|
||||
|
|
|
@ -10,66 +10,68 @@
|
|||
[cljs.test :as t :include-macros true]))
|
||||
|
||||
(t/deftest remove-attributes-for-token-id
|
||||
(t/testing "removes attributes matching the `token-id`, keeps other attributes"
|
||||
(t/is (= {:ry :b}
|
||||
(wtt/remove-attributes-for-token-id
|
||||
#{:rx :ry} :a {:rx :a :ry :b})))))
|
||||
(t/testing "removes attributes matching the `token`, keeps other attributes"
|
||||
(t/is (= {:ry "b"}
|
||||
(wtt/remove-attributes-for-token #{:rx :ry} {:name "a"} {:rx "a" :ry "b"})))))
|
||||
|
||||
(t/deftest token-applied-test
|
||||
(t/testing "matches passed token with `:token-attributes`"
|
||||
(t/is (true? (wtt/token-applied? {:id :a} {:applied-tokens {:x :a}} #{:x}))))
|
||||
(t/is (true? (wtt/token-applied? {:name "a"} {:applied-tokens {:x "a"}} #{:x}))))
|
||||
(t/testing "doesn't match empty token"
|
||||
(t/is (nil? (wtt/token-applied? {} {:applied-tokens {:x :a}} #{:x}))))
|
||||
(t/is (nil? (wtt/token-applied? {} {:applied-tokens {:x "a"}} #{:x}))))
|
||||
(t/testing "does't match passed token `:id`"
|
||||
(t/is (nil? (wtt/token-applied? {:id :b} {:applied-tokens {:x :a}} #{:x}))))
|
||||
(t/is (nil? (wtt/token-applied? {:name "b"} {:applied-tokens {:x "a"}} #{:x}))))
|
||||
(t/testing "doesn't match passed `:token-attributes`"
|
||||
(t/is (nil? (wtt/token-applied? {:id :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 {:id :a}
|
||||
{:applied-tokens {:x :a :y :b}}
|
||||
(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}
|
||||
shape-applied-x {:id :shape-applied-x
|
||||
:applied-tokens {:x 1}}
|
||||
shape-applied-y {:id :shape-applied-y
|
||||
:applied-tokens {:y 1}}
|
||||
shape-applied-x-y {:id :shape-applied-x-y
|
||||
:applied-tokens {:x 1 :y 1}}
|
||||
shape-applied-none {:id :shape-applied-none
|
||||
shape-applied-x {:id "shape-applied-x"
|
||||
:applied-tokens {:x "1"}}
|
||||
shape-applied-y {:id "shape-applied-y"
|
||||
:applied-tokens {:y "1"}}
|
||||
shape-applied-x-y {:id "shape-applied-x-y"
|
||||
:applied-tokens {:x "1" :y "1"}}
|
||||
shape-applied-none {:id "shape-applied-none"
|
||||
:applied-tokens {}}
|
||||
shape-applied-all {:id :shape-applied-all
|
||||
:applied-tokens {:x 1 :y 1 :z 1}}
|
||||
ids-set (fn [& xs] (into #{} (map :id xs)))
|
||||
shape-applied-all {:id "shape-applied-all"
|
||||
:applied-tokens {:x "1" :y "1" :z "1"}}
|
||||
shape-ids (fn [& xs] (into #{} (map :id xs)))
|
||||
shapes [shape-applied-x
|
||||
shape-applied-y
|
||||
shape-applied-x-y
|
||||
shape-applied-all
|
||||
shape-applied-none]
|
||||
expected (wtt/shapes-ids-by-applied-attributes {:id 1} shapes attributes)]
|
||||
(t/is (= (:x expected) (ids-set shape-applied-x
|
||||
shape-applied-x-y
|
||||
shape-applied-all)))
|
||||
(t/is (= (:y expected) (ids-set shape-applied-y
|
||||
shape-applied-x-y
|
||||
shape-applied-all)))
|
||||
(t/is (= (:z expected) (ids-set shape-applied-all)))
|
||||
(t/is (true? (wtt/shapes-applied-all? expected (ids-set shape-applied-all) attributes)))
|
||||
(t/is (false? (wtt/shapes-applied-all? expected (apply ids-set shapes) attributes))))))
|
||||
expected (wtt/shapes-ids-by-applied-attributes {:name "1"} shapes attributes)]
|
||||
(t/is (= (:x expected) (shape-ids shape-applied-x
|
||||
shape-applied-x-y
|
||||
shape-applied-all)))
|
||||
(t/is (= (:y expected) (shape-ids shape-applied-y
|
||||
shape-applied-x-y
|
||||
shape-applied-all)))
|
||||
(t/is (= (:z expected) (shape-ids shape-applied-all)))
|
||||
(t/is (true? (wtt/shapes-applied-all? expected (shape-ids shape-applied-all) attributes)))
|
||||
(t/is (false? (wtt/shapes-applied-all? expected (apply shape-ids shapes) attributes)))
|
||||
(shape-ids shape-applied-x
|
||||
shape-applied-x-y
|
||||
shape-applied-all))))
|
||||
|
||||
(t/deftest tokens-applied-test
|
||||
(t/testing "is true when single shape matches the token and attributes"
|
||||
(t/is (true? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :a}}
|
||||
{:applied-tokens {:x :b}}]
|
||||
(t/is (true? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
|
||||
{:applied-tokens {:x "b"}}]
|
||||
#{:x}))))
|
||||
(t/testing "is false when no shape matches the token or attributes"
|
||||
(t/is (nil? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :b}}
|
||||
{:applied-tokens {:x :b}}]
|
||||
(t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "b"}}
|
||||
{:applied-tokens {:x "b"}}]
|
||||
#{:x})))
|
||||
(t/is (nil? (wtt/shapes-token-applied? {:id :a} [{:applied-tokens {:x :a}}
|
||||
{:applied-tokens {:x :a}}]
|
||||
(t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}}
|
||||
{:applied-tokens {:x "a"}}]
|
||||
#{:y})))))
|
||||
|
||||
(t/deftest name->path-test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue