💄 Unify comments

This commit is contained in:
Andrés Moya 2024-05-07 11:35:01 +02:00
parent b68bc9a08c
commit 97e34d6e28
4 changed files with 100 additions and 86 deletions

View file

@ -51,12 +51,13 @@
(thf/make-component :b2 :frame-b2))) (thf/make-component :b2 :frame-b2)))
(t/deftest test-keep-swap-slot-relocating-blue1-to-root (t/deftest test-keep-swap-slot-relocating-blue1-to-root
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
;; ============================== Action ============================== ;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page) (:objects page)
#{(:parent-id blue1)} ;; parents #{(:parent-id blue1)} ;; parents
@ -66,10 +67,11 @@
#{(:id blue1)}) ;; ids #{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ============================== Get ================================= ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (thf/get-shape file' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -78,12 +80,12 @@
(t/is (nil? (ctk/get-swap-slot blue1'))))) (t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-keep-swap-slot-move-blue1-to-root (t/deftest test-keep-swap-slot-move-blue1-to-root
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
;; ============================== Action ============================== ;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
uuid/zero ;; frame-id uuid/zero ;; frame-id
@ -94,10 +96,11 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ============================== Get ================================= ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (thf/get-shape file' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -107,14 +110,14 @@
(t/deftest test-keep-swap-slot-relocating-blue1-to-b2 (t/deftest test-keep-swap-slot-relocating-blue1-to-b2
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
b2 (thf/get-shape file :frame-b2) b2 (thf/get-shape file :frame-b2)
;; ============================== Action ============================== ;; ==== Action
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page) (:objects page)
#{(:parent-id blue1)} ;; parents #{(:parent-id blue1)} ;; parents
@ -124,10 +127,11 @@
#{(:id blue1)}) ;; ids #{(:id blue1)}) ;; ids
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ============================== Get ================================= ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (thf/get-shape file' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -136,14 +140,14 @@
(t/is (nil? (ctk/get-swap-slot blue1'))))) (t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-keep-swap-slot-move-blue1-to-b2 (t/deftest test-keep-swap-slot-move-blue1-to-b2
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
b2 (thf/get-shape file :frame-b2) b2 (thf/get-shape file :frame-b2)
;; ============================== Action ============================== ;; ==== Action
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
(:id b2) ;; frame-id (:id b2) ;; frame-id
@ -154,10 +158,11 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; ============================== Get ================================= ;; ==== Get
blue1' (thf/get-shape file' :blue1)] blue1' (thf/get-shape file' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -166,13 +171,13 @@
(t/is (nil? (ctk/get-swap-slot blue1'))))) (t/is (nil? (ctk/get-swap-slot blue1')))))
(t/deftest test-keep-swap-slot-relocating-yellow-to-root (t/deftest test-keep-swap-slot-relocating-yellow-to-root
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (thf/get-shape file :frame-yellow)
;; ============================== Action ============================== ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page) (:objects page)
@ -196,10 +201,11 @@
#{(:id yellow')}) ;; ids #{(:id yellow')}) ;; ids
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ============================== Get ================================= ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (thf/get-shape file'' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -208,13 +214,14 @@
(t/is (nil? (ctk/get-swap-slot blue1''))))) (t/is (nil? (ctk/get-swap-slot blue1'')))))
(t/deftest test-keep-swap-slot-move-yellow-to-root (t/deftest test-keep-swap-slot-move-yellow-to-root
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (thf/get-shape file :frame-yellow)
;; ============================== Action ============================== ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
@ -238,10 +245,11 @@
nil) ;; cell nil) ;; cell
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ============================== Get ================================= ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (thf/get-shape file'' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -251,13 +259,14 @@
(t/deftest test-keep-swap-slot-relocating-yellow-to-b2 (t/deftest test-keep-swap-slot-relocating-yellow-to-b2
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (thf/get-shape file :frame-yellow)
;; ============================== Action ============================== ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-relocate-shapes (pcb/empty-changes nil) changes (cls/generate-relocate-shapes (pcb/empty-changes nil)
(:objects page) (:objects page)
@ -282,10 +291,11 @@
#{(:id yellow')}) ;; ids #{(:id yellow')}) ;; ids
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ============================== Get ================================= ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (thf/get-shape file'' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))
@ -294,13 +304,14 @@
(t/is (nil? (ctk/get-swap-slot blue1''))))) (t/is (nil? (ctk/get-swap-slot blue1'')))))
(t/deftest test-keep-swap-slot-move-yellow-to-b2 (t/deftest test-keep-swap-slot-move-yellow-to-b2
(let [;; ============================== Setup =============================== (let [;; ==== Setup
file (setup-file) file (setup-file)
page (thf/current-page file) page (thf/current-page file)
blue1 (thf/get-shape file :blue1) blue1 (thf/get-shape file :blue1)
yellow (thf/get-shape file :frame-yellow) yellow (thf/get-shape file :frame-yellow)
;; ============================== Action ============================== ;; ==== Action
;; Move blue1 into yellow ;; Move blue1 into yellow
changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil)
#{(:id blue1)} ;; ids #{(:id blue1)} ;; ids
@ -326,10 +337,11 @@
file'' (thf/apply-changes file' changes') file'' (thf/apply-changes file' changes')
;; ============================== Get ================================= ;; ==== Get
blue1'' (thf/get-shape file'' :blue1)] blue1'' (thf/get-shape file'' :blue1)]
;; ================================== Check =============================== ;; ==== Check
;; blue1 had swap-id before move ;; blue1 had swap-id before move
(t/is (some? (ctk/get-swap-slot blue1))) (t/is (some? (ctk/get-swap-slot blue1)))

View file

@ -15,14 +15,14 @@
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
(t/deftest test-add-component-from-single-shape (t/deftest test-add-component-from-single-shape
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(thf/add-sample-shape :shape1 :type :frame)) (thf/add-sample-shape :shape1 :type :frame))
page (thf/current-page file) page (thf/current-page file)
shape1 (thf/get-shape file :shape1) shape1 (thf/get-shape file :shape1)
;; Action ;; ==== Action
[_ component-id changes] [_ component-id changes]
(cll/generate-add-component (pcb/empty-changes) (cll/generate-add-component (pcb/empty-changes)
[shape1] [shape1]
@ -35,11 +35,11 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
component (thf/get-component-by-id file' component-id) component (thf/get-component-by-id file' component-id)
root (thf/get-shape-by-id file' (:main-instance-id component))] root (thf/get-shape-by-id file' (:main-instance-id component))]
;; Check ;; ==== Check
(t/is (some? component)) (t/is (some? component))
(t/is (some? root)) (t/is (some? root))
(t/is (= (:component-id root) (:id component))))) (t/is (= (:component-id root) (:id component)))))

View file

@ -16,7 +16,7 @@
(t/use-fixtures :each thi/test-fixture) (t/use-fixtures :each thi/test-fixture)
(t/deftest test-touched-when-changing-attribute (t/deftest test-touched-when-changing-attribute
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
@ -27,7 +27,7 @@
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (thf/get-shape file :copy-root)
;; Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada")))
@ -39,13 +39,13 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root'))) copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child') fills' (:fills copy-child')
fill' (first fills')] fill' (first fills')]
;; Check ;; ==== Check
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
@ -53,7 +53,7 @@
(t/is (= (:touched copy-child') #{:fill-group})))) (t/is (= (:touched copy-child') #{:fill-group}))))
(t/deftest test-not-touched-when-adding-shape (t/deftest test-not-touched-when-adding-shape
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
@ -64,7 +64,8 @@
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (thf/get-shape file :copy-root)
;; Action ;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action ;; 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. ;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes) changes (cls/generate-relocate-shapes (pcb/empty-changes)
@ -77,16 +78,16 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))]
;; Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
(t/deftest test-touched-when-deleting-shape (t/deftest test-touched-when-deleting-shape
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1 (tho/add-simple-component-with-copy :component1
:main-root :main-root
@ -96,7 +97,8 @@
page (thf/current-page file) page (thf/current-page file)
copy-root (thf/get-shape file :copy-root) copy-root (thf/get-shape file :copy-root)
;; Action ;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action will not ;; IMPORTANT: as modifying copies structure is now forbidden, this action will not
;; delete the child shape, but hide it (thus setting the visibility group). ;; delete the child shape, but hide it (thus setting the visibility group).
[_all-parents changes] [_all-parents changes]
@ -109,16 +111,16 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))]
;; Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') #{:visibility-group})))) (t/is (= (:touched copy-child') #{:visibility-group}))))
(t/deftest test-not-touched-when-moving-shape (t/deftest test-not-touched-when-moving-shape
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-component-with-many-children-and-copy :component1 (tho/add-component-with-many-children-and-copy :component1
:main-root :main-root
@ -130,7 +132,8 @@
copy-root (thf/get-shape file :copy-root) copy-root (thf/get-shape file :copy-root)
copy-child1 (thf/get-shape-by-id file (first (:shapes copy-root))) copy-child1 (thf/get-shape-by-id file (first (:shapes copy-root)))
;; Action ;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action ;; 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. ;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes) changes (cls/generate-relocate-shapes (pcb/empty-changes)
@ -143,16 +146,16 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy-root' (thf/get-shape file' :copy-root) copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))] copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))]
;; Check ;; ==== Check
(t/is (= (:touched copy-root') nil)) (t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil)))) (t/is (= (:touched copy-child') nil))))
(t/deftest test-touched-when-changing-upper (t/deftest test-touched-when-changing-upper
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-nested-component-with-copy :component1 (tho/add-nested-component-with-copy :component1
:main1-root :main1-root
@ -166,7 +169,7 @@
page (thf/current-page file) page (thf/current-page file)
copy2-root (thf/get-shape file :copy2-root) copy2-root (thf/get-shape file :copy2-root)
;; Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada")))
@ -178,19 +181,19 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy2-root' (thf/get-shape file' :copy2-root) copy2-root' (thf/get-shape file' :copy2-root)
fills' (:fills copy2-root') fills' (:fills copy2-root')
fill' (first fills')] fill' (first fills')]
;; Check ;; ==== Check
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy2-root') #{:fill-group})))) (t/is (= (:touched copy2-root') #{:fill-group}))))
(t/deftest test-touched-when-changing-lower (t/deftest test-touched-when-changing-lower
(let [;; Setup (let [;; ==== Setup
file (-> (thf/sample-file :file1) file (-> (thf/sample-file :file1)
(tho/add-nested-component-with-copy :component1 (tho/add-nested-component-with-copy :component1
:main1-root :main1-root
@ -204,7 +207,7 @@
page (thf/current-page file) page (thf/current-page file)
copy2-root (thf/get-shape file :copy2-root) copy2-root (thf/get-shape file :copy2-root)
;; Action ;; ==== Action
update-fn (fn [shape] update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada")))
@ -216,13 +219,13 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
copy2-root' (thf/get-shape file' :copy2-root) copy2-root' (thf/get-shape file' :copy2-root)
copy2-child' (thf/get-shape-by-id file' (first (:shapes copy2-root'))) copy2-child' (thf/get-shape-by-id file' (first (:shapes copy2-root')))
fills' (:fills copy2-child') fills' (:fills copy2-child')
fill' (first fills')] fill' (first fills')]
;; Check ;; ==== Check
(t/is (= (count fills') 1)) (t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1)) (t/is (= (:fill-opacity fill') 1))

View file

@ -19,19 +19,22 @@
;; Related .penpot file: common/test/cases/swap-and-reset.penpot ;; Related .penpot file: common/test/cases/swap-and-reset.penpot
(t/deftest test-simple-swap (t/deftest test-simple-swap
(let [;; Setup (let [;; ==== Setup
file file (-> (thf/sample-file :file1)
(-> (thf/sample-file :file1) (thc/add-simple-component-with-copy :component-1
(thc/add-simple-component-with-copy :component-1 :component-1-main-root :component-1-main-child :component-1-copy-root) :component-1-main-root
(thc/add-simple-component :component-2 :component-2-root :component-2-child)) :component-1-main-child
:component-1-copy-root)
(thc/add-simple-component :component-2
:component-2-root
:component-2-child))
component-1-copy-root (thf/get-shape file :component-1-copy-root) component-1-copy-root (thf/get-shape file :component-1-copy-root)
component-1 (thf/get-component file :component-1)
component-2 (thf/get-component file :component-2) component-2 (thf/get-component file :component-2)
page (thf/current-page file) page (thf/current-page file)
;; Action ;; ==== Action
[new-shape all-parents changes] [new-shape _all-parents changes]
(cll/generate-component-swap (pcb/empty-changes) (cll/generate-component-swap (pcb/empty-changes)
(:objects page) (:objects page)
component-1-copy-root component-1-copy-root
@ -45,16 +48,16 @@
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
;; Get ;; ==== Get
swapped (thf/get-shape-by-id file' (:id new-shape))] swapped (thf/get-shape-by-id file' (:id new-shape))]
;; Check ;; ==== Check
(t/is (not= (:component-id component-1-copy-root) (:component-id swapped))) (t/is (not= (:component-id component-1-copy-root) (:component-id swapped)))
(t/is (= (:id component-2) (:component-id swapped))) (t/is (= (:id component-2) (:component-id swapped)))
(t/is (= (:id file) (:component-file swapped))))) (t/is (= (:id file) (:component-file swapped)))))
(t/deftest test-swap-nested (t/deftest test-swap-nested
(let [;; Setup (let [;; ==== Setup
file file
(-> (thf/sample-file :file1) (-> (thf/sample-file :file1)
(thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child) (thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child)
@ -65,9 +68,7 @@
(thc/add-simple-component :component-2 :component-2-main-root :component-2-main-child)) (thc/add-simple-component :component-2 :component-2-main-root :component-2-main-child))
page (thf/current-page file) page (thf/current-page file)
component-1 (thf/get-component file :component-1)
component-2 (thf/get-component file :component-2) component-2 (thf/get-component file :component-2)
component-3 (thf/get-component file :component-3)
copy copy
(->> (->>
@ -78,8 +79,8 @@
libraries {(:id file) file} libraries {(:id file) file}
;; Action ;; ==== Action
[new-shape all-parents changes] [new-shape _all-parents changes]
(cll/generate-component-swap (pcb/empty-changes) (cll/generate-component-swap (pcb/empty-changes)
(:objects page) (:objects page)
copy copy
@ -95,7 +96,7 @@
libraries' {(:id file') file'} libraries' {(:id file') file'}
page' (thf/current-page file') page' (thf/current-page file')
;; Get ;; ==== Get
swapped (thf/get-shape-by-id file' (:id new-shape)) swapped (thf/get-shape-by-id file' (:id new-shape))
component-1-copy-root (thf/get-shape file' :component-1-copy-root) component-1-copy-root (thf/get-shape file' :component-1-copy-root)
slot (-> (ctf/find-swap-slot swapped slot (-> (ctf/find-swap-slot swapped
@ -104,7 +105,7 @@
libraries') libraries')
(ctk/build-swap-slot-group))] (ctk/build-swap-slot-group))]
;; Check ;; ==== Check
(t/is (not= (:component-id copy) (:component-id swapped))) (t/is (not= (:component-id copy) (:component-id swapped)))
(t/is (= (:id component-2) (:component-id swapped))) (t/is (= (:id component-2) (:component-id swapped)))
(t/is (= (:id file) (:component-file swapped))) (t/is (= (:id file) (:component-file swapped)))
@ -112,7 +113,7 @@
(t/is (= (ctk/get-swap-slot swapped) (:id component-1-copy-root))))) (t/is (= (ctk/get-swap-slot swapped) (:id component-1-copy-root)))))
(t/deftest test-swap-and-reset-override (t/deftest test-swap-and-reset-override
(let [;; Setup (let [;; ==== Setup
file file
(-> (thf/sample-file :file1) (-> (thf/sample-file :file1)
(thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child) (thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child)
@ -133,8 +134,8 @@
first first
(thf/get-shape-by-id file)) (thf/get-shape-by-id file))
;; Action ;; ==== Action
[new-shape all-parents changes-swap] [new-shape _all-parents changes-swap]
(cll/generate-component-swap (pcb/empty-changes) (cll/generate-component-swap (pcb/empty-changes)
(:objects page) (:objects page)
copy copy
@ -158,17 +159,15 @@
true) true)
file' (thf/apply-changes file changes) file' (thf/apply-changes file changes)
page' (thf/current-page file')
;; Get ;; ==== Get
reset reset
(->> (->>
(thf/get-shape file' :component-container-instance) (thf/get-shape file' :component-container-instance)
:shapes :shapes
first first
(thf/get-shape-by-id file')) (thf/get-shape-by-id file'))]
component-1-copy-root (thf/get-shape file' :component-1-copy-root)] ;; ==== Check
;; Check
(t/is (= (:id component-1) (:component-id reset))) (t/is (= (:id component-1) (:component-id reset)))
(t/is (nil? (ctk/get-swap-slot reset))))) (t/is (nil? (ctk/get-swap-slot reset)))))