Skip to content

Commit 912d5a3

Browse files
committed
fix and simplify some tests
1 parent bd0c94d commit 912d5a3

File tree

3 files changed

+114
-163
lines changed

3 files changed

+114
-163
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,8 @@
47584758
:label :string,
47594759
:id :any,
47604760
:attrs :map,
4761-
:visible :boolean},
4761+
:visible :boolean,
4762+
:cached-attrs :map},
47624763
:req {:tag :any}},
47634764
:focused :boolean,
47644765
:filter :keyword},
@@ -4869,7 +4870,8 @@
48694870
:label :string,
48704871
:id :any,
48714872
:attrs :map,
4872-
:visible :boolean},
4873+
:visible :boolean,
4874+
:cached-attrs :map},
48734875
:req {:tag :any}},
48744876
:focused :boolean,
48754877
:filter :keyword},

test/benchmark_test.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[renderer.app.events :as app.e]
88
[renderer.document.events :as document.e]
99
[renderer.element.events :as element.e]
10-
[renderer.snap.events :as snap.e]))
10+
[renderer.snap.events]))
1111

1212
(defn bench
1313
"Returns the elapsed time of the event handling in milliseconds."
@@ -19,7 +19,7 @@
1919
end (.getTime (js/Date.))]
2020
(- end start))))
2121

22-
(deftest test-pp-str
22+
(deftest polygons
2323
(rf-test/run-test-sync
2424
(rf/dispatch [::app.e/initialize-db])
2525
(rf/dispatch [::document.e/init])
@@ -32,11 +32,11 @@
3232
(testing "selecting elements"
3333
(is (> 1000 (bench [::element.e/select-all]))))
3434

35-
(testing "selecting elements with snap disabled"
36-
(rf/dispatch [::snap.e/toggle])
37-
(is (> 100 (bench [::element.e/select-all]))))
35+
(testing "deselecting elements"
36+
(is (> 1000 (bench [::element.e/deselect-all]))))
3837

3938
(testing "moving elements"
39+
(rf/dispatch [::element.e/select-all])
4040
(is (> 100 (bench [::element.e/translate [100 100]]))))
4141

4242
(testing "scaling elements"

test/element_impl_test.cljs

+105-156
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@
1111
:cy "0"
1212
:r "50"}}]
1313

14-
(is (= (hierarchy/translate circle-el [50 50])
15-
{:type :element
16-
:tag :circle
17-
:attrs {:cx "50"
18-
:cy "50"
19-
:r "50"}}))
20-
21-
(is (= (hierarchy/scale circle-el [2 2] [50 50])
22-
{:type :element
23-
:tag :circle
24-
:attrs {:cx "0"
25-
:cy "0"
26-
:r "100"}}))
27-
28-
(is (= (hierarchy/scale circle-el [2 2] [0 0])
29-
{:type :element
30-
:tag :circle
31-
:attrs {:cx "50"
32-
:cy "50"
33-
:r "100"}}))
14+
(is (= (:attrs (hierarchy/translate circle-el [50 50]))
15+
{:cx "50"
16+
:cy "50"
17+
:r "50"}))
18+
19+
(is (= (:attrs (hierarchy/scale circle-el [2 2] [50 50]))
20+
{:cx "0"
21+
:cy "0"
22+
:r "100"}))
23+
24+
(is (= (:attrs (hierarchy/scale circle-el [2 2] [0 0]))
25+
{:cx "50"
26+
:cy "50"
27+
:r "100"}))
3428

3529
(is (= (hierarchy/bounds circle-el)
3630
[-50 -50 50 50]))
@@ -46,29 +40,23 @@
4640
:width "50"
4741
:height "50"}}]
4842

49-
(is (= (hierarchy/translate rect-el [50 50])
50-
{:type :element
51-
:tag :rect
52-
:attrs {:x "50"
53-
:y "50"
54-
:width "50"
55-
:height "50"}}))
56-
57-
(is (= (hierarchy/scale rect-el [2 2] [25 25])
58-
{:type :element
59-
:tag :rect
60-
:attrs {:x "-25"
61-
:y "-25"
62-
:width "100"
63-
:height "100"}}))
64-
65-
(is (= (hierarchy/scale rect-el [2 2] [0 0])
66-
{:type :element
67-
:tag :rect
68-
:attrs {:x "0"
69-
:y "0"
70-
:width "100"
71-
:height "100"}}))
43+
(is (= (:attrs (hierarchy/translate rect-el [50 50]))
44+
{:x "50"
45+
:y "50"
46+
:width "50"
47+
:height "50"}))
48+
49+
(is (= (:attrs (hierarchy/scale rect-el [2 2] [25 25]))
50+
{:x "-25"
51+
:y "-25"
52+
:width "100"
53+
:height "100"}))
54+
55+
(is (= (:attrs (hierarchy/scale rect-el [2 2] [0 0]))
56+
{:x "0"
57+
:y "0"
58+
:width "100"
59+
:height "100"}))
7260

