|
44 | 44 |
|
45 | 45 | (testing "select same tags"
|
46 | 46 | (rf/dispatch [::e/add {:tag :rect
|
47 |
| - :attrs {:width 100 |
48 |
| - :height 100}}]) |
| 47 | + :attrs {:width "100" |
| 48 | + :height "100"}}]) |
49 | 49 | (is (= :rect (-> @selected first :tag)))
|
50 | 50 |
|
51 | 51 | (rf/dispatch [::e/add {:tag :rect
|
52 |
| - :attrs {:width 100 |
53 |
| - :height 100}}]) |
| 52 | + :attrs {:width "100" |
| 53 | + :height "100"}}]) |
54 | 54 | (rf/dispatch [::e/select-same-tags])
|
55 | 55 | (is (= (count @selected) 2))))))
|
56 | 56 |
|
| 57 | +(deftest index |
| 58 | + (rf-test/run-test-sync |
| 59 | + (rf/dispatch [::app.e/initialize-db]) |
| 60 | + (rf/dispatch [::document.e/new-from-template nil]) |
| 61 | + |
| 62 | + (rf/dispatch [::e/add {:tag :rect |
| 63 | + :attrs {:width "100" |
| 64 | + :height "100"}}]) |
| 65 | + (rf/dispatch [::e/add {:tag :circle |
| 66 | + :attrs {:r "100" |
| 67 | + :cx "100" |
| 68 | + :cy "100"}}]) |
| 69 | + |
| 70 | + (rf/dispatch [::e/add {:tag :line |
| 71 | + :attrs {:x1 "0" |
| 72 | + :y1 "0" |
| 73 | + :x2 "50" |
| 74 | + :y2 "50"}}]) |
| 75 | + |
| 76 | + (let [elements (rf/subscribe [::s/root-children])] |
| 77 | + (testing "initial order" |
| 78 | + (is (= (mapv :tag @elements) [:rect :circle :line]))) |
| 79 | + |
| 80 | + (testing "lower" |
| 81 | + (rf/dispatch [::e/lower]) |
| 82 | + (is (= (mapv :tag @elements) [:rect :line :circle]))) |
| 83 | + |
| 84 | + (testing "raise" |
| 85 | + (rf/dispatch [::e/raise]) |
| 86 | + (is (= (mapv :tag @elements) [:rect :circle :line]))) |
| 87 | + |
| 88 | + (testing "raise when already on top" |
| 89 | + (rf/dispatch [::e/raise]) |
| 90 | + (is (= (mapv :tag @elements) [:rect :circle :line]))) |
| 91 | + |
| 92 | + (testing "lower to bottom" |
| 93 | + (rf/dispatch [::e/lower-to-bottom]) |
| 94 | + (is (= (mapv :tag @elements) [:line :rect :circle]))) |
| 95 | + |
| 96 | + (testing "raise to top" |
| 97 | + (rf/dispatch [::e/raise-to-top]) |
| 98 | + (is (= (mapv :tag @elements) [:rect :circle :line])))))) |
| 99 | + |
| 100 | +(deftest align |
| 101 | + (rf-test/run-test-sync |
| 102 | + (rf/dispatch [::app.e/initialize-db]) |
| 103 | + (rf/dispatch [::document.e/new-from-template [800 600]]) |
| 104 | + |
| 105 | + (rf/dispatch [::e/add {:tag :rect |
| 106 | + :attrs {:x "50" |
| 107 | + :y "50" |
| 108 | + :width "100" |
| 109 | + :height "100"}}]) |
| 110 | + |
| 111 | + (let [elements (rf/subscribe [::s/selected])] |
| 112 | + (testing "align left" |
| 113 | + (rf/dispatch [::e/align :left]) |
| 114 | + (is (= (-> @elements first :attrs) {:x "0" |
| 115 | + :y "50" |
| 116 | + :width "100" |
| 117 | + :height "100"}))) |
| 118 | + |
| 119 | + (testing "align top" |
| 120 | + (rf/dispatch [::e/align :top]) |
| 121 | + (is (= (-> @elements first :attrs) {:x "0" |
| 122 | + :y "0" |
| 123 | + :width "100" |
| 124 | + :height "100"}))) |
| 125 | + |
| 126 | + (testing "align right" |
| 127 | + (rf/dispatch [::e/align :right]) |
| 128 | + (is (= (-> @elements first :attrs) {:x "700" |
| 129 | + :y "0" |
| 130 | + :width "100" |
| 131 | + :height "100"}))) |
| 132 | + |
| 133 | + (testing "align bottom" |
| 134 | + (rf/dispatch [::e/align :bottom]) |
| 135 | + (is (= (-> @elements first :attrs) {:x "700" |
| 136 | + :y "500" |
| 137 | + :width "100" |
| 138 | + :height "100"}))) |
| 139 | + |
| 140 | + (testing "align center vertical" |
| 141 | + (rf/dispatch [::e/align :center-vertical]) |
| 142 | + (is (= (-> @elements first :attrs) {:x "700" |
| 143 | + :y "250" |
| 144 | + :width "100" |
| 145 | + :height "100"}))) |
| 146 | + |
| 147 | + (testing "align center horizontal" |
| 148 | + (rf/dispatch [::e/align :center-horizontal]) |
| 149 | + (is (= (-> @elements first :attrs) {:x "350" |
| 150 | + :y "250" |
| 151 | + :width "100" |
| 152 | + :height "100"})))))) |
| 153 | + |
57 | 154 | (deftest visibility
|
58 | 155 | (rf-test/run-test-sync
|
59 | 156 | (rf/dispatch [::app.e/initialize-db])
|
60 | 157 | (rf/dispatch [::document.e/init])
|
61 | 158 |
|
62 | 159 | (let [selected (rf/subscribe [::s/selected])]
|
63 | 160 | (rf/dispatch [::e/add {:tag :rect
|
64 |
| - :attrs {:width 100 |
65 |
| - :height 100}}]) |
| 161 | + :attrs {:width "100" |
| 162 | + :height "100"}}]) |
66 | 163 | (testing "default state"
|
67 | 164 | (is (-> @selected first :visible)))
|
68 | 165 |
|
|
81 | 178 |
|
82 | 179 | (let [selected (rf/subscribe [::s/selected])]
|
83 | 180 | (rf/dispatch [::e/add {:tag :rect
|
84 |
| - :attrs {:width 100 |
85 |
| - :height 100}}]) |
| 181 | + :attrs {:width "100" |
| 182 | + :height "100"}}]) |
86 | 183 | (testing "default state"
|
87 | 184 | (is (not (-> @selected first :label))))
|
88 | 185 |
|
|
101 | 198 |
|
102 | 199 | (let [selected (rf/subscribe [::s/selected])]
|
103 | 200 | (rf/dispatch [::e/add {:tag :rect
|
104 |
| - :attrs {:width 100 |
105 |
| - :height 100}}]) |
| 201 | + :attrs {:width "100" |
| 202 | + :height "100"}}]) |
106 | 203 | (testing "default state"
|
107 | 204 | (is (not (-> @selected first :locked))))
|
108 | 205 |
|
|
121 | 218 |
|
122 | 219 | (let [selected (rf/subscribe [::s/selected])]
|
123 | 220 | (rf/dispatch [::e/add {:tag :rect
|
124 |
| - :attrs {:width 100 |
125 |
| - :height 100 |
| 221 | + :attrs {:width "100" |
| 222 | + :height "100" |
126 | 223 | :fill "white"}}])
|
127 | 224 | (is (= (-> @selected first :attrs :fill) "white"))
|
128 | 225 |
|
|
145 | 242 |
|
146 | 243 | (let [selected (rf/subscribe [::s/selected])]
|
147 | 244 | (rf/dispatch [::e/add {:tag :rect
|
148 |
| - :attrs {:width 100 |
149 |
| - :height 100}}]) |
| 245 | + :attrs {:width "100" |
| 246 | + :height "100"}}]) |
150 | 247 |
|
151 | 248 | (testing "delete selection"
|
152 | 249 | (let [id (-> @selected first :id)]
|
|
161 | 258 | (rf/dispatch [::document.e/init])
|
162 | 259 | (let [selected (rf/subscribe [::s/selected])]
|
163 | 260 | (rf/dispatch [::e/add {:tag :rect
|
164 |
| - :attrs {:width 100 |
165 |
| - :height 100}}]) |
| 261 | + :attrs {:width "100" |
| 262 | + :height "100"}}]) |
166 | 263 | (rf/dispatch [::e/scale [2 4]])
|
167 | 264 | (is (= (-> @selected first :attrs :width) "200"))
|
168 | 265 | (is (= (-> @selected first :attrs :height) "400")))))
|
|
173 | 270 | (rf/dispatch [::document.e/init])
|
174 | 271 | (let [selected (rf/subscribe [::s/selected])]
|
175 | 272 | (rf/dispatch [::e/add {:tag :rect
|
176 |
| - :attrs {:x 100 |
177 |
| - :y 100 |
178 |
| - :width 100 |
179 |
| - :height 100}}]) |
| 273 | + :attrs {:x "100" |
| 274 | + :y "100" |
| 275 | + :width "100" |
| 276 | + :height "100"}}]) |
180 | 277 | (rf/dispatch [::e/translate [50 100]])
|
181 | 278 | (is (= (-> @selected first :attrs :x) "150"))
|
182 | 279 | (is (= (-> @selected first :attrs :y) "200")))))
|
|
187 | 284 | (rf/dispatch [::document.e/init])
|
188 | 285 | (let [selected (rf/subscribe [::s/selected])]
|
189 | 286 | (rf/dispatch [::e/add {:tag :rect
|
190 |
| - :attrs {:x 100 |
191 |
| - :y 100 |
192 |
| - :width 100 |
193 |
| - :height 100}}]) |
| 287 | + :attrs {:x "100" |
| 288 | + :y "100" |
| 289 | + :width "100" |
| 290 | + :height "100"}}]) |
194 | 291 | (rf/dispatch [::e/place [100 100]])
|
195 | 292 | (is (= (-> @selected first :attrs :x) "50"))
|
196 | 293 | (is (= (-> @selected first :attrs :y) "50")))))
|
|
201 | 298 | (rf/dispatch [::document.e/init])
|
202 | 299 | (let [selected (rf/subscribe [::s/selected])]
|
203 | 300 | (rf/dispatch [::e/add {:tag :rect
|
204 |
| - :attrs {:x 100 |
205 |
| - :y 100 |
206 |
| - :width 100 |
207 |
| - :height 100 |
| 301 | + :attrs {:x "100" |
| 302 | + :y "100" |
| 303 | + :width "100" |
| 304 | + :height "100" |
208 | 305 | :fill "red"}}])
|
209 | 306 | (rf/dispatch [::e/->path])
|
210 | 307 | (is (= (-> @selected first :tag) :path))
|
|
217 | 314 | (rf/dispatch [::document.e/init])
|
218 | 315 | (let [selected (rf/subscribe [::s/selected])]
|
219 | 316 | (rf/dispatch [::e/add {:tag :rect
|
220 |
| - :attrs {:x 100 |
221 |
| - :y 100 |
222 |
| - :width 100 |
223 |
| - :height 100 |
| 317 | + :attrs {:x "100" |
| 318 | + :y "100" |
| 319 | + :width "100" |
| 320 | + :height "100" |
224 | 321 | :fill "red"
|
225 | 322 | :stroke "black"}}])
|
226 | 323 | (rf/dispatch [::e/stroke->path])
|
|
234 | 331 | (rf/dispatch [::document.e/init])
|
235 | 332 | (let [selected (rf/subscribe [::s/selected])]
|
236 | 333 | (rf/dispatch [::e/add {:tag :rect
|
237 |
| - :attrs {:x 100 |
238 |
| - :y 100 |
239 |
| - :width 100 |
240 |
| - :height 100 |
| 334 | + :attrs {:x "100" |
| 335 | + :y "100" |
| 336 | + :width "100" |
| 337 | + :height "100" |
241 | 338 | :fill "red"
|
242 | 339 | :stroke "black"}}])
|
243 | 340 | (rf/dispatch [::e/add {:tag :rect
|
244 |
| - :attrs {:x 100 |
245 |
| - :y 100 |
246 |
| - :width 100 |
247 |
| - :height 100}}]) |
| 341 | + :attrs {:x "100" |
| 342 | + :y "100" |
| 343 | + :width "100" |
| 344 | + :height "100"}}]) |
248 | 345 | (rf/dispatch [::e/select-all])
|
249 | 346 | (rf/dispatch [::e/boolean-operation :unite])
|
250 | 347 | (is (= (-> @selected first :tag) :path))
|
|
268 | 365 | (rf/dispatch [::app.e/initialize-db])
|
269 | 366 | (rf/dispatch [::document.e/init])
|
270 | 367 | (rf/dispatch [::e/add {:tag :rect
|
271 |
| - :attrs {:x 100 |
272 |
| - :y 100 |
273 |
| - :width 100 |
274 |
| - :height 100}}]) |
| 368 | + :attrs {:x "100" |
| 369 | + :y "100" |
| 370 | + :width "100" |
| 371 | + :height "100"}}]) |
275 | 372 | (let [selected (rf/subscribe [::s/selected])
|
276 | 373 | id (-> @selected first :id)]
|
277 | 374 | (rf/dispatch [::e/animate :animate {}])
|
|
283 | 380 | (rf/dispatch [::app.e/initialize-db])
|
284 | 381 | (rf/dispatch [::document.e/init])
|
285 | 382 | (rf/dispatch [::e/add {:tag :rect
|
286 |
| - :attrs {:x 100 |
287 |
| - :y 100 |
288 |
| - :width 100 |
289 |
| - :height 100}}]) |
| 383 | + :attrs {:x "100" |
| 384 | + :y "100" |
| 385 | + :width "100" |
| 386 | + :height "100"}}]) |
290 | 387 | (let [selected (rf/subscribe [::s/selected])
|
291 | 388 | id (-> @selected first :id)]
|
292 | 389 | (testing "group"
|
|
0 commit comments