diff --git a/frontend/test/token_tests/helpers/state.cljs b/frontend/test/token_tests/helpers/state.cljs index 283c3125f..789de7049 100644 --- a/frontend/test/token_tests/helpers/state.cljs +++ b/frontend/test/token_tests/helpers/state.cljs @@ -1,5 +1,6 @@ (ns token-tests.helpers.state (:require + [app.common.types.tokens-lib :as ctob] [app.main.ui.workspace.tokens.style-dictionary :as sd] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -21,11 +22,10 @@ (ptk/reify ::end+ ptk/WatchEvent (watch [_ state _] - (->> (rx/from (sd/resolve-tokens+ (get-in state [:workspace-data :tokens]))) - (rx/mapcat - (fn [_] - (rx/of - (end)))))))) + (->> (rx/from (-> (get-in state [:workspace-data :tokens-lib]) + (ctob/get-active-themes-set-tokens) + (sd/resolve-tokens+ {:names-map? true}))) + (rx/mapcat #(rx/of (end))))))) (defn stop-on "Helper function to be used with async version of run-store. diff --git a/frontend/test/token_tests/helpers/tokens.cljs b/frontend/test/token_tests/helpers/tokens.cljs index df222f83a..73cf124fc 100644 --- a/frontend/test/token_tests/helpers/tokens.cljs +++ b/frontend/test/token_tests/helpers/tokens.cljs @@ -10,7 +10,7 @@ (update-in state [:data :tokens] assoc id token))) (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) (get name))) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 140cbd318..5f0f22f04 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -1,18 +1,20 @@ (ns token-tests.logic.token-actions-test (:require - [token-tests.helpers.state :as tohs] [app.common.logging :as log] [app.common.test-helpers.compositions :as ctho] - [app.main.ui.workspace.tokens.changes :as wtch] [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] - [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.state :as ths] + [token-tests.helpers.state :as tohs] [token-tests.helpers.tokens :as toht])) + (t/use-fixtures :each {:before (fn [] ;; Ignore rxjs async errors @@ -40,34 +42,36 @@ (ctho/add-rect :rect-3 rect-3) (assoc-in [:data :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-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)))))) -;; (t/deftest test-apply-token -;; (t/testing "applies token to shape and updates shape attributes to resolved value" -;; (t/async -;; done -;; (let [file (setup-file-with-tokens) -;; store (ths/setup-store file) -;; rect-1 (cths/get-shape file :rect-1) -;; events [(wtch/apply-token {:shape-ids [(:id rect-1)] -;; :attributes #{:rx :ry} -;; :token (toht/get-token file :token-2) -;; :on-update-shape wtch/update-shape-radius-all})]] -;; (tohs/run-store-async -;; store done events -;; (fn [new-state] -;; (let [file' (ths/get-file-from-store new-state) -;; token-2' (toht/get-token file' :token-2) -;; rect-1' (cths/get-shape file' :rect-1)] -;; (t/testing "shape `:applied-tokens` got updated" -;; (t/is (some? (:applied-tokens rect-1'))) -;; (t/is (= (:rx (:applied-tokens rect-1')) (wtt/token-identifier token-2'))) -;; (t/is (= (:ry (:applied-tokens rect-1')) (wtt/token-identifier token-2')))) -;; (t/testing "shape radius got update to the resolved token value." -;; (t/is (= (:rx rect-1') 24)) -;; (t/is (= (:ry rect-1') 24)))))))))) +(t/deftest test-apply-token + (t/testing "applies token to shape and updates shape attributes to resolved value" + (t/async + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:rx :ry} + :token (toht/get-token file "borderRadius.md") + :on-update-shape wtch/update-shape-radius-all})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:rx (:applied-tokens rect-1')) (:name token))) + (t/is (= (:ry (:applied-tokens rect-1')) (:name token)))) + (t/testing "shape radius got update to the resolved token value." + (t/is (= (:rx rect-1') 24)) + (t/is (= (:ry rect-1') 24)))))))))) ;; (t/deftest test-apply-multiple-tokens ;; (t/testing "applying a token twice with the same attributes will override the previously applied tokens values"