Skip to content

Commit 9c8df2c

Browse files
committed
fix fn specs and enable boolean operation tests
1 parent 8a54fd5 commit 9c8df2c

File tree

7 files changed

+13621
-12063
lines changed

7 files changed

+13621
-12063
lines changed

.clj-kondo/metosin/malli-types-cljs/config.edn

+13,578-12,038
Large diffs are not rendered by default.

src/renderer/element/handlers.cljs

+17-4
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@
133133
(count (children-ids db (first parent-els)))))))
134134

135135
(m/=> siblings [:function
136-
[:-> App [:vector uuid?]]
137-
[:-> App uuid? [:vector uuid?]]])
136+
[:-> App [:maybe [:vector uuid?]]]
137+
[:-> App uuid? [:maybe [:vector uuid?]]]])
138138
(defn siblings
139139
([db]
140140
(:children (parent db)))
@@ -182,8 +182,10 @@
182182
of nested elements."
183183
[db id]
184184
(let [ancestor-els (reverse (ancestor-ids db id))]
185-
(conj (mapv #(index db %) ancestor-els)
186-
(index db id))))
185+
(->> (index db id)
186+
(conj (map #(index db %) ancestor-els))
187+
(remove nil?)
188+
(vec))))
187189

188190
(m/=> descendant-ids [:function
189191
[:-> App [:set uuid?]]
@@ -658,12 +660,18 @@
658660
:parent (-> selected-elements first :parent)
659661
:attrs (merge attrs {:d new-path})})))))
660662

663+
(m/=> paste-in-place [:function
664+
[:-> App App]
665+
[:-> App Element App]])
661666
(defn paste-in-place
662667
([db]
663668
(reduce paste-in-place (deselect db) (:copied-elements db)))
664669
([db el]
665670
(reduce select (add db el) (selected-ids db))))
666671

672+
(m/=> paste [:function
673+
[:-> App App]
674+
[:-> App Element Element App]])
667675
(defn paste
668676
([db]
669677
(let [parent-el (hovered-svg db)]
@@ -705,6 +713,9 @@
705713
:attrs attrs
706714
:parent id}) (selected-ids db))))
707715

716+
(m/=> paste-styles [:function
717+
[:-> App App]
718+
[:-> App uuid? App]])
708719
(defn paste-styles
709720
([db]
710721
(reduce paste-styles db (selected-ids db)))
@@ -719,6 +730,7 @@
719730
(update-attr id attr #(if % (-> attrs attr) disj))))
720731
db style-attrs)) db)))
721732

733+
(m/=> inherit-attrs [:-> App Element uuid? App])
722734
(defn inherit-attrs
723735
[db source-el id]
724736
(reduce
@@ -787,6 +799,7 @@
787799
(-> (add db svg)
788800
(collapse))))
789801

802+
(m/=> snapping-points [:-> App [:maybe [:sequential Element]] [:vector Vec2D]])
790803
(defn snapping-points
791804
[db els]
792805
(let [options (-> db :snap :options)]

src/renderer/snap/handlers.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
(assoc nneighbor :base-point %)))
2828
(remove nil?)))
2929

30+
(m/=> update-nearest-neighbors [:-> App App])
3031
(defn update-nearest-neighbors
3132
[db]
3233
(let [zoom (get-in db [:documents (:active-document db) :zoom])

src/renderer/tool/handlers.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
[db]
7676
(get-in db [:documents (:active-document db) :temp-element]))
7777

78+
(m/=> create-temp-element [:-> App App])
7879
(defn create-temp-element
7980
[db]
8081
(->> (temp db)

src/renderer/utils/i18n.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"Internationalization namespace
33
https://github.com/taoensso/tempura"
44
(:require
5+
[malli.core :as m]
56
[re-frame.core :as rf]
67
[renderer.app.subs :as-alias app.s]
78
[taoensso.tempura :refer [tr] :refer-macros [load-resource-at-compile-time]]))
@@ -12,6 +13,7 @@
1213
{:en-US (load-resource-at-compile-time "lang/en-US.edn")
1314
:el-GR (load-resource-at-compile-time "lang/el-GR.edn")})
1415

16+
(m/=> lang? [:-> keyword? boolean?])
1517
(defn lang?
1618
[lang]
1719
(contains? dictionary lang))

src/renderer/utils/path.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
(def PathManipulation
1010
[:enum :simplify :smooth :flatten :reverse])
1111

12+
(m/=> get-d [:-> any? string?])
1213
(defn get-d
1314
[paper-path]
1415
(-> paper-path

test/element_test.cljs

+21-21
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,27 @@
171171
(is (= (-> @selected first :attrs :fill) "black"))
172172
(not (-> @selected first :attrs :stroke)))))
173173

174-
#_(deftest boolean-operation
175-
(rf-test/run-test-sync
176-
(rf/dispatch [::app.e/initialize-db])
177-
(rf/dispatch [::document.e/init])
178-
(let [selected (rf/subscribe [::s/selected])]
179-
(rf/dispatch [::e/add {:tag :rect
180-
:attrs {:x 100
181-
:y 100
182-
:width 100
183-
:height 100
184-
:fill "red"
185-
:stroke "black"}}])
186-
(rf/dispatch [::e/add {:tag :rect
187-
:attrs {:x 100
188-
:y 100
189-
:width 100
190-
:height 100}}])
191-
(rf/dispatch [::e/select-all])
192-
(rf/dispatch [::e/boolean-operation :unite])
193-
(is (= (-> @selected first :tag) :path))
194-
(is (= (-> @selected first :attrs :fill) "red")))))
174+
(deftest boolean-operation
175+
(rf-test/run-test-sync
176+
(rf/dispatch [::app.e/initialize-db])
177+
(rf/dispatch [::document.e/init])
178+
(let [selected (rf/subscribe [::s/selected])]
179+
(rf/dispatch [::e/add {:tag :rect
180+
:attrs {:x 100
181+
:y 100
182+
:width 100
183+
:height 100
184+
:fill "red"
185+
:stroke "black"}}])
186+
(rf/dispatch [::e/add {:tag :rect
187+
:attrs {:x 100
188+
:y 100
189+
:width 100
190+
:height 100}}])
191+
(rf/dispatch [::e/select-all])
192+
(rf/dispatch [::e/boolean-operation :unite])
193+
(is (= (-> @selected first :tag) :path))
194+
(is (= (-> @selected first :attrs :fill) "red")))))
195195

196196
(deftest import-svg
197197
(rf-test/run-test-sync

0 commit comments

Comments
 (0)