Move all files under frontend directory.

This commit is contained in:
Andrey Antukh 2016-11-20 20:03:17 +01:00
parent 92b45b2d05
commit e21798f1ed
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
603 changed files with 10 additions and 31 deletions

View file

@ -0,0 +1,114 @@
(ns uxbox.tests.geom-types
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer (pprint)]
[uxbox.util.geom.point :as gpt]
[uxbox.util.geom.matrix :as gmt]))
(t/deftest point-constructors-test
(let [p (gpt/point 1 2)]
(t/is (= (:x p) 1))
(t/is (= (:y p) 2))
(t/is (gpt/point? p)))
(let [p (gpt/point 1)]
(t/is (= (:x p) 1))
(t/is (= (:y p) 1)))
(let [p (gpt/point)]
(t/is (= (:x p) 0))
(t/is (= (:y p) 0)))
(let [p (gpt/point [1 2])]
(t/is (= (:x p) 1))
(t/is (= (:y p) 2))))
(t/deftest point-rotate-test
(let [p1 (gpt/point 10 0)
p2 (gpt/rotate p1 90)]
(t/is (= (:x p2) 0))
(t/is (= (:y p2) 10))
(t/is (gpt/point? p2))))
(t/deftest point-add-test
(let [p1 (gpt/point 1 1)
p2 (gpt/point 2 2)
p3 (gpt/add p1 p2)]
(t/is (= (:x p3) 3))
(t/is (= (:y p3) 3))
(t/is (gpt/point? p3))))
(t/deftest point-subtract-test
(let [p1 (gpt/point 3 3)
p2 (gpt/point 2 2)
p3 (gpt/subtract p1 p2)]
(t/is (= (:x p3) 1))
(t/is (= (:y p3) 1))
(t/is (gpt/point? p3))))
(t/deftest point-distance-test
(let [p1 (gpt/point 0 0)
p2 (gpt/point 10 0)
d (gpt/distance p1 p2)]
(t/is (number? d))
(t/is (= d 10))))
(t/deftest point-length-test
(let [p1 (gpt/point 10 0)
ln (gpt/length p1)]
(t/is (number? ln))
(t/is (= ln 10))))
(t/deftest point-angle-test
(let [p1 (gpt/point 0 10)
angle (gpt/angle p1)]
(t/is (number? angle))
(t/is (= angle 90)))
(let [p1 (gpt/point 0 10)
p2 (gpt/point 10 10)
angle (gpt/angle-with-other p1 p2)]
(t/is (number? angle))
(t/is (= angle 45))))
(t/deftest point-quadrant-test
(let [p1 (gpt/point 10 10)
p2 (gpt/point -10 10)
p3 (gpt/point -10 -10)
p4 (gpt/point 10 -10)]
(t/is (= 1 (gpt/quadrant p1)))
(t/is (= 2 (gpt/quadrant p2)))
(t/is (= 3 (gpt/quadrant p3)))
(t/is (= 4 (gpt/quadrant p4)))))
(t/deftest matrix-constructors-test
(let [m (gmt/matrix)]
(t/is (= @m [1 0 0 1 0 0]))
(t/is (gmt/matrix? m)))
(let [m (gmt/matrix 1 1 1 2 2 2)]
(t/is (= @m [1 1 1 2 2 2]))
(t/is (gmt/matrix? m)))
(let [m (gmt/matrix [1 1 1 2 2 2])]
(t/is (= @m [1 1 1 2 2 2]))
(t/is (gmt/matrix? m))))
(t/deftest matrix-rotate-test
(let [m (-> (gmt/matrix)
(gmt/rotate 10))]
(t/is (= @m [0.984807753012208
0.17364817766693033
-0.17364817766693033
0.984807753012208
0 0]))))
(t/deftest matrix-scale-test
(let [m (-> (gmt/matrix)
(gmt/scale 2))]
(t/is (= @m [2 0 0 2 0 0]))))
(t/deftest matrix-translate-test
(let [m (-> (gmt/matrix)
(gmt/translate 2 10))]
(t/is (= @m [1 0 0 1 2 10]))))

View file

@ -0,0 +1,22 @@
(ns uxbox.tests.main
(:require [cljs.test :as test]
[uxbox.tests.geom-types]
[uxbox.tests.shapes-state]))
(enable-console-print!)
(defn main
[]
(test/run-tests
(test/empty-env)
'uxbox.tests.geom-types
'uxbox.tests.shapes-state
))
(defmethod test/report [:cljs.test/default :end-run-tests]
[m]
(if (test/successful? m)
(set! (.-exitCode js/process) 0)
(set! (.-exitCode js/process) 1)))
(set! *main-cli-fn* main)

