♻️ Unify move shape on workspace and relocate on layers panel

This commit is contained in:
Pablo Alba
2024-05-27 17:33:55 +02:00
committed by Andrés Moya
parent 2982dde7df
commit 018464aedf
9 changed files with 317 additions and 527 deletions

View File

@@ -61,41 +61,12 @@
blue1 (ths/get-shape file :blue1)
;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
blue1' (ths/get-shape file' :blue1)]
;; ==== Check
;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1)))
;; blue1 has not swap-id after move
(t/is (some? blue1'))
(t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-remove-swap-slot-move-blue1-to-root
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue1 (ths/get-shape file :blue1)
;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
uuid/zero ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
@@ -111,7 +82,6 @@
(t/is (some? blue1'))
(t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-remove-swap-slot-relocating-blue1-to-b2
(let [;; ==== Setup
file (setup-file)
@@ -121,43 +91,12 @@
;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
blue1' (ths/get-shape file' :blue1)]
;; ==== Check
;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1)))
;; blue1 has not swap-id after move
(t/is (some? blue1'))
(t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-remove-swap-slot-move-blue1-to-b2
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue1 (ths/get-shape file :blue1)
b2 (ths/get-shape file :frame-b2)
;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
(:id b2) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
@@ -182,26 +121,26 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
page' (thf/current-page file')
yellow' (ths/get-shape file' :frame-yellow)
;; Move yellow into root
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page')
#{(:parent-id yellow')} ;; parents
uuid/zero ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
uuid/zero ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
file'' (thf/apply-changes file' changes')
;; ==== Get
@@ -216,50 +155,6 @@
(t/is (some? blue1''))
(t/is (nil? (ctk/get-swap-slot blue1'')))))
(t/deftest test-remove-swap-slot-move-yellow-to-root
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue1 (ths/get-shape file :blue1)
yellow (ths/get-shape file :frame-yellow)
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
(:id yellow) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
file' (thf/apply-changes file changes)
page' (thf/current-page file')
yellow' (ths/get-shape file' :frame-yellow)
;; Move yellow into root
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id yellow')} ;; ids
uuid/zero ;; frame-id
(:id page') ;; page-id
(:objects page') ;; objects
0 ;; drop-index
nil) ;; cell
file'' (thf/apply-changes file' changes')
;; ==== Get
blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check
;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1)))
;; blue1 has not swap-id after move
(t/is (some? blue1''))
(t/is (nil? (ctk/get-swap-slot blue1'')))))
(t/deftest test-remove-swap-slot-relocating-yellow-to-b2
(let [;; ==== Setup
file (setup-file)
@@ -269,13 +164,13 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
page' (thf/current-page file')
@@ -283,57 +178,12 @@
b2' (ths/get-shape file' :frame-b2)
;; Move yellow into b2
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page')
#{(:parent-id yellow')} ;; parents
(:id b2') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
file'' (thf/apply-changes file' changes')
;; ==== Get
blue1'' (ths/get-shape file'' :blue1)]
;; ==== Check
;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1)))
;; blue1 has not swap-id after move
(t/is (some? blue1''))
(t/is (nil? (ctk/get-swap-slot blue1'')))))
(t/deftest test-remove-swap-slot-move-yellow-to-b2
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue1 (ths/get-shape file :blue1)
yellow (ths/get-shape file :frame-yellow)
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
(:id yellow) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
file' (thf/apply-changes file changes)
page' (thf/current-page file')
yellow' (ths/get-shape file' :frame-yellow)
b2' (ths/get-shape file' :frame-b2)
;; Move yellow into b2
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id yellow')} ;; ids
(:id b2') ;; frame-id
(:id page') ;; page-id
(:objects page') ;; objects
0 ;; drop-index
nil) ;; cell
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
(:id b2') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id yellow')}) ;; ids
file'' (thf/apply-changes file' changes')
@@ -404,13 +254,12 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
(:id yellow) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
page' (thf/current-page file')
@@ -459,13 +308,13 @@
blue1 (ths/get-shape file :blue1)
;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
(:parent-id blue1) ;; parent-id
(:id page) ;; page-id
2 ;; to-index
#{(:id blue1)}) ;; ids
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:parent-id blue1) ;; parent-id
(:id page) ;; page-id
2 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
@@ -489,13 +338,12 @@
;; ==== Action
;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids
(:id yellow) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
@@ -503,13 +351,12 @@
page' (thf/current-page file')
blue1' (ths/get-shape file' :blue1)
b1' (ths/get-shape file' :frame-b1)
changes' (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1')} ;; ids
(:id b1') ;; frame-id
(:id page') ;; page-id
(:objects page') ;; objects
0 ;; drop-index
nil) ;; cell
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
(:id b1') ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1')}) ;; ids
file'' (thf/apply-changes file' changes')
@@ -535,13 +382,13 @@
;; ==== Action
;; Relocate blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id blue1)} ;; parents
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id yellow) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes)
@@ -549,13 +396,13 @@
page' (thf/current-page file')
blue1' (ths/get-shape file' :blue1)
b1' (ths/get-shape file' :frame-b1)
changes' (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page')
#{(:parent-id blue1')} ;; parents
(:id b1') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id blue1')}) ;; ids
changes' (cls/generate-relocate (pcb/empty-changes nil)
(:objects page')
(:id b1') ;; parent-id
(:id page') ;; page-id
0 ;; to-index
#{(:id blue1')}) ;; ids
file'' (thf/apply-changes file' changes')
@@ -581,43 +428,12 @@
green-copy (ths/get-shape file :green-copy)
;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id green-copy)} ;; parents
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
blue2' (ths/get-shape file' :blue2)]
;; ==== Check
;; blue2 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue2)))
;; blue1still has swap-id after move
(t/is (some? blue2'))
(t/is (some? (ctk/get-swap-slot blue2')))))
(t/deftest test-remove-swap-slot-moving-green-copy-to-root
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue2 (ths/get-shape file :blue2)
green-copy (ths/get-shape file :green-copy)
;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id green-copy)} ;; ids
uuid/zero ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids
file' (thf/apply-changes file changes)
@@ -633,7 +449,6 @@
(t/is (some? blue2'))
(t/is (some? (ctk/get-swap-slot blue2')))))
(t/deftest test-remove-swap-slot-relocating-green-copy-to-b2
(let [;; ==== Setup
file (setup-file)
@@ -644,44 +459,12 @@
b2 (ths/get-shape file :frame-b2)
;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page)
#{(:parent-id green-copy)} ;; parents
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
blue2' (ths/get-shape file' :blue2)]
;; ==== Check
;; blue2 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue2)))
;; blue1still has swap-id after move
(t/is (some? blue2'))
(t/is (some? (ctk/get-swap-slot blue2')))))
(t/deftest test-remove-swap-slot-moving-green-copy-to-b2
(let [;; ==== Setup
file (setup-file)
page (thf/current-page file)
blue2 (ths/get-shape file :blue2)
green-copy (ths/get-shape file :green-copy)
b2 (ths/get-shape file :frame-b2)
;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id green-copy)} ;; ids
(:id b2) ;; frame-id
(:id page) ;; page-id
(:objects page) ;; objects
0 ;; drop-index
nil) ;; cell
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id b2) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id green-copy)}) ;; ids
file' (thf/apply-changes file changes)
@@ -697,7 +480,6 @@
(t/is (some? blue2'))
(t/is (some? (ctk/get-swap-slot blue2')))))
(t/deftest test-remove-swap-slot-duplicating-green-copy
(let [;; ==== Setup
file (setup-file)

View File

@@ -136,13 +136,13 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-root)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
@@ -231,13 +231,13 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-child1)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)

View File

@@ -196,13 +196,15 @@
main-root (ths/get-shape file :main-root)
;; ==== Action
changes1 (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id main-root)} ; parents
(thi/id :main-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
changes1 (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :main-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
updated-file (thf/apply-changes file changes1)
@@ -294,13 +296,13 @@
main-child1 (ths/get-shape file :main-child1)
;; ==== Action
changes1 (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id main-child1)} ; parents
(thi/id :main-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id main-child1)}) ; ids
changes1 (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :main-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id main-child1)}) ; ids
updated-file (thf/apply-changes file changes1)

View File

@@ -112,13 +112,13 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-root)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
file' (thf/apply-changes file changes)
@@ -187,13 +187,13 @@
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-child1)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids
changes (cls/generate-relocate (pcb/empty-changes)
(:objects page)
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids
file' (thf/apply-changes file changes)

View File

@@ -0,0 +1,84 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.logic.move-shapes-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.logic.shapes :as cls]
[app.common.test-helpers.compositions :as tho]
[app.common.test-helpers.files :as thf]
[app.common.test-helpers.ids-map :as thi]
[app.common.test-helpers.shapes :as ths]
[app.common.uuid :as uuid]
[clojure.test :as t]))
(t/use-fixtures :each thi/test-fixture)
(t/deftest test-relocate-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-frame :frame-to-move)
(tho/add-frame :frame-parent))
page (thf/current-page file)
frame-to-move (ths/get-shape file :frame-to-move)
frame-parent (ths/get-shape file :frame-parent)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
(:id frame-parent) ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id frame-to-move)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
frame-to-move' (ths/get-shape file' :frame-to-move)
frame-parent' (ths/get-shape file' :frame-parent)]
;; ==== Check
;; frame-to-move has moved
(t/is (= (:parent-id frame-to-move) uuid/zero))
(t/is (= (:parent-id frame-to-move') (:id frame-parent')))))
(t/deftest test-relocate-shape-out-of-group
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-frame :frame-1)
(tho/add-group :group-1 :parent-label :frame-1)
(ths/add-sample-shape :circle-1 :parent-label :group-1))
page (thf/current-page file)
circle (ths/get-shape file :circle-1)
group (ths/get-shape file :group-1)
;; ==== Action
changes (cls/generate-relocate (pcb/empty-changes nil)
(:objects page)
uuid/zero ;; parent-id
(:id page) ;; page-id
0 ;; to-index
#{(:id circle)}) ;; ids
file' (thf/apply-changes file changes)
;; ==== Get
circle' (ths/get-shape file' :circle-1)
group' (ths/get-shape file' :group-1)]
;; ==== Check
;; the circle has moved, and the group is deleted
(t/is (= (:parent-id circle) (:id group)))
(t/is (= (:parent-id circle') uuid/zero))
(t/is group)
(t/is (nil? group'))))