mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 06:02:32 -05:00
Add helpers for creating test tokens
This commit is contained in:
parent
0730ecef46
commit
71976ed7e9
1 changed files with 22 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
(ns token-tests.logic.token-actions-test
|
||||
(:require
|
||||
[app.common.test-helpers.ids-map :as thi]
|
||||
[app.common.test-helpers.compositions :as ctho]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
|
@ -12,20 +13,25 @@
|
|||
(t/use-fixtures :each
|
||||
{:before thp/reset-idmap!})
|
||||
|
||||
(defn add-token [state label params]
|
||||
(let [id (thi/new-id! label)
|
||||
token (assoc params :id id)]
|
||||
(update-in state [:data :tokens] assoc id token)))
|
||||
|
||||
(defn get-token [file label]
|
||||
(let [id (thi/id label)]
|
||||
(get-in file [:data :tokens id])))
|
||||
|
||||
(def radius-token
|
||||
{:id #uuid "91bf7f1f-fce2-482f-a423-c6b502705ff1"
|
||||
:value "12"
|
||||
{:value "12"
|
||||
:name "sm"
|
||||
:type :border-radius})
|
||||
|
||||
(def radius-ref-token
|
||||
{:id #uuid "4c2bf84d-3a98-47a2-8e3c-e7fb037a615c"
|
||||
:value "{sm} * 2"
|
||||
{:value "{sm} * 2"
|
||||
:name "md"
|
||||
:type :border-radius})
|
||||
|
||||
|
||||
(def test-tokens
|
||||
{(:id radius-token) radius-token
|
||||
(:id radius-ref-token) radius-ref-token})
|
||||
|
@ -36,7 +42,12 @@
|
|||
(ctho/add-rect :rect-1 {})
|
||||
(ctho/add-rect :rect-2 {})
|
||||
(ctho/add-rect :rect-3 {})
|
||||
(assoc-in [:data :tokens] test-tokens)))
|
||||
(add-token :token-1 {:value "12"
|
||||
:name "borderRadius.sm"
|
||||
:type :border-radius})
|
||||
(add-token :token-2 {:value "{borderRadius.sm} * 2"
|
||||
:name "borderRadius.md"
|
||||
:type :border-radius})))
|
||||
|
||||
(t/deftest test-apply-token
|
||||
(t/async
|
||||
|
@ -46,21 +57,22 @@
|
|||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(wtc/apply-token {:shape-ids [(:id rect-1)]
|
||||
:attributes #{:rx :ry}
|
||||
:token radius-token
|
||||
:token (get-token file :token-1)
|
||||
:on-update-shape wtc/update-shape-radius})
|
||||
;; Will override
|
||||
(wtc/apply-token {:shape-ids [(:id rect-1)]
|
||||
:attributes #{:rx :ry}
|
||||
:token radius-ref-token
|
||||
:token (get-token file :token-2)
|
||||
:on-update-shape wtc/update-shape-radius})]]
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-store new-state)
|
||||
token-2' (get-token file' :token-2)
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
(t/is (= (:rx (:applied-tokens rect-1')) (:id radius-ref-token)))
|
||||
(t/is (= (:ry (:applied-tokens rect-1')) (:id radius-ref-token)))
|
||||
(t/is (= (:rx (:applied-tokens rect-1')) (:id token-2')))
|
||||
(t/is (= (:ry (:applied-tokens rect-1')) (:id token-2')))
|
||||
(t/is (= (:rx rect-1') 24))
|
||||
(t/is (= (:ry rect-1') 24))))))))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue