From 31b5f5cefa957921524ada7857e2fdd2ee09545d Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Mon, 21 Oct 2024 16:36:47 +0200 Subject: [PATCH] :recycle: Format code --- frontend/src/app/main/data/tokens.cljs | 5 +- frontend/src/app/main/refs.cljs | 2 +- frontend/src/app/main/ui.cljs | 2 +- .../sidebar/options/menus/measures.cljs | 14 +- .../app/main/ui/workspace/tokens/changes.cljs | 34 +- .../ui/workspace/tokens/context_menu.cljs | 6 +- .../ui/workspace/tokens/modals/themes.cljs | 12 +- .../app/main/ui/workspace/tokens/sets.cljs | 2 +- .../workspace/tokens/sets_context_menu.cljs | 2 +- .../app/main/ui/workspace/tokens/token.cljs | 2 +- .../app/main/ui/workspace/tokens/update.cljs | 14 +- frontend/test/token_tests/helpers/tokens.cljs | 4 +- .../token_tests/logic/token_actions_test.cljs | 414 +++++++++--------- .../token_tests/style_dictionary_test.cljs | 6 +- frontend/test/token_tests/token_test.cljs | 10 +- 15 files changed, 266 insertions(+), 263 deletions(-) diff --git a/frontend/src/app/main/data/tokens.cljs b/frontend/src/app/main/data/tokens.cljs index b2f8c3bff..b657d0c66 100644 --- a/frontend/src/app/main/data/tokens.cljs +++ b/frontend/src/app/main/data/tokens.cljs @@ -259,8 +259,8 @@ (pcb/update-active-token-themes #{ctob/hidden-token-theme-path} #{})) add-to-hidden-theme? (let [prev-hidden-theme (ctob/get-theme tokens-lib ctob/hidden-token-theme-group ctob/hidden-token-theme-name)] - (-> base-changes - (pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme))) + (-> base-changes + (pcb/update-token-theme (ctob/toggle-set prev-hidden-theme ctob/hidden-token-theme-path) prev-hidden-theme))) :else base-changes)) ;; Either update or add token to existing set @@ -279,6 +279,7 @@ ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) + _ (prn "paso por aquĆ­") changes (-> (pcb/empty-changes it) (pcb/with-library-data data) (pcb/delete-token set-name token-name))] diff --git a/frontend/src/app/main/refs.cljs b/frontend/src/app/main/refs.cljs index e44e920e4..83aed63ed 100644 --- a/frontend/src/app/main/refs.cljs +++ b/frontend/src/app/main/refs.cljs @@ -501,7 +501,7 @@ (l/derived #(some-> (wtts/get-selected-token-set %) (ctob/get-token token-name)) - st/state))) + st/state))) (def workspace-selected-token-set-tokens (l/derived #(or (wtts/get-selected-token-set-tokens %) {}) st/state)) diff --git a/frontend/src/app/main/ui.cljs b/frontend/src/app/main/ui.cljs index 0bc7aa70a..81ebd5fbb 100644 --- a/frontend/src/app/main/ui.cljs +++ b/frontend/src/app/main/ui.cljs @@ -6,7 +6,6 @@ (ns app.main.ui (:require - [app.main.ui.workspace.tokens.modals.themes :as wtmt] [app.config :as cf] [app.main.refs :as refs] [app.main.ui.context :as ctx] @@ -20,6 +19,7 @@ [app.main.ui.onboarding.team-choice :refer [onboarding-team-modal]] [app.main.ui.releases :refer [release-notes-modal]] [app.main.ui.static :as static] + [app.main.ui.workspace.tokens.modals.themes :as wtmt] [app.util.dom :as dom] [app.util.i18n :refer [tr]] [rumext.v2 :as mf])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index 1aed9f173..0dc52d062 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -12,6 +12,7 @@ [app.common.logic.shapes :as cls] [app.common.types.shape.layout :as ctl] [app.common.types.shape.radius :as ctsr] + [app.common.types.tokens-lib :as ctob] [app.main.constants :refer [size-presets]] [app.main.data.tokens :as dt] [app.main.data.workspace :as udw] @@ -32,8 +33,7 @@ [app.util.dom :as dom] [app.util.i18n :as i18n :refer [tr]] [clojure.set :refer [rename-keys union]] - [rumext.v2 :as mf] - [app.common.types.tokens-lib :as ctob])) + [rumext.v2 :as mf])) (def measure-attrs [:proportion-lock @@ -248,11 +248,11 @@ (st/emit! (udw/trigger-bounding-box-cloaking ids) (dwu/start-undo-transaction undo-id) (dwsh/update-shapes ids - (if token-value - #(assoc-in % [:applied-tokens attr] (:id value)) - #(d/dissoc-in % [:applied-tokens attr])) - {:reg-objects? true - :attrs [:applied-tokens]}) + (if token-value + #(assoc-in % [:applied-tokens attr] (:id value)) + #(d/dissoc-in % [:applied-tokens attr])) + {:reg-objects? true + :attrs [:applied-tokens]}) (udw/update-dimensions ids attr (or token-value value)) (dwu/commit-undo-transaction undo-id))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/changes.cljs b/frontend/src/app/main/ui/workspace/tokens/changes.cljs index 0ddd8c830..5be2d4e73 100644 --- a/frontend/src/app/main/ui/workspace/tokens/changes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/changes.cljs @@ -91,11 +91,11 @@ (defn update-shape-radius-all [value shape-ids] (dwsh/update-shapes shape-ids - (fn [shape] - (when (ctsr/has-radius? shape) - (ctsr/set-radius-1 shape value))) - {:reg-objects? true - :attrs ctt/border-radius-keys})) + (fn [shape] + (when (ctsr/has-radius? shape) + (ctsr/set-radius-1 shape value))) + {:reg-objects? true + :attrs ctt/border-radius-keys})) (defn update-opacity [value shape-ids] (when (<= 0 value 1) @@ -111,22 +111,22 @@ (defn update-shape-radius-single-corner [value shape-ids attributes] (dwsh/update-shapes shape-ids - (fn [shape] - (when (ctsr/has-radius? shape) - (cond-> shape - (:rx shape) (ctsr/switch-to-radius-4) - :always (ctsr/set-radius-4 (first attributes) value)))) - {:reg-objects? true - :attrs [:rx :ry :r1 :r2 :r3 :r4]})) + (fn [shape] + (when (ctsr/has-radius? shape) + (cond-> shape + (:rx shape) (ctsr/switch-to-radius-4) + :always (ctsr/set-radius-4 (first attributes) value)))) + {:reg-objects? true + :attrs [:rx :ry :r1 :r2 :r3 :r4]})) (defn update-stroke-width [value shape-ids] (dwsh/update-shapes shape-ids - (fn [shape] - (when (seq (:strokes shape)) - (assoc-in shape [:strokes 0 :stroke-width] value))) - {:reg-objects? true - :attrs [:strokes]})) + (fn [shape] + (when (seq (:strokes shape)) + (assoc-in shape [:strokes 0 :stroke-width] value))) + {:reg-objects? true + :attrs [:strokes]})) (defn update-color [value shape-ids] diff --git a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs index a50218df7..bedd6c56f 100644 --- a/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/context_menu.cljs @@ -47,8 +47,8 @@ :selected? selected? :action (fn [] (if selected? - (st/emit! (wtch/unapply-token props)) - (st/emit! (wtch/apply-token (assoc props :on-update-shape on-update-shape-fn)))))})) + (st/emit! (wtch/unapply-token props)) + (st/emit! (wtch/apply-token (assoc props :on-update-shape on-update-shape-fn)))))})) attributes))) (defn all-or-sepearate-actions [{:keys [attribute-labels on-update-shape-all on-update-shape]} @@ -216,6 +216,8 @@ :y (.-clientY ^js event) :position :right :fields fields + :action "edit" + :selected-token-set-id selected-token-set-id :token token})))}])) (defn selection-actions [{:keys [type token] :as context-data}] diff --git a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs index f75bb4ba8..c70105df3 100644 --- a/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/modals/themes.cljs @@ -165,12 +165,12 @@ :on-change (comp on-update-group dom/get-target-val)} :render-right (when (seq theme-groups) (mf/fnc [] - [:button {:class (stl/css :group-drop-down-button) - :type "button" - :on-click (fn [e] - (dom/stop-propagation e) - (on-toggle-dropdown))} - i/arrow]))}]] + [:button {:class (stl/css :group-drop-down-button) + :type "button" + :on-click (fn [e] + (dom/stop-propagation e) + (on-toggle-dropdown))} + i/arrow]))}]] [:& labeled-input {:label "Theme" :input-props {:default-value (:name theme) :on-change (comp on-update-name dom/get-target-val)}}]] diff --git a/frontend/src/app/main/ui/workspace/tokens/sets.cljs b/frontend/src/app/main/ui/workspace/tokens/sets.cljs index 6ba57882b..7b7fd163b 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets.cljs @@ -7,10 +7,10 @@ (ns app.main.ui.workspace.tokens.sets (:require-macros [app.main.style :as stl]) (:require + [app.main.data.notifications :as ntf] [app.main.data.tokens :as wdt] [app.main.refs :as refs] [app.main.store :as st] - [app.main.data.notifications :as ntf] [app.main.ui.hooks :as h] [app.main.ui.icons :as i] [app.main.ui.workspace.tokens.sets-context :as sets-context] diff --git a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs index e82ba44c4..d034fe210 100644 --- a/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/sets_context_menu.cljs @@ -28,7 +28,7 @@ [:span {:class (stl/css :title)} title]]) (mf/defc menu - [{:keys [token-set-name]}] + [{:keys [token-set-name]}] (let [{:keys [on-edit]} (sets-context/use-context)] [:ul {:class (stl/css :context-list)} [:& menu-entry {:title "Rename" :on-click #(on-edit token-set-name)}] diff --git a/frontend/src/app/main/ui/workspace/tokens/token.cljs b/frontend/src/app/main/ui/workspace/tokens/token.cljs index 8783f4732..215f9ca51 100644 --- a/frontend/src/app/main/ui/workspace/tokens/token.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/token.cljs @@ -38,7 +38,7 @@ (and (attr? k) (= v (token-identifier token)))) applied-tokens) - (into {})))) + (into {})))) (defn token-attribute-applied? "Test if `token` is applied to a `shape` on single `token-attribute`." diff --git a/frontend/src/app/main/ui/workspace/tokens/update.cljs b/frontend/src/app/main/ui/workspace/tokens/update.cljs index 5f0b581a9..b4cfc047d 100644 --- a/frontend/src/app/main/ui/workspace/tokens/update.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/update.cljs @@ -32,10 +32,10 @@ ctt/rotation-keys wtch/update-rotation}) (def attribute-actions-map - (reduce - (fn [acc [ks action]] - (into acc (map (fn [k] [k action]) ks))) - {} attributes->shape-update)) + (reduce + (fn [acc [ks action]] + (into acc (map (fn [k] [k action]) ks))) + {} attributes->shape-update)) ;; Helpers --------------------------------------------------------------------- @@ -110,7 +110,7 @@ (fn [[v shape-ids]] (action v shape-ids attrs)) update-infos))) - shapes-update-info)) + shapes-update-info)) (defn update-tokens [resolved-tokens] (->> @refs/workspace-page-objects @@ -124,8 +124,8 @@ (->> (rx/from (-> - (wtts/get-active-theme-sets-tokens-names-map state) - (wtsd/resolve-tokens+ {:names-map? true}))) + (wtts/get-active-theme-sets-tokens-names-map state) + (wtsd/resolve-tokens+ {:names-map? true}))) (rx/mapcat (fn [sd-tokens] (let [undo-id (js/Symbol)] diff --git a/frontend/test/token_tests/helpers/tokens.cljs b/frontend/test/token_tests/helpers/tokens.cljs index 73cf124fc..4f510c002 100644 --- a/frontend/test/token_tests/helpers/tokens.cljs +++ b/frontend/test/token_tests/helpers/tokens.cljs @@ -1,8 +1,8 @@ (ns token-tests.helpers.tokens (:require [app.common.test-helpers.ids-map :as thi] - [app.main.ui.workspace.tokens.token :as wtt] - [app.common.types.tokens-lib :as ctob])) + [app.common.types.tokens-lib :as ctob] + [app.main.ui.workspace.tokens.token :as wtt])) (defn add-token [state label params] (let [id (thi/new-id! label) diff --git a/frontend/test/token_tests/logic/token_actions_test.cljs b/frontend/test/token_tests/logic/token_actions_test.cljs index 9c79dcb90..e3f215c03 100644 --- a/frontend/test/token_tests/logic/token_actions_test.cljs +++ b/frontend/test/token_tests/logic/token_actions_test.cljs @@ -49,205 +49,205 @@ (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)))))))))) + 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" (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.sm") - :on-update-shape wtch/update-shape-radius-all}) - (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)))))))))) + 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.sm") + :on-update-shape wtch/update-shape-radius-all}) + (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-token-overwrite (t/testing "removes old token attributes and applies only single attribute" (t/async - done - (let [file (setup-file-with-tokens) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [;; Apply "borderRadius.sm" to all border radius attributes - (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} - :token (toht/get-token file "borderRadius.sm") - :shape-ids [(:id rect-1)] - :on-update-shape wtch/update-shape-radius-all}) + done + (let [file (setup-file-with-tokens) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [;; Apply "borderRadius.sm" to all border radius attributes + (wtch/apply-token {:attributes #{:rx :ry :r1 :r2 :r3 :r4} + :token (toht/get-token file "borderRadius.sm") + :shape-ids [(:id rect-1)] + :on-update-shape wtch/update-shape-radius-all}) ;; Apply single `:r1` attribute to same shape ;; while removing other attributes from the border-radius set ;; but keep `:r4` for testing purposes - (wtch/apply-token {:attributes #{:r1} - :attributes-to-remove #{:rx :ry :r1 :r2 :r3} - :token (toht/get-token file "borderRadius.md") - :shape-ids [(:id rect-1)] - :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-sm (toht/get-token file' "borderRadius.sm") - token-md (toht/get-token file' "borderRadius.md") - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "other border-radius attributes got removed" - (t/is (nil? (:rx (:applied-tokens rect-1'))))) - (t/testing "r1 got applied with borderRadius.md" - (t/is (= (:r1 (:applied-tokens rect-1')) (:name token-md)))) - (t/testing "while :r4 was kept with borderRadius.sm" - (t/is (= (:r4 (:applied-tokens rect-1')) (:name token-sm))))))))))) + (wtch/apply-token {:attributes #{:r1} + :attributes-to-remove #{:rx :ry :r1 :r2 :r3} + :token (toht/get-token file "borderRadius.md") + :shape-ids [(:id rect-1)] + :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-sm (toht/get-token file' "borderRadius.sm") + token-md (toht/get-token file' "borderRadius.md") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "other border-radius attributes got removed" + (t/is (nil? (:rx (:applied-tokens rect-1'))))) + (t/testing "r1 got applied with borderRadius.md" + (t/is (= (:r1 (:applied-tokens rect-1')) (:name token-md)))) + (t/testing "while :r4 was kept with borderRadius.sm" + (t/is (= (:r4 (:applied-tokens rect-1')) (:name token-sm))))))))))) (t/deftest test-apply-dimensions (t/testing "applies dimensions token and updates the shapes width and height" (t/async - done - (let [dimensions-token {:name "dimensions.sm" - :value "100" - :type :dimensions} - file (-> (setup-file-with-tokens) - (update-in [:data :tokens-lib] - #(ctob/add-token-in-set % "Set A" (ctob/make-token dimensions-token)))) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:width :height} - :token (toht/get-token file "dimensions.sm") - :on-update-shape wtch/update-shape-dimensions})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' "dimensions.sm") - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) - (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) - (t/testing "shapes width and height got updated" - (t/is (= (:width rect-1') 100)) - (t/is (= (:height rect-1') 100)))))))))) + done + (let [dimensions-token {:name "dimensions.sm" + :value "100" + :type :dimensions} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token dimensions-token)))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:width :height} + :token (toht/get-token file "dimensions.sm") + :on-update-shape wtch/update-shape-dimensions})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "dimensions.sm") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) + (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) + (t/testing "shapes width and height got updated" + (t/is (= (:width rect-1') 100)) + (t/is (= (:height rect-1') 100)))))))))) (t/deftest test-apply-sizing (t/testing "applies sizing token and updates the shapes width and height" (t/async - done - (let [sizing-token {:name "sizing.sm" - :value "100" - :type :sizing} - file (-> (setup-file-with-tokens) - (update-in [:data :tokens-lib] - #(ctob/add-token-in-set % "Set A" (ctob/make-token sizing-token)))) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:width :height} - :token (toht/get-token file "sizing.sm") - :on-update-shape wtch/update-shape-dimensions})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' "sizing.sm") - rect-1' (cths/get-shape file' :rect-1)] - (t/testing "shape `:applied-tokens` got updated" - (t/is (some? (:applied-tokens rect-1'))) - (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) - (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) - (t/testing "shapes width and height got updated" - (t/is (= (:width rect-1') 100)) - (t/is (= (:height rect-1') 100)))))))))) + done + (let [sizing-token {:name "sizing.sm" + :value "100" + :type :sizing} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token sizing-token)))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:width :height} + :token (toht/get-token file "sizing.sm") + :on-update-shape wtch/update-shape-dimensions})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "sizing.sm") + rect-1' (cths/get-shape file' :rect-1)] + (t/testing "shape `:applied-tokens` got updated" + (t/is (some? (:applied-tokens rect-1'))) + (t/is (= (:width (:applied-tokens rect-1')) (:name token-target'))) + (t/is (= (:height (:applied-tokens rect-1')) (:name token-target')))) + (t/testing "shapes width and height got updated" + (t/is (= (:width rect-1') 100)) + (t/is (= (:height rect-1') 100)))))))))) (t/deftest test-apply-opacity (t/testing "applies opacity token and updates the shapes opacity" (t/async - done - (let [opacity-float {:name "opacity.float" - :value "0.3" - :type :opacity} - opacity-percent {:name "opacity.percent" - :value "40%" - :type :opacity} - opacity-invalid {:name "opacity.invalid" - :value "100" - :type :opacity} - file (-> (setup-file-with-tokens) - (update-in [:data :tokens-lib] - #(-> % - (ctob/add-token-in-set "Set A" (ctob/make-token opacity-float)) - (ctob/add-token-in-set "Set A" (ctob/make-token opacity-percent)) - (ctob/add-token-in-set "Set A" (ctob/make-token opacity-invalid))))) - store (ths/setup-store file) - rect-1 (cths/get-shape file :rect-1) - rect-2 (cths/get-shape file :rect-2) - rect-3 (cths/get-shape file :rect-3) - events [(wtch/apply-token {:shape-ids [(:id rect-1)] - :attributes #{:opacity} - :token (toht/get-token file "opacity.float") - :on-update-shape wtch/update-opacity}) - (wtch/apply-token {:shape-ids [(:id rect-2)] - :attributes #{:opacity} - :token (toht/get-token file "opacity.percent") - :on-update-shape wtch/update-opacity}) - (wtch/apply-token {:shape-ids [(:id rect-3)] - :attributes #{:opacity} - :token (toht/get-token file "opacity.invalid") - :on-update-shape wtch/update-opacity})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - rect-1' (cths/get-shape file' :rect-1) - rect-2' (cths/get-shape file' :rect-2) - rect-3' (cths/get-shape file' :rect-3) - token-opacity-float (toht/get-token file' "opacity.float") - token-opacity-percent (toht/get-token file' "opacity.percent") - token-opacity-invalid (toht/get-token file' "opacity.invalid")] - (t/testing "float value got translated to float and applied to opacity" - (t/is (= (:opacity (:applied-tokens rect-1')) (:name token-opacity-float))) - (t/is (= (:opacity rect-1') 0.3))) - (t/testing "percentage value got translated to float and applied to opacity" - (t/is (= (:opacity (:applied-tokens rect-2')) (:name token-opacity-percent))) - (t/is (= (:opacity rect-2') 0.4))) - (t/testing "invalid opacity value got applied but did not change shape" - (t/is (= (:opacity (:applied-tokens rect-3')) (:name token-opacity-invalid))) - (t/is (nil? (:opacity rect-3'))))))))))) + done + (let [opacity-float {:name "opacity.float" + :value "0.3" + :type :opacity} + opacity-percent {:name "opacity.percent" + :value "40%" + :type :opacity} + opacity-invalid {:name "opacity.invalid" + :value "100" + :type :opacity} + file (-> (setup-file-with-tokens) + (update-in [:data :tokens-lib] + #(-> % + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-float)) + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-percent)) + (ctob/add-token-in-set "Set A" (ctob/make-token opacity-invalid))))) + store (ths/setup-store file) + rect-1 (cths/get-shape file :rect-1) + rect-2 (cths/get-shape file :rect-2) + rect-3 (cths/get-shape file :rect-3) + events [(wtch/apply-token {:shape-ids [(:id rect-1)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.float") + :on-update-shape wtch/update-opacity}) + (wtch/apply-token {:shape-ids [(:id rect-2)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.percent") + :on-update-shape wtch/update-opacity}) + (wtch/apply-token {:shape-ids [(:id rect-3)] + :attributes #{:opacity} + :token (toht/get-token file "opacity.invalid") + :on-update-shape wtch/update-opacity})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + rect-1' (cths/get-shape file' :rect-1) + rect-2' (cths/get-shape file' :rect-2) + rect-3' (cths/get-shape file' :rect-3) + token-opacity-float (toht/get-token file' "opacity.float") + token-opacity-percent (toht/get-token file' "opacity.percent") + token-opacity-invalid (toht/get-token file' "opacity.invalid")] + (t/testing "float value got translated to float and applied to opacity" + (t/is (= (:opacity (:applied-tokens rect-1')) (:name token-opacity-float))) + (t/is (= (:opacity rect-1') 0.3))) + (t/testing "percentage value got translated to float and applied to opacity" + (t/is (= (:opacity (:applied-tokens rect-2')) (:name token-opacity-percent))) + (t/is (= (:opacity rect-2') 0.4))) + (t/testing "invalid opacity value got applied but did not change shape" + (t/is (= (:opacity (:applied-tokens rect-3')) (:name token-opacity-invalid))) + (t/is (nil? (:opacity rect-3'))))))))))) (t/deftest test-apply-rotation (t/testing "applies rotation token and updates the shapes rotation" @@ -278,37 +278,37 @@ (t/deftest test-apply-stroke-width (t/testing "applies stroke-width token and updates the shapes with stroke" (t/async - done - (let [stroke-width-token {:name "stroke-width.sm" - :value "10" - :type :stroke-width} - file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, - :stroke-style :solid, - :stroke-color "#000000", - :stroke-opacity 1, - :stroke-width 5}]}}) - (update-in [:data :tokens-lib] - #(ctob/add-token-in-set % "Set A" (ctob/make-token stroke-width-token)))) - store (ths/setup-store file) - rect-with-stroke (cths/get-shape file :rect-1) - rect-without-stroke (cths/get-shape file :rect-2) - events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] - :attributes #{:stroke-width} - :token (toht/get-token file "stroke-width.sm") - :on-update-shape wtch/update-stroke-width})]] - (tohs/run-store-async - store done events - (fn [new-state] - (let [file' (ths/get-file-from-store new-state) - token-target' (toht/get-token file' "stroke-width.sm") - rect-with-stroke' (cths/get-shape file' :rect-1) - rect-without-stroke' (cths/get-shape file' :rect-2)] - (t/testing "token got applied to rect with stroke and shape stroke got updated" - (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (:name token-target'))) - (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) - (t/testing "token got applied to rect without stroke but shape didnt get updated" - (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (:name token-target'))) - (t/is (empty? (:strokes rect-without-stroke'))))))))))) + done + (let [stroke-width-token {:name "stroke-width.sm" + :value "10" + :type :stroke-width} + file (-> (setup-file-with-tokens {:rect-1 {:strokes [{:stroke-alignment :inner, + :stroke-style :solid, + :stroke-color "#000000", + :stroke-opacity 1, + :stroke-width 5}]}}) + (update-in [:data :tokens-lib] + #(ctob/add-token-in-set % "Set A" (ctob/make-token stroke-width-token)))) + store (ths/setup-store file) + rect-with-stroke (cths/get-shape file :rect-1) + rect-without-stroke (cths/get-shape file :rect-2) + events [(wtch/apply-token {:shape-ids [(:id rect-with-stroke) (:id rect-without-stroke)] + :attributes #{:stroke-width} + :token (toht/get-token file "stroke-width.sm") + :on-update-shape wtch/update-stroke-width})]] + (tohs/run-store-async + store done events + (fn [new-state] + (let [file' (ths/get-file-from-store new-state) + token-target' (toht/get-token file' "stroke-width.sm") + rect-with-stroke' (cths/get-shape file' :rect-1) + rect-without-stroke' (cths/get-shape file' :rect-2)] + (t/testing "token got applied to rect with stroke and shape stroke got updated" + (t/is (= (:stroke-width (:applied-tokens rect-with-stroke')) (:name token-target'))) + (t/is (= (get-in rect-with-stroke' [:strokes 0 :stroke-width]) 10))) + (t/testing "token got applied to rect without stroke but shape didnt get updated" + (t/is (= (:stroke-width (:applied-tokens rect-without-stroke')) (:name token-target'))) + (t/is (empty? (:strokes rect-without-stroke'))))))))))) (t/deftest test-toggle-token-none (t/testing "should apply token to all selected items, where no item has the token applied" diff --git a/frontend/test/token_tests/style_dictionary_test.cljs b/frontend/test/token_tests/style_dictionary_test.cljs index 6ec097138..fa0093f47 100644 --- a/frontend/test/token_tests/style_dictionary_test.cljs +++ b/frontend/test/token_tests/style_dictionary_test.cljs @@ -1,10 +1,10 @@ (ns token-tests.style-dictionary-test (:require + [app.common.data :as d] [app.main.ui.workspace.tokens.style-dictionary :as sd] - [cljs.test :as t :include-macros true] - [promesa.core :as p] [app.main.ui.workspace.tokens.token :as wtt] - [app.common.data :as d])) + [cljs.test :as t :include-macros true] + [promesa.core :as p])) (def border-radius-token {:value "12px" diff --git a/frontend/test/token_tests/token_test.cljs b/frontend/test/token_tests/token_test.cljs index 2aca8fda2..309fed6e2 100644 --- a/frontend/test/token_tests/token_test.cljs +++ b/frontend/test/token_tests/token_test.cljs @@ -64,8 +64,8 @@ shape-applied-x-y shape-applied-all))) (t/is (= (:y expected) (shape-ids shape-applied-y - shape-applied-x-y - shape-applied-all))) + 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))) @@ -77,14 +77,14 @@ (t/testing "is true when single shape matches the token and attributes" (t/is (true? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}} {:applied-tokens {:x "b"}}] - #{:x})))) + #{:x})))) (t/testing "is false when no shape matches the token or attributes" (t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "b"}} {:applied-tokens {:x "b"}}] - #{:x}))) + #{:x}))) (t/is (nil? (wtt/shapes-token-applied? {:name "a"} [{:applied-tokens {:x "a"}} {:applied-tokens {:x "a"}}] - #{:y}))))) + #{:y}))))) (t/deftest name->path-test (t/is (= ["foo" "bar" "baz"] (wtt/token-name->path "foo.bar.baz")))