0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-12 06:51:23 -05:00

Add delete shape tests.

And general test format change.
This commit is contained in:
Andrey Antukh 2016-02-03 17:19:42 +02:00
parent aaf27ed6a8
commit 615aeea576

View file

@ -4,127 +4,169 @@
[uxbox.rstore :as rs]
[uxbox.data.workspace :as dw]))
(t/deftest drop-shape-test
(t/testing "case 1: move shape before other shape"
(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])
event (dw/drop-shape 3 1 :before)
result (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; 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 :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/delete-shape 4)
expected (-> initial
(assoc-in [:pages-by-id 1 :shapes] [1 3])
(update-in [:shapes-by-id] dissoc 4))
result (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
(t/testing "case 2: move shape after other shape"
(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])
event (dw/drop-shape 3 1 :after)
result (rs/-apply-update event initial)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; 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 :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/delete-shape 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 (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))))
(t/testing "case 3: move shape before other shape that is part of group."
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 2 :before)
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 (rs/-apply-update event initial)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
;; 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])
event (dw/drop-shape 3 1 :before)
result (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
(t/testing "case 4: move shape inside group"
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 1 :inside)
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 (rs/-apply-update event initial)]
;; (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])
event (dw/drop-shape 3 1 :after)
result (rs/-apply-update event initial)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
(t/testing "case 5: move shape outside of group"
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 4]}}
:shapes-by-id {1 {:id 1 :page 1
:type :builtin/group
:items [2 3]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 4 :after)
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 (rs/-apply-update event initial)]
(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 :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 2 :before)
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 (rs/-apply-update event initial)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
(t/testing "case 6: move group inside group"
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 2]}}
:shapes-by-id {1 {:id 1 :page 1
:type :builtin/group
:items [3]}
2 {:id 2 :page 1
:type :builtin/group
:items [4]}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1 :group 2}}}
event (dw/drop-shape 2 3 :after)
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))
;; 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 :builtin/group
:items [2]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 1 :inside)
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 (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
result (rs/-apply-update event initial)]
;; (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 :builtin/group
:items [2 3]}
2 {:id 2 :page 1 :group 1}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1}}}
event (dw/drop-shape 3 4 :after)
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 (rs/-apply-update event initial)]
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))
(t/testing "case 7: move group outside group"
(let [initial {:pages-by-id {1 {:id 1 :shapes [1 3]}}
:shapes-by-id {1 {:id 1 :page 1
:type :builtin/group
:items [2]}
2 {:id 2 :page 1
:group 1
:type :builtin/group
:items [4]}
3 {:id 3 :page 1}
4 {:id 4 :page 1 :group 2}}}
event (dw/drop-shape 2 1 :after)
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 (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(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 :builtin/group
:items [3]}
2 {:id 2 :page 1
:type :builtin/group
:items [4]}
3 {:id 3 :page 1 :group 1}
4 {:id 4 :page 1 :group 2}}}
event (dw/drop-shape 2 3 :after)
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 (rs/-apply-update event initial)]
;; (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 :builtin/group
:items [2]}
2 {:id 2 :page 1
:group 1
:type :builtin/group
:items [4]}
3 {:id 3 :page 1}
4 {:id 4 :page 1 :group 2}}}
event (dw/drop-shape 2 1 :after)
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 (rs/-apply-update event initial)]
;; (pprint expected)
;; (pprint result)
(t/is (= result expected))
(t/is (vector? (get-in result [:pages-by-id 1 :shapes])))))