7361
(is (= (hierarchy/bounds rect-el)
7462
[0 0 50 50]))
@@ -84,29 +72,23 @@
8472
:rx "50"
8573
:ry "50"}}]
8674

87-
(is (= (hierarchy/translate ellipse-el [50 50])
88-
{:type :element
89-
:tag :ellipse
90-
:attrs {:cx "50"
91-
:cy "50"
92-
:rx "50"
93-
:ry "50"}}))
94-
95-
(is (= (hierarchy/scale ellipse-el [2 2] [25 25])
96-
{:type :element
97-
:tag :ellipse
98-
:attrs {:cx "25"
99-
:cy "25"
100-
:rx "100"
101-
:ry "100"}}))
102-
103-
(is (= (hierarchy/scale ellipse-el [2 2] [0 0])
104-
{:type :element
105-
:tag :ellipse
106-
:attrs {:cx "50"
107-
:cy "50"
108-
:rx "100"
109-
:ry "100"}}))
75+
(is (= (:attrs (hierarchy/translate ellipse-el [50 50]))
76+
{:cx "50"
77+
:cy "50"
78+
:rx "50"
79+
:ry "50"}))
80+
81+
(is (= (:attrs (hierarchy/scale ellipse-el [2 2] [25 25]))
82+
{:cx "25"
83+
:cy "25"
84+
:rx "100"
85+
:ry "100"}))
86+
87+
(is (= (:attrs (hierarchy/scale ellipse-el [2 2] [0 0]))
88+
{:cx "50"
89+
:cy "50"
90+
:rx "100"
91+
:ry "100"}))
11092

11193
(is (= (hierarchy/bounds ellipse-el)
11294
[-50 -50 50 50]))
@@ -122,29 +104,23 @@
122104
:x2 "50"
123105
:y2 "50"}}]
124106

125-
(is (= (hierarchy/translate line-el [50 50])
126-
{:type :element
127-
:tag :line
128-
:attrs {:x1 "50"
129-
:y1 "50"
130-
:x2 "100"
131-
:y2 "100"}}))
132-
133-
(is (= (hierarchy/scale line-el [2 2] [25 25])
134-
{:type :element
135-
:tag :line
136-
:attrs {:x1 "-25"
137-
:y1 "-25"
138-
:x2 "75"
139-
:y2 "75"}}))
140-
141-
(is (= (hierarchy/scale line-el [2 2] [0 0])
142-
{:type :element
143-
:tag :line
144-
:attrs {:x1 "0"
145-
:y1 "0"
146-
:x2 "100"
147-
:y2 "100"}}))
107+
(is (= (:attrs (hierarchy/translate line-el [50 50]))
108+
{:x1 "50"
109+
:y1 "50"
110+
:x2 "100"
111+
:y2 "100"}))
112+
113+
(is (= (:attrs (hierarchy/scale line-el [2 2] [25 25]))
114+
{:x1 "-25"
115+
:y1 "-25"
116+
:x2 "75"
117+
:y2 "75"}))
118+
119+
(is (= (:attrs (hierarchy/scale line-el [2 2] [0 0]))
120+
{:x1 "0"
121+
:y1 "0"
122+
:x2 "100"
123+
:y2 "100"}))
148124

149125
(is (= (hierarchy/bounds line-el)
150126
[0 0 50 50]))
@@ -157,20 +133,14 @@
157133
:tag :polygon
158134
:attrs {:points "528 -305 718 -370 941 -208"}}]
159135

160-
(is (= (hierarchy/translate polygon-el [10 10])
161-
{:type :element
162-
:tag :polygon
163-
:attrs {:points "538 -295 728 -360 951 -198"}}))
136+
(is (= (:attrs (hierarchy/translate polygon-el [10 10]))
137+
{:points "538 -295 728 -360 951 -198"}))
164138

165-
(is (= (hierarchy/scale polygon-el [2 2] [25 25])
166-
{:type :element
167-
:tag :polygon
168-
:attrs {:points "503 -265 883 -395 1329 -71"}}))
139+
(is (= (:attrs (hierarchy/scale polygon-el [2 2] [25 25]))
140+
{:points "503 -265 883 -395 1329 -71"}))
169141

170-
(is (= (hierarchy/scale polygon-el [2 2] [0 0])
171-
{:type :element
172-
:tag :polygon
173-
:attrs {:points "528 -240 908 -370 1354 -46"}}))
142+
(is (= (:attrs (hierarchy/scale polygon-el [2 2] [0 0]))
143+
{:points "528 -240 908 -370 1354 -46"}))
174144