View file

@ -0,0 +1,510 @@
(ns uxbox.tests.shapes-state
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer (pprint)]
[uxbox.util.uuid :as uuid]
[uxbox.main.state.shapes :as sh]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Duplicate (one shape)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn constantly-inc
[init]
(let [v (atom init)]
(fn [& args]
(let [result @v]
(swap! v inc)
result))))
;; duplicate shape: duplicate simple shape
(t/deftest duplicate-shapes-test1
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [2 1])
(assoc-in [:shapes-by-id 2] {:id 2 :page 1}))]
(with-redefs [uxbox.util.uuid/random (constantly 2)]
(let [result (sh/duplicate-shapes initial [1])]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))))
;; duplicate shape: duplicate inside group
(t/deftest duplicate-shapes-test2
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :name "1" :page 1
:type :group
:items [2 3]}
2 {:id 2 :name "2" :page 1 :group 1}
3 {:id 3 :name "3" :page 1 :group 1}}}
expected (-> initial
(assoc-in [:shapes-by-id 1 :items] [5 4 2 3])
(assoc-in [:shapes-by-id 4] {:id 4 :name "3" :page 1 :group 1})
(assoc-in [:shapes-by-id 5] {:id 5 :name "2" :page 1 :group 1}))]
(with-redefs [uxbox.util.uuid/random (constantly-inc 4)]
(let [result (sh/duplicate-shapes initial [2 3])]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))))
;; duplicate shape: duplicate mixed bag
(t/deftest duplicate-shapes-test3
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 4]}}
:shapes-by-id {1 {:id 1 :name "1" :page 1
:type :group
:items [2 3]}
2 {:id 2 :name "2" :page 1 :group 1}
3 {:id 3 :name "3" :page 1 :group 1}
4 {:id 4 :name "4" :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [6 5 1 4])
(assoc-in [:shapes-by-id 5] {:id 5 :name "4" :page 1})
(assoc-in [:shapes-by-id 6] {:id 6 :name "3" :page 1}))]
(with-redefs [uxbox.util.uuid/random (constantly-inc 5)]
(let [result (sh/duplicate-shapes initial [3 4])]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))))
;; duplicate shape: duplicate one group
(t/deftest duplicate-shapes-test4
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 3 :page 1 :group 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [3 1])
(assoc-in [:shapes-by-id 3] {:id 3 :page 1
:type :group
:items [4]})
(assoc-in [:shapes-by-id 4] {:id 4 :page 1 :group 3}))]
(with-redefs [uxbox.util.uuid/random (constantly-inc 3)]
(let [result (sh/duplicate-shapes initial [1])]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Drop Shape (drag and drop and sorted)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; drop shape: move shape before other shape
(t/deftest drop-shape-test1
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1}
3 {:id 3 :page 1}}}
expected (assoc-in initial [:pages-by-id 1 :shapes] [3 1 2])
result (sh/drop-shape initial 3 1 :before)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move shape after other shape
(t/deftest drop-shape-test2
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1}
3 {:id 3 :page 1}}}
expected (assoc-in initial [:pages-by-id 1 :shapes] [1 3 2])
result (sh/drop-shape initial 3 1 :after)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move shape before other shape that is part of group.
(t/deftest drop-shape-test3
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 4])
(assoc-in [:shapes-by-id 1 :items] [3 2])
(assoc-in [:shapes-by-id 3 :group] 1))
result (sh/drop-shape initial 3 2 :before)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move shape inside group
(t/deftest drop-shape-test4
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 4])
(assoc-in [:shapes-by-id 1 :items] [2 3])
(assoc-in [:shapes-by-id 3 :group] 1))
result (sh/drop-shape initial 3 1 :inside)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move shape outside of group
(t/deftest drop-shape-test5
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2 3]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 4 3])
(assoc-in [:shapes-by-id 1 :items] [2])
(update-in [:shapes-by-id 3] dissoc :group))
result (sh/drop-shape initial 3 4 :after)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move group inside group
(t/deftest drop-shape-test6
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [3]}
2 {:id 2 :page 1
:type :group
:items [4]}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1])
(assoc-in [:shapes-by-id 1 :items] [3 2])
(assoc-in [:shapes-by-id 2 :group] 1))
result (sh/drop-shape initial 2 3 :after)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move group outside group
(t/deftest drop-shape-test7
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1
:group 1
:type :group
:items [4]}
3 {:id 3 :page 1}
4 {:id 4 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [2 3])
(update-in [:shapes-by-id] dissoc 1)
(update-in [:shapes-by-id 2] dissoc :group))
result (sh/drop-shape initial 2 1 :after)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; drop shape: move shape to neested group
(t/deftest drop-shape-test8
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 5 6]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1
:group 1
:type :group
:items [3 4]}
3 {:id 3 :page 1 :group 2}
4 {:id 4 :page 1 :group 2}
5 {:id 5 :page 1}
6 {:id 6 :page 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 5])
(update-in [:shapes-by-id 2 :items] conj 6)
(update-in [:shapes-by-id 6] assoc :group 2))
result (sh/drop-shape initial 6 4 :after)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
;; drop shape: move shape to neested group
(t/deftest drop-shape-test9
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2 5 6]}
2 {:id 2 :page 1
:group 1
:type :group
:items [3 4]}
3 {:id 3 :page 1 :group 2}
4 {:id 4 :page 1 :group 2}
5 {:id 5 :page 1 :group 1}
6 {:id 6 :page 1 :group 1}}}
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1])
(assoc-in [:shapes-by-id 2 :items] [3 4 6])
(assoc-in [:shapes-by-id 1 :items] [2 5])
(update-in [:shapes-by-id 6] assoc :group 2))
result (sh/drop-shape initial 6 4 :after)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Delete Shape
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; delete shape: delete from page
(t/deftest delete-shape-test1
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
shape (get-in initial [:shapes-by-id 4])
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 3])
(update-in [:shapes-by-id] dissoc 4))
result (sh/dissoc-shape initial shape)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
;; delete shape: delete from group
(t/deftest delete-shape-test2
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
shape (get-in initial [:shapes-by-id 2])
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [3 4])
(update-in [:shapes-by-id] dissoc 2)
(update-in [:shapes-by-id] dissoc 1))
result (sh/dissoc-shape initial shape)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Group Shapes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; group a shape
(t/deftest group-shapes-1
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1}
3 {:id 3 :page 1}}}
expected (-> initial
(assoc-in [:workspace :selected] #{4})
(assoc-in [:pages-by-id 1 :shapes] [1 4 3])
(assoc-in [:shapes-by-id 2 :group] 4)
(assoc-in [:shapes-by-id 4] {:type :group :name "Group 10"
:items [2] :id 4 :page 1}))]
(with-redefs [uxbox.util.uuid/random (constantly 4)
cljs.core/rand-int (constantly 10)]
(let [result (sh/group-shapes initial [2] 1)]
(t/is (= result expected))))))
;; group two shapes
(t/deftest group-shapes-2
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1}
3 {:id 3 :page 1}}}
expected (-> initial
(assoc-in [:workspace :selected] #{4})
(assoc-in [:pages-by-id 1 :shapes] [1 4])
(assoc-in [:shapes-by-id 2 :group] 4)
(assoc-in [:shapes-by-id 3 :group] 4)
(assoc-in [:shapes-by-id 4] {:type :group :name "Group 10"
:items [2 3] :id 4 :page 1}))]
(with-redefs [uxbox.util.uuid/random (constantly 4)
cljs.core/rand-int (constantly 10)]
(let [result (sh/group-shapes initial [2 3] 1)]
(t/is (= result expected))))))
;; group group
(t/deftest group-shapes-3
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1}
3 {:id 3 :page 1 :type :group}}}
expected (-> initial
(assoc-in [:workspace :selected] #{4})
(assoc-in [:pages-by-id 1 :shapes] [1 4])
(assoc-in [:shapes-by-id 2 :group] 4)
(assoc-in [:shapes-by-id 3 :group] 4)
(assoc-in [:shapes-by-id 4] {:type :group :name "Group 10"
:items [2 3] :id 4 :page 1}))]
(with-redefs [uxbox.util.uuid/random (constantly 4)
cljs.core/rand-int (constantly 10)]
(let [result (sh/group-shapes initial [2 3] 1)]
(t/is (= result expected))))))
;; group shapes inside a group
(t/deftest group-shapes-4
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3]}}
:shapes-by-id {1 {:id 1 :page 1}
2 {:id 2 :page 1 :group 3}
3 {:id 3 :page 1 :type :group}}}
expected (-> initial
(assoc-in [:workspace :selected] #{4})
(assoc-in [:pages-by-id 1 :shapes] [1 3])
(assoc-in [:shapes-by-id 2 :group] 4)
(assoc-in [:shapes-by-id 3 :items] [4])
(assoc-in [:shapes-by-id 4] {:type :group :name "Group 10"
:items [2] :id 4 :page 1 :group 3}))]
(with-redefs [uxbox.util.uuid/random (constantly 4)
cljs.core/rand-int (constantly 10)]
(let [result (sh/group-shapes initial [2] 1)]
(t/is (= result expected))))))
;; group shapes in multiple groups
(t/deftest group-shapes-5
(let [initial {:pages-by-id {1 {:id 1 :shapes [3 4]}}
:shapes-by-id {1 {:id 1 :page 1 :group 4}
2 {:id 2 :page 1 :group 3}
3 {:id 3 :page 1 :type :group :items [2]}
4 {:id 4 :page 1 :type :group :imtes [3]}}}
expected (-> initial
(assoc-in [:workspace :selected] #{5})
(assoc-in [:pages-by-id 1 :shapes] [5])
(assoc-in [:shapes-by-id 1 :group] 5)
(assoc-in [:shapes-by-id 2 :group] 5)
(assoc-in [:shapes-by-id 5] {:type :group :name "Group 10"
:items [1 2] :id 5 :page 1})
(update-in [:shapes-by-id] dissoc 3)
(update-in [:shapes-by-id] dissoc 4))]
(with-redefs [uxbox.util.uuid/random (constantly 5)
cljs.core/rand-int (constantly 10)]
(let [result (sh/group-shapes initial [1 2] 1)]
(t/is (= result expected))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Degroups
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; degroup a single group
;; degroup group
(t/deftest degroup-shapes-1
(let [initial {:pages-by-id {1 {:id 1 :shapes [3]}}
:shapes-by-id {1 {:id 1 :page 1 :group 3}
2 {:id 2 :page 1 :group 3}
3 {:id 3 :page 1 :type :group :items [1 2]}}}
expected (-> initial
(assoc-in [:workspace :selected] #{1 2})
(assoc-in [:pages-by-id 1 :shapes] [1 2])
(update-in [:shapes-by-id 1] dissoc :group)
(update-in [:shapes-by-id 2] dissoc :group)
(update-in [:shapes-by-id] dissoc 3))]
(let [result (sh/degroup-shapes initial [3] 1)]
(t/is (= result expected)))))
;; degroup group inside a group
(t/deftest degroup-shapes-2
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1 :type :group :items [2]}
2 {:id 2 :page 1 :type :group :items [3] :group 1}
3 {:id 3 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:workspace :selected] #{3})
(assoc-in [:pages-by-id 1 :shapes] [1])
(update-in [:shapes-by-id] dissoc 2)
(assoc-in [:shapes-by-id 1 :items] [3])
(assoc-in [:shapes-by-id 3 :group] 1))]
(let [result (sh/degroup-shapes initial [2] 1)]
(t/is (= result expected)))))
;; degroup multiple groups not nested
(t/deftest degroup-shapes-3
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2]}}
:shapes-by-id {1 {:id 1 :page 1 :type :group :items [3]}
2 {:id 2 :page 1 :type :group :items [4]}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:workspace :selected] #{3 4})
(assoc-in [:pages-by-id 1 :shapes] [3 4])
(update :shapes-by-id dissoc 1)
(update :shapes-by-id dissoc 2)
(update-in [:shapes-by-id 3] dissoc :group)
(update-in [:shapes-by-id 4] dissoc :group))]
(let [result (sh/degroup-shapes initial [1 2] 1)]
(t/is (= result expected)))))
;; degroup multiple groups nested (child first)
(t/deftest degroup-shapes-4
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1 :type :group :items [2]}
2 {:id 2 :page 1 :type :group :items [3] :group 1}
3 {:id 3 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:workspace :selected] #{3})
(assoc-in [:pages-by-id 1 :shapes] [3])
(update :shapes-by-id dissoc 1)
(update :shapes-by-id dissoc 2)
(update-in [:shapes-by-id 3] dissoc :group))]
(let [result (sh/degroup-shapes initial [2 1] 1)]
(t/is (= result expected)))))
;; degroup multiple groups nested (parent first)
(t/deftest degroup-shapes-5
(let [initial {:pages-by-id {1 {:id 1 :shapes [1]}}
:shapes-by-id {1 {:id 1 :page 1 :type :group :items [2]}
2 {:id 2 :page 1 :type :group :items [3] :group 1}
3 {:id 3 :page 1 :group 2}}}
expected (-> initial
(assoc-in [:workspace :selected] #{3})
(assoc-in [:pages-by-id 1 :shapes] [3])
(update :shapes-by-id dissoc 1)
(update :shapes-by-id dissoc 2)
(update-in [:shapes-by-id 3] dissoc :group))]
(let [result (sh/degroup-shapes initial [1 2] 1)]
(t/is (= result expected)))))