mirror of
https://github.com/penpot/penpot.git
synced 2025-01-04 13:50:12 -05:00
WIP
This commit is contained in:
parent
1d8c33d2c5
commit
0fe695530c
7 changed files with 343 additions and 344 deletions
|
@ -28,10 +28,12 @@
|
|||
(r/map->Match data))
|
||||
|
||||
(defn resolve
|
||||
([router id] (resolve router id {}))
|
||||
([router id]
|
||||
(resolve router id {}))
|
||||
([router id params]
|
||||
(when-let [match (r/match-by-name router id)]
|
||||
(r/match->path match params))))
|
||||
(when (some? router)
|
||||
(when-let [match (r/match-by-name router id)]
|
||||
(r/match->path match params)))))
|
||||
|
||||
(defn create
|
||||
[routes]
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
(defn locate-page
|
||||
[file-id id]
|
||||
(assert (uuid? id) "Page not valid uuid")
|
||||
(-> (dsh/lookup-file @st/state file-id)
|
||||
(-> (dsh/lookup-file-data @st/state file-id)
|
||||
(dsh/get-page id)))
|
||||
|
||||
(defn locate-objects
|
||||
|
@ -91,7 +91,7 @@
|
|||
[proxy]
|
||||
(let [file-id (obj/get proxy "$file")
|
||||
page-id (obj/get proxy "$page")
|
||||
id (obj/get proxy "$id")]
|
||||
id (obj/get proxy "$id")]
|
||||
(when (and (some? file-id) (some? page-id) (some? id))
|
||||
(locate-shape file-id page-id id))))
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
[state]
|
||||
(let [page-id (:current-page-id state)
|
||||
file-id (:current-file-id state)]
|
||||
(get-in state [:files file-id :pages-index page-id])))
|
||||
(get-in state [:files file-id :data :pages-index page-id])))
|
||||
|
||||
(defn id
|
||||
[label]
|
||||
|
|
|
@ -126,25 +126,26 @@
|
|||
(not (:component-root %))))
|
||||
(map :id))]
|
||||
(concat
|
||||
(apply concat (mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids))
|
||||
(apply concat (mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids)))))
|
||||
(apply concat
|
||||
(mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids))
|
||||
(apply concat
|
||||
(mapv #(copy-paste-shape % file :target-page-label target-page-label :target-container-id uuid/zero) frame-1-instance-ids)))))
|
||||
|
||||
(t/deftest main-and-first-level-copy-1
|
||||
(t/async
|
||||
done
|
||||
(t/async done
|
||||
(with-redefs [uuid/next cthi/next-uuid]
|
||||
(let [;; ==== Setup
|
||||
file (setup-file)
|
||||
store (ths/setup-store file)
|
||||
;; ==== Action
|
||||
;; ==== Action
|
||||
|
||||
|
||||
;; For each main and first level copy:
|
||||
;; - Duplicate it two times with copy-paste.
|
||||
;; For each main and first level copy:
|
||||
;; - Duplicate it two times with copy-paste.
|
||||
events
|
||||
(concat
|
||||
(duplicate-each-main-and-first-level-copy file)
|
||||
;; - Change color of Simple1
|
||||
;; - Change color of Simple1
|
||||
(set-color-bottom-shape :frame-simple-1 file {:color "#111111"}))]
|
||||
|
||||
(ths/run-store
|
||||
|
@ -365,8 +366,7 @@
|
|||
|
||||
|
||||
(t/deftest copy-nested-3
|
||||
(t/async
|
||||
done
|
||||
(t/async done
|
||||
(with-redefs [uuid/next cthi/next-uuid]
|
||||
(let [;; ==== Setup
|
||||
file (setup-file)
|
||||
|
@ -393,4 +393,4 @@
|
|||
;; Check that it's NOT PROPAGATED.
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#111111") 10))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#222222") 4))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 0)))))))))
|
||||
(t/is (= (count-shapes file' "rect-simple-1" "#333333") 0)))))))))
|
||||
|
|
|
@ -18,7 +18,9 @@
|
|||
|
||||
(t/deftest test-common-shape-properties
|
||||
(let [;; ==== Setup
|
||||
store (ths/setup-store (cthf/sample-file :file1 :page-label :page1))
|
||||
store (ths/setup-store
|
||||
(cthf/sample-file :file1 :page-label :page1))
|
||||
|
||||
_ (set! st/state store)
|
||||
context (api/create-context "TEST")
|
||||
|
||||
|
@ -27,7 +29,7 @@
|
|||
^js shape (.createRectangle context)
|
||||
|
||||
get-shape-path
|
||||
#(vector :files (aget file "$id") :pages-index (aget page "$id") :objects (aget shape "$id") %)]
|
||||
#(vector :files (aget file "$id") :data :pages-index (aget page "$id") :objects (aget shape "$id") %)]
|
||||
|
||||
(t/testing "Basic shape properites"
|
||||
(t/testing " - name"
|
||||
|
@ -251,4 +253,3 @@
|
|||
|
||||
(t/testing "Clone")
|
||||
(t/testing "Remove")))
|
||||
|
||||
|
|
|
@ -26,19 +26,17 @@
|
|||
(defn init
|
||||
[]
|
||||
(t/run-tests
|
||||
;; 'frontend-tests.helpers-shapes-test
|
||||
;; 'frontend-tests.logic.comp-remove-swap-slots-test
|
||||
;; 'frontend-tests.logic.copying-and-duplicating-test
|
||||
;; 'frontend-tests.logic.frame-guides-test
|
||||
;; 'frontend-tests.logic.groups-test
|
||||
;; 'frontend-tests.plugins.context-shapes-test
|
||||
;; 'frontend-tests.util-range-tree-test
|
||||
;; 'frontend-tests.util-snap-data-test
|
||||
;; 'frontend-tests.util-simple-math-test
|
||||
;; 'frontend-tests.basic-shapes-test
|
||||
'frontend-tests.helpers-shapes-test
|
||||
'frontend-tests.logic.comp-remove-swap-slots-test
|
||||
'frontend-tests.logic.copying-and-duplicating-test
|
||||
'frontend-tests.logic.frame-guides-test
|
||||
'frontend-tests.logic.groups-test
|
||||
'frontend-tests.plugins.context-shapes-test
|
||||
'frontend-tests.util-range-tree-test
|
||||
'frontend-tests.util-snap-data-test
|
||||
'frontend-tests.util-simple-math-test
|
||||
'frontend-tests.basic-shapes-test
|
||||
'frontend-tests.tokens.logic.token-actions-test
|
||||
|
||||
;; 'frontend-tests.tokens.style-dictionary-test
|
||||
;; 'frontend-tests.tokens.token-test
|
||||
;; 'frontend-tests.tokens.token-form-test
|
||||
))
|
||||
'frontend-tests.tokens.style-dictionary-test
|
||||
'frontend-tests.tokens.token-test
|
||||
'frontend-tests.tokens.token-form-test))
|
||||
|
|
|
@ -59,334 +59,332 @@
|
|||
token (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
|
||||
(app.common.pprint/pprint rect-1')
|
||||
|
||||
(t/testing "shape `:applied-tokens` got updated"
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
(t/is (= (:r1 (:applied-tokens rect-1')) (:name token))))
|
||||
|
||||
#_(t/testing "shape radius got update to the resolved token value."
|
||||
(t/is (= (:r1 rect-1') 24))))))))))
|
||||
(t/testing "shape radius got update to the resolved token value."
|
||||
(t/is (= (:r1 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 #{:r1 :r2 :r3 :r4}
|
||||
;; :token (toht/get-token file "borderRadius.sm")
|
||||
;; :on-update-shape wtch/update-shape-radius-all})
|
||||
;; (wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||
;; :attributes #{:r1 :r2 :r3 :r4}
|
||||
;; :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-state 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 (= (:r1 (:applied-tokens rect-1')) (:name token))))
|
||||
;; (t/testing "shape radius got update to the resolved token value."
|
||||
;; (t/is (= (:r1 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 #{:r1 :r2 :r3 :r4}
|
||||
:token (toht/get-token file "borderRadius.sm")
|
||||
:on-update-shape wtch/update-shape-radius-all})
|
||||
(wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||
:attributes #{:r1 :r2 :r3 :r4}
|
||||
: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-state 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 (= (:r1 (:applied-tokens rect-1')) (:name token))))
|
||||
(t/testing "shape radius got update to the resolved token value."
|
||||
(t/is (= (:r1 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 #{: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 :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-state 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 "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-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 #{: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 :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-state 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 "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-state 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-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-state 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-state 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-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-state 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-state 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-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-state 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"
|
||||
;; (t/async
|
||||
;; done
|
||||
;; (let [rotation-token {:name "rotation.medium"
|
||||
;; :value "120"
|
||||
;; :type :rotation}
|
||||
;; file (-> (setup-file-with-tokens)
|
||||
;; (update-in [:data :tokens-lib]
|
||||
;; #(ctob/add-token-in-set % "Set A" (ctob/make-token rotation-token))))
|
||||
;; store (ths/setup-store file)
|
||||
;; rect-1 (cths/get-shape file :rect-1)
|
||||
;; events [(wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||
;; :attributes #{:rotation}
|
||||
;; :token (toht/get-token file "rotation.medium")
|
||||
;; :on-update-shape wtch/update-rotation})]]
|
||||
;; (tohs/run-store-async
|
||||
;; store done events
|
||||
;; (fn [new-state]
|
||||
;; (let [file' (ths/get-file-from-state new-state)
|
||||
;; token-target' (toht/get-token file' "rotation.medium")
|
||||
;; rect-1' (cths/get-shape file' :rect-1)]
|
||||
;; (t/is (some? (:applied-tokens rect-1')))
|
||||
;; (t/is (= (:rotation (:applied-tokens rect-1')) (:name token-target')))
|
||||
;; (t/is (= (:rotation rect-1') 120)))))))))
|
||||
(t/deftest test-apply-rotation
|
||||
(t/testing "applies rotation token and updates the shapes rotation"
|
||||
(t/async
|
||||
done
|
||||
(let [rotation-token {:name "rotation.medium"
|
||||
:value "120"
|
||||
:type :rotation}
|
||||
file (-> (setup-file-with-tokens)
|
||||
(update-in [:data :tokens-lib]
|
||||
#(ctob/add-token-in-set % "Set A" (ctob/make-token rotation-token))))
|
||||
store (ths/setup-store file)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
events [(wtch/apply-token {:shape-ids [(:id rect-1)]
|
||||
:attributes #{:rotation}
|
||||
:token (toht/get-token file "rotation.medium")
|
||||
:on-update-shape wtch/update-rotation})]]
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-target' (toht/get-token file' "rotation.medium")
|
||||
rect-1' (cths/get-shape file' :rect-1)]
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
(t/is (= (:rotation (:applied-tokens rect-1')) (:name token-target')))
|
||||
(t/is (= (:rotation rect-1') 120)))))))))
|
||||
|
||||
;; (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-state 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-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-state 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"
|
||||
;; (t/async
|
||||
;; done
|
||||
;; (let [file (setup-file-with-tokens)
|
||||
;; store (ths/setup-store file)
|
||||
;; rect-1 (cths/get-shape file :rect-1)
|
||||
;; rect-2 (cths/get-shape file :rect-2)
|
||||
;; events [(wtch/toggle-token {:shapes [rect-1 rect-2]
|
||||
;; :token-type-props {:attributes #{:r1 :r2 :r3 :r4}
|
||||
;; :on-update-shape wtch/update-shape-radius-all}
|
||||
;; :token (toht/get-token file "borderRadius.md")})]]
|
||||
;; (tohs/run-store-async
|
||||
;; store done events
|
||||
;; (fn [new-state]
|
||||
;; (let [file' (ths/get-file-from-state new-state)
|
||||
;; token-2' (toht/get-token file' "borderRadius.md")
|
||||
;; rect-1' (cths/get-shape file' :rect-1)
|
||||
;; rect-2' (cths/get-shape file' :rect-2)]
|
||||
;; (t/is (some? (:applied-tokens rect-1')))
|
||||
;; (t/is (some? (:applied-tokens rect-2')))
|
||||
;; (t/is (= (:r1 (:applied-tokens rect-1')) (:name token-2')))
|
||||
;; (t/is (= (:r1 (:applied-tokens rect-2')) (:name token-2')))
|
||||
;; (t/is (= (:r1 rect-1') 24))
|
||||
;; (t/is (= (:r1 rect-2') 24)))))))))
|
||||
(t/deftest test-toggle-token-none
|
||||
(t/testing "should apply token to all selected items, where no item has the token applied"
|
||||
(t/async
|
||||
done
|
||||
(let [file (setup-file-with-tokens)
|
||||
store (ths/setup-store file)
|
||||
rect-1 (cths/get-shape file :rect-1)
|
||||
rect-2 (cths/get-shape file :rect-2)
|
||||
events [(wtch/toggle-token {:shapes [rect-1 rect-2]
|
||||
:token-type-props {:attributes #{:r1 :r2 :r3 :r4}
|
||||
:on-update-shape wtch/update-shape-radius-all}
|
||||
:token (toht/get-token file "borderRadius.md")})]]
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
token-2' (toht/get-token file' "borderRadius.md")
|
||||
rect-1' (cths/get-shape file' :rect-1)
|
||||
rect-2' (cths/get-shape file' :rect-2)]
|
||||
(t/is (some? (:applied-tokens rect-1')))
|
||||
(t/is (some? (:applied-tokens rect-2')))
|
||||
(t/is (= (:r1 (:applied-tokens rect-1')) (:name token-2')))
|
||||
(t/is (= (:r1 (:applied-tokens rect-2')) (:name token-2')))
|
||||
(t/is (= (:r1 rect-1') 24))
|
||||
(t/is (= (:r1 rect-2') 24)))))))))
|
||||
|
||||
;; (t/deftest test-toggle-token-mixed
|
||||
;; (t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes"
|
||||
;; (t/async
|
||||
;; done
|
||||
;; (let [file (-> (setup-file-with-tokens)
|
||||
;; (toht/apply-token-to-shape :rect-1 "borderRadius.sm" #{:r1 :r2 :r3 :r4})
|
||||
;; (toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:r1 :r2 :r3 :r4}))
|
||||
;; store (ths/setup-store file)
|
||||
(t/deftest test-toggle-token-mixed
|
||||
(t/testing "should unapply given token if one of the selected items has the token applied while keeping other tokens with some attributes"
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (setup-file-with-tokens)
|
||||
(toht/apply-token-to-shape :rect-1 "borderRadius.sm" #{:r1 :r2 :r3 :r4})
|
||||
(toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:r1 :r2 :r3 :r4}))
|
||||
store (ths/setup-store file)
|
||||
|
||||
;; rect-with-token (cths/get-shape file :rect-1)
|
||||
;; rect-without-token (cths/get-shape file :rect-2)
|
||||
;; rect-with-other-token (cths/get-shape file :rect-3)
|
||||
rect-with-token (cths/get-shape file :rect-1)
|
||||
rect-without-token (cths/get-shape file :rect-2)
|
||||
rect-with-other-token (cths/get-shape file :rect-3)
|
||||
|
||||
;; events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token]
|
||||
;; :token (toht/get-token file "borderRadius.sm")
|
||||
;; :token-type-props {:attributes #{:r1 :r2 :r3 :r4}}})]]
|
||||
;; (tohs/run-store-async
|
||||
;; store done events
|
||||
;; (fn [new-state]
|
||||
;; (let [file' (ths/get-file-from-state new-state)
|
||||
;; rect-with-token' (cths/get-shape file' :rect-1)
|
||||
;; rect-without-token' (cths/get-shape file' :rect-2)
|
||||
;; rect-with-other-token' (cths/get-shape file' :rect-3)]
|
||||
events [(wtch/toggle-token {:shapes [rect-with-token rect-without-token rect-with-other-token]
|
||||
:token (toht/get-token file "borderRadius.sm")
|
||||
:token-type-props {:attributes #{:r1 :r2 :r3 :r4}}})]]
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
rect-with-token' (cths/get-shape file' :rect-1)
|
||||
rect-without-token' (cths/get-shape file' :rect-2)
|
||||
rect-with-other-token' (cths/get-shape file' :rect-3)]
|
||||
|
||||
;; (t/testing "rect-with-token got the token removed"
|
||||
;; (t/is (nil? (:r1 (:applied-tokens rect-with-token')))))
|
||||
(t/testing "rect-with-token got the token removed"
|
||||
(t/is (nil? (:r1 (:applied-tokens rect-with-token')))))
|
||||
|
||||
;; (t/testing "rect-without-token didn't get updated"
|
||||
;; (t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token))))
|
||||
(t/testing "rect-without-token didn't get updated"
|
||||
(t/is (= (:applied-tokens rect-without-token') (:applied-tokens rect-without-token))))
|
||||
|
||||
;; (t/testing "rect-with-other-token didn't get updated"
|
||||
;; (t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token)))))))))))
|
||||
(t/testing "rect-with-other-token didn't get updated"
|
||||
(t/is (= (:applied-tokens rect-with-other-token') (:applied-tokens rect-with-other-token)))))))))))
|
||||
|
||||
;; (t/deftest test-toggle-token-apply-to-all
|
||||
;; (t/testing "should apply token to all if none of the shapes has it applied"
|
||||
;; (t/async
|
||||
;; done
|
||||
;; (let [file (-> (setup-file-with-tokens)
|
||||
;; (toht/apply-token-to-shape :rect-1 "borderRadius.md" #{:r1 :r2 :r3 :r4})
|
||||
;; (toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:r1 :r2 :r3 :r4}))
|
||||
;; store (ths/setup-store file)
|
||||
(t/deftest test-toggle-token-apply-to-all
|
||||
(t/testing "should apply token to all if none of the shapes has it applied"
|
||||
(t/async
|
||||
done
|
||||
(let [file (-> (setup-file-with-tokens)
|
||||
(toht/apply-token-to-shape :rect-1 "borderRadius.md" #{:r1 :r2 :r3 :r4})
|
||||
(toht/apply-token-to-shape :rect-3 "borderRadius.md" #{:r1 :r2 :r3 :r4}))
|
||||
store (ths/setup-store file)
|
||||
|
||||
;; rect-with-other-token-1 (cths/get-shape file :rect-1)
|
||||
;; rect-without-token (cths/get-shape file :rect-2)
|
||||
;; rect-with-other-token-2 (cths/get-shape file :rect-3)
|
||||
rect-with-other-token-1 (cths/get-shape file :rect-1)
|
||||
rect-without-token (cths/get-shape file :rect-2)
|
||||
rect-with-other-token-2 (cths/get-shape file :rect-3)
|
||||
|
||||
;; events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2]
|
||||
;; :token (toht/get-token file "borderRadius.sm")
|
||||
;; :token-type-props {:attributes #{:r1 :r2 :r3 :r4}}})]]
|
||||
;; (tohs/run-store-async
|
||||
;; store done events
|
||||
;; (fn [new-state]
|
||||
;; (let [file' (ths/get-file-from-state new-state)
|
||||
;; target-token (toht/get-token file' "borderRadius.sm")
|
||||
;; rect-with-other-token-1' (cths/get-shape file' :rect-1)
|
||||
;; rect-without-token' (cths/get-shape file' :rect-2)
|
||||
;; rect-with-other-token-2' (cths/get-shape file' :rect-3)]
|
||||
events [(wtch/toggle-token {:shapes [rect-with-other-token-1 rect-without-token rect-with-other-token-2]
|
||||
:token (toht/get-token file "borderRadius.sm")
|
||||
:token-type-props {:attributes #{:r1 :r2 :r3 :r4}}})]]
|
||||
(tohs/run-store-async
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [file' (ths/get-file-from-state new-state)
|
||||
target-token (toht/get-token file' "borderRadius.sm")
|
||||
rect-with-other-token-1' (cths/get-shape file' :rect-1)
|
||||
rect-without-token' (cths/get-shape file' :rect-2)
|
||||
rect-with-other-token-2' (cths/get-shape file' :rect-3)]
|
||||
|
||||
;; (t/testing "token got applied to all shapes"
|
||||
;; (t/is (= (:r1 (:applied-tokens rect-with-other-token-1')) (:name target-token)))
|
||||
;; (t/is (= (:r1 (:applied-tokens rect-without-token')) (:name target-token)))
|
||||
;; (t/is (= (:r1 (:applied-tokens rect-with-other-token-2')) (:name target-token)))))))))))
|
||||
(t/testing "token got applied to all shapes"
|
||||
(t/is (= (:r1 (:applied-tokens rect-with-other-token-1')) (:name target-token)))
|
||||
(t/is (= (:r1 (:applied-tokens rect-without-token')) (:name target-token)))
|
||||
(t/is (= (:r1 (:applied-tokens rect-with-other-token-2')) (:name target-token)))))))))))
|
||||
|
|
Loading…
Reference in a new issue