mirror of
https://github.com/penpot/penpot.git
synced 2025-01-21 14:12:36 -05:00
Restore apply-tokens test
This commit is contained in:
parent
eceffda095
commit
1df40ea07a
3 changed files with 39 additions and 35 deletions
|
@ -1,5 +1,6 @@
|
||||||
(ns token-tests.helpers.state
|
(ns token-tests.helpers.state
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.types.tokens-lib :as ctob]
|
||||||
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
[app.main.ui.workspace.tokens.style-dictionary :as sd]
|
||||||
[beicon.v2.core :as rx]
|
[beicon.v2.core :as rx]
|
||||||
[potok.v2.core :as ptk]))
|
[potok.v2.core :as ptk]))
|
||||||
|
@ -21,11 +22,10 @@
|
||||||
(ptk/reify ::end+
|
(ptk/reify ::end+
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens])))
|
(->> (rx/from (-> (get-in state [:workspace-data :tokens-lib])
|
||||||
(rx/mapcat
|
(ctob/get-active-themes-set-tokens)
|
||||||
(fn [_]
|
(sd/resolve-tokens+ {:names-map? true})))
|
||||||
(rx/of
|
(rx/mapcat #(rx/of (end)))))))
|
||||||
(end))))))))
|
|
||||||
|
|
||||||
(defn stop-on
|
(defn stop-on
|
||||||
"Helper function to be used with async version of run-store.
|
"Helper function to be used with async version of run-store.
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(update-in state [:data :tokens] assoc id token)))
|
(update-in state [:data :tokens] assoc id token)))
|
||||||
|
|
||||||
(defn get-token [file name]
|
(defn get-token [file name]
|
||||||
(some-> (get-in file [:data :tokens-li])
|
(some-> (get-in file [:data :tokens-lib])
|
||||||
(ctob/get-active-themes-set-tokens)
|
(ctob/get-active-themes-set-tokens)
|
||||||
(get name)))
|
(get name)))
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
(ns token-tests.logic.token-actions-test
|
(ns token-tests.logic.token-actions-test
|
||||||
(:require
|
(:require
|
||||||
[token-tests.helpers.state :as tohs]
|
|
||||||
[app.common.logging :as log]
|
[app.common.logging :as log]
|
||||||
[app.common.test-helpers.compositions :as ctho]
|
[app.common.test-helpers.compositions :as ctho]
|
||||||
[app.main.ui.workspace.tokens.changes :as wtch]
|
|
||||||
[app.common.test-helpers.files :as cthf]
|
[app.common.test-helpers.files :as cthf]
|
||||||
[app.common.types.tokens-lib :as ctob]
|
|
||||||
[cljs.test :as t :include-macros true]
|
|
||||||
[app.common.test-helpers.shapes :as cths]
|
[app.common.test-helpers.shapes :as cths]
|
||||||
[frontend-tests.helpers.state :as ths]
|
[app.common.types.tokens-lib :as ctob]
|
||||||
|
[app.main.ui.workspace.tokens.changes :as wtch]
|
||||||
|
[cljs.pprint :as pprint]
|
||||||
|
[cljs.test :as t :include-macros true]
|
||||||
[frontend-tests.helpers.pages :as thp]
|
[frontend-tests.helpers.pages :as thp]
|
||||||
|
[frontend-tests.helpers.state :as ths]
|
||||||
|
[token-tests.helpers.state :as tohs]
|
||||||
[token-tests.helpers.tokens :as toht]))
|
[token-tests.helpers.tokens :as toht]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(t/use-fixtures :each
|
(t/use-fixtures :each
|
||||||
{:before (fn []
|
{:before (fn []
|
||||||
;; Ignore rxjs async errors
|
;; Ignore rxjs async errors
|
||||||
|
@ -40,34 +42,36 @@
|
||||||
(ctho/add-rect :rect-3 rect-3)
|
(ctho/add-rect :rect-3 rect-3)
|
||||||
(assoc-in [:data :tokens-lib]
|
(assoc-in [:data :tokens-lib]
|
||||||
(-> (ctob/make-tokens-lib)
|
(-> (ctob/make-tokens-lib)
|
||||||
|
(ctob/add-theme (ctob/make-token-theme :name "Theme A" :sets #{"Set A"}))
|
||||||
|
(ctob/set-active-themes #{"/Theme A"})
|
||||||
(ctob/add-set (ctob/make-token-set :name "Set A"))
|
(ctob/add-set (ctob/make-token-set :name "Set A"))
|
||||||
(ctob/add-token-in-set "Set A" (ctob/make-token border-radius-token))
|
(ctob/add-token-in-set "Set A" (ctob/make-token border-radius-token))
|
||||||
(ctob/add-token-in-set "Set A" (ctob/make-token reference-border-radius-token))))))
|
(ctob/add-token-in-set "Set A" (ctob/make-token reference-border-radius-token))))))
|
||||||
|
|
||||||
;; (t/deftest test-apply-token
|
(t/deftest test-apply-token
|
||||||
;; (t/testing "applies token to shape and updates shape attributes to resolved value"
|
(t/testing "applies token to shape and updates shape attributes to resolved value"
|
||||||
;; (t/async
|
(t/async
|
||||||
;; done
|
done
|
||||||
;; (let [file (setup-file-with-tokens)
|
(let [file (setup-file-with-tokens)
|
||||||
;; store (ths/setup-store file)
|
store (ths/setup-store file)
|
||||||
;; rect-1 (cths/get-shape file :rect-1)
|
rect-1 (cths/get-shape file :rect-1)
|
||||||
;; events [(wtch/apply-token {:shape-ids [(:id rect-1)]
|
events [(wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||||
;; :attributes #{:rx :ry}
|
:attributes #{:rx :ry}
|
||||||
;; :token (toht/get-token file :token-2)
|
:token (toht/get-token file "borderRadius.md")
|
||||||
;; :on-update-shape wtch/update-shape-radius-all})]]
|
:on-update-shape wtch/update-shape-radius-all})]]
|
||||||
;; (tohs/run-store-async
|
(tohs/run-store-async
|
||||||
;; store done events
|
store done events
|
||||||
;; (fn [new-state]
|
(fn [new-state]
|
||||||
;; (let [file' (ths/get-file-from-store new-state)
|
(let [file' (ths/get-file-from-store new-state)
|
||||||
;; token-2' (toht/get-token file' :token-2)
|
token (toht/get-token file' "borderRadius.md")
|
||||||
;; rect-1' (cths/get-shape file' :rect-1)]
|
rect-1' (cths/get-shape file' :rect-1)]
|
||||||
;; (t/testing "shape `:applied-tokens` got updated"
|
(t/testing "shape `:applied-tokens` got updated"
|
||||||
;; (t/is (some? (:applied-tokens rect-1')))
|
(t/is (some? (:applied-tokens rect-1')))
|
||||||
;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2')))
|
(t/is (= (:rx (:applied-tokens rect-1')) (:name token)))
|
||||||
;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2'))))
|
(t/is (= (:ry (:applied-tokens rect-1')) (:name token))))
|
||||||
;; (t/testing "shape radius got update to the resolved token value."
|
(t/testing "shape radius got update to the resolved token value."
|
||||||
;; (t/is (= (:rx rect-1') 24))
|
(t/is (= (:rx rect-1') 24))
|
||||||
;; (t/is (= (:ry rect-1') 24))))))))))
|
(t/is (= (:ry rect-1') 24))))))))))
|
||||||
|
|
||||||
;; (t/deftest test-apply-multiple-tokens
|
;; (t/deftest test-apply-multiple-tokens
|
||||||
;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values"
|
;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values"
|
||||||
|
|
Loading…
Add table
Reference in a new issue