175145
(is (= (hierarchy/bounds polygon-el)
176146
[528 -370 941 -208]))
@@ -186,20 +156,14 @@
186156
:tag :polyline
187157
:attrs {:points "528 -305 718 -370 941 -208"}}]
188158

189-
(is (= (hierarchy/translate polyline-el [10 10])
190-
{:type :element
191-
:tag :polyline
192-
:attrs {:points "538 -295 728 -360 951 -198"}}))
159+
(is (= (:attrs (hierarchy/translate polyline-el [10 10]))
160+
{:points "538 -295 728 -360 951 -198"}))
193161

194-
(is (= (hierarchy/scale polyline-el [2 2] [25 25])
195-
{:type :element
196-
:tag :polyline
197-
:attrs {:points "503 -265 883 -395 1329 -71"}}))
162+
(is (= (:attrs (hierarchy/scale polyline-el [2 2] [25 25]))
163+
{:points "503 -265 883 -395 1329 -71"}))
198164

199-
(is (= (hierarchy/scale polyline-el [2 2] [0 0])
200-
{:type :element
201-
:tag :polyline
202-
:attrs {:points "528 -240 908 -370 1354 -46"}}))
165+
(is (= (:attrs (hierarchy/scale polyline-el [2 2] [0 0]))
166+
{:points "528 -240 908 -370 1354 -46"}))
203167

204168
(is (= (hierarchy/bounds polyline-el)
205169
[528 -370 941 -208]))
@@ -215,20 +179,14 @@
215179
:tag :path
216180
:attrs {:d "M528 -305 718 -371 941 -208 663 -174 664 -261z"}}]
217181

218-
(is (= (hierarchy/translate path-el [10 10])
219-
{:type :element
220-
:tag :path
221-
:attrs {:d "M538-295L728-361 951-198 673-164 674-251z"}}))
182+
(is (= (:attrs (hierarchy/translate path-el [10 10]))
183+
{:d "M538-295L728-361 951-198 673-164 674-251z"}))
222184

223-
(is (= (hierarchy/scale path-el [2 2] [25 25])
224-
{:type :element
225-
:tag :path
226-
:attrs {:d "M503-264L883-396 1329-70 773-2 775-176z"}}))
185+
(is (= (:attrs (hierarchy/scale path-el [2 2] [25 25]))
186+
{:d "M503-264L883-396 1329-70 773-2 775-176z"}))
227187

228-
(is (= (hierarchy/scale path-el [2 2] [0 0])
229-
{:type :element
230-
:tag :path
231-
:attrs {:d "M528-239L908-371 1354-45 798 23 800-151z"}}))
188+
(is (= (:attrs (hierarchy/scale path-el [2 2] [0 0]))
189+
{:d "M528-239L908-371 1354-45 798 23 800-151z"}))
232190

233191
(is (= (hierarchy/bounds path-el)
234192
[528 -371 941 -174]))
@@ -243,29 +201,23 @@
243201
:width "50"
244202
:height "50"}}]
245203

246-
(is (= (hierarchy/translate svg-el [50 50])
247-
{:type :element
248-
:tag :svg
249-
:attrs {:x "50"
250-
:y "50"
251-
:width "50"
252-
:height "50"}}))
253-
254-
(is (= (hierarchy/scale svg-el [2 2] [25 25])
255-
{:type :element
256-
:tag :svg
257-
:attrs {:x "-25"
258-
:y "-25"
259-
:width "100"
260-
:height "100"}}))
261-
262-
(is (= (hierarchy/scale svg-el [2 2] [0 0])
263-
{:type :element
264-
:tag :svg
265-
:attrs {:x "0"
266-
:y "0"
267-
:width "100"
268-
:height "100"}}))
204+
(is (= (:attrs (hierarchy/translate svg-el [50 50]))
205+
{:x "50"
206+
:y "50"
207+
:width "50"
208+
:height "50"}))
209+
210+
(is (= (:attrs (hierarchy/scale svg-el [2 2] [25 25]))
211+
{:x "-25"
212+
:y "-25"
213+
:width "100"
214+
:height "100"}))
215+
216+
(is (= (:attrs (hierarchy/scale svg-el [2 2] [0 0]))
217+
{:x "0"
218+
:y "0"
219+
:width "100"
220+
:height "100"}))
269221

270222
(is (= (hierarchy/bounds svg-el)
271223
[0 0 50 50]))
@@ -281,11 +233,8 @@
281233
:width "50"
282234
:height "50"}}]
283235

284-
(is (= (hierarchy/translate text-el [50 50])
285-
{:type :element
286-
:tag :text
287-
:content "My text"
288-
:attrs {:x "50"
289-
:y "50"
290-
:width "50"
291-
:height "50"}}))))
236+
(is (= (:attrs (hierarchy/translate text-el [50 50]))
237+
{:x "50"
238+
:y "50"
239+
:width "50"
240+
:height "50"}))))

0 commit comments

Comments
 (0)