From 5cc367f7f20418839cf5ed5688add9b19356da5a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 24 Feb 2016 21:10:30 +0200 Subject: [PATCH] Add more tests to drop-shape function. --- src/uxbox/data/workspace.cljs | 2 +- src/uxbox/state/shapes.cljs | 2 +- test/uxbox/data/workspace_tests.cljs | 128 -------------------- test/uxbox/state/shapes_tests.cljs | 171 +++++++++++++++++++++++++++ 4 files changed, 173 insertions(+), 130 deletions(-) diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 7a9806a9d..d786ca874 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -336,7 +336,7 @@ (reify rs/UpdateEvent (-apply-update [_ state] - (stsh/drop-shape state tid sid loc)))) + (stsh/drop-shape state sid tid loc)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Events (for selected) diff --git a/src/uxbox/state/shapes.cljs b/src/uxbox/state/shapes.cljs index 28c018cbd..2603c64c3 100644 --- a/src/uxbox/state/shapes.cljs +++ b/src/uxbox/state/shapes.cljs @@ -185,7 +185,7 @@ state))) (defn drop-shape - [state tid sid loc] + [state sid tid loc] (if (= tid sid) state (case loc diff --git a/test/uxbox/data/workspace_tests.cljs b/test/uxbox/data/workspace_tests.cljs index 4cf4dd040..1da8a14e8 100644 --- a/test/uxbox/data/workspace_tests.cljs +++ b/test/uxbox/data/workspace_tests.cljs @@ -40,131 +40,3 @@ ;; (pprint expected) ;; (pprint result) (t/is (= result expected)))) - -;; 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]))))) - -;; 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]))))) - -;; 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]))))) - -;; 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]))))) - -;; 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]))))) - -;; 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]))))) diff --git a/test/uxbox/state/shapes_tests.cljs b/test/uxbox/state/shapes_tests.cljs index f60424db9..7f557b22f 100644 --- a/test/uxbox/state/shapes_tests.cljs +++ b/test/uxbox/state/shapes_tests.cljs @@ -91,3 +91,174 @@ ;; (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 (ssh/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 (ssh/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 :builtin/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 (ssh/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 :builtin/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 (ssh/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 :builtin/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 (ssh/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 :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}}} + 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 (ssh/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 :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}}} + 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 (ssh/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 :builtin/group + :items [2]} + 2 {:id 2 :page 1 + :group 1 + :type :builtin/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 (ssh/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 :builtin/group + :items [2 5 6]} + 2 {:id 2 :page 1 + :group 1 + :type :builtin/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 (ssh/drop-shape initial 6 4 :after)] + (pprint expected) + (pprint result) + (t/is (= result expected))))