From 97e34d6e28e6fbd52b671a33ecb665c6b4ab6fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 7 May 2024 11:35:01 +0200 Subject: [PATCH] :lipstick: Unify comments --- .../logic/comp_remove_swap_slots_test.cljc | 76 +++++++++++-------- .../logic/component_creation_test.cljc | 8 +- .../logic/components_touched_test.cljc | 51 +++++++------ .../logic/swap_and_reset_test.cljc | 51 ++++++------- 4 files changed, 100 insertions(+), 86 deletions(-) diff --git a/common/test/common_tests/logic/comp_remove_swap_slots_test.cljc b/common/test/common_tests/logic/comp_remove_swap_slots_test.cljc index 2fd559e0c..dcbd5cc48 100644 --- a/common/test/common_tests/logic/comp_remove_swap_slots_test.cljc +++ b/common/test/common_tests/logic/comp_remove_swap_slots_test.cljc @@ -51,12 +51,13 @@ (thf/make-component :b2 :frame-b2))) (t/deftest test-keep-swap-slot-relocating-blue1-to-root - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) + page (thf/current-page file) blue1 (thf/get-shape file :blue1) - ;; ============================== Action ============================== + ;; ==== Action changes (cls/generate-relocate-shapes (pcb/empty-changes nil) (:objects page) #{(:parent-id blue1)} ;; parents @@ -66,10 +67,11 @@ #{(:id blue1)}) ;; ids file' (thf/apply-changes file changes) - ;; ============================== Get ================================= + ;; ==== Get blue1' (thf/get-shape file' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -78,12 +80,12 @@ (t/is (nil? (ctk/get-swap-slot blue1'))))) (t/deftest test-keep-swap-slot-move-blue1-to-root - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) - ;; ============================== Action ============================== + ;; ==== Action changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) #{(:id blue1)} ;; ids uuid/zero ;; frame-id @@ -94,10 +96,11 @@ file' (thf/apply-changes file changes) - ;; ============================== Get ================================= + ;; ==== Get blue1' (thf/get-shape file' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -107,14 +110,14 @@ (t/deftest test-keep-swap-slot-relocating-blue1-to-b2 - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) b2 (thf/get-shape file :frame-b2) - ;; ============================== Action ============================== + ;; ==== Action changes (cls/generate-relocate-shapes (pcb/empty-changes nil) (:objects page) #{(:parent-id blue1)} ;; parents @@ -124,10 +127,11 @@ #{(:id blue1)}) ;; ids file' (thf/apply-changes file changes) - ;; ============================== Get ================================= + ;; ==== Get blue1' (thf/get-shape file' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -136,14 +140,14 @@ (t/is (nil? (ctk/get-swap-slot blue1'))))) (t/deftest test-keep-swap-slot-move-blue1-to-b2 - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) b2 (thf/get-shape file :frame-b2) - ;; ============================== Action ============================== + ;; ==== Action changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) #{(:id blue1)} ;; ids (:id b2) ;; frame-id @@ -154,10 +158,11 @@ file' (thf/apply-changes file changes) - ;; ============================== Get ================================= + ;; ==== Get blue1' (thf/get-shape file' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -166,13 +171,13 @@ (t/is (nil? (ctk/get-swap-slot blue1'))))) (t/deftest test-keep-swap-slot-relocating-yellow-to-root - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) yellow (thf/get-shape file :frame-yellow) - ;; ============================== Action ============================== + ;; ==== Action ;; Move blue1 into yellow changes (cls/generate-relocate-shapes (pcb/empty-changes nil) (:objects page) @@ -196,10 +201,11 @@ #{(:id yellow')}) ;; ids file'' (thf/apply-changes file' changes') - ;; ============================== Get ================================= + ;; ==== Get blue1'' (thf/get-shape file'' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -208,13 +214,14 @@ (t/is (nil? (ctk/get-swap-slot blue1''))))) (t/deftest test-keep-swap-slot-move-yellow-to-root - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) yellow (thf/get-shape file :frame-yellow) - ;; ============================== Action ============================== + ;; ==== Action + ;; Move blue1 into yellow changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) #{(:id blue1)} ;; ids @@ -238,10 +245,11 @@ nil) ;; cell file'' (thf/apply-changes file' changes') - ;; ============================== Get ================================= + ;; ==== Get blue1'' (thf/get-shape file'' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -251,13 +259,14 @@ (t/deftest test-keep-swap-slot-relocating-yellow-to-b2 - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) yellow (thf/get-shape file :frame-yellow) - ;; ============================== Action ============================== + ;; ==== Action + ;; Move blue1 into yellow changes (cls/generate-relocate-shapes (pcb/empty-changes nil) (:objects page) @@ -282,10 +291,11 @@ #{(:id yellow')}) ;; ids file'' (thf/apply-changes file' changes') - ;; ============================== Get ================================= + ;; ==== Get blue1'' (thf/get-shape file'' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) @@ -294,13 +304,14 @@ (t/is (nil? (ctk/get-swap-slot blue1''))))) (t/deftest test-keep-swap-slot-move-yellow-to-b2 - (let [;; ============================== Setup =============================== + (let [;; ==== Setup file (setup-file) page (thf/current-page file) blue1 (thf/get-shape file :blue1) yellow (thf/get-shape file :frame-yellow) - ;; ============================== Action ============================== + ;; ==== Action + ;; Move blue1 into yellow changes (cls/generate-move-shapes-to-frame (pcb/empty-changes nil) #{(:id blue1)} ;; ids @@ -326,10 +337,11 @@ file'' (thf/apply-changes file' changes') - ;; ============================== Get ================================= + ;; ==== Get blue1'' (thf/get-shape file'' :blue1)] - ;; ================================== Check =============================== + ;; ==== Check + ;; blue1 had swap-id before move (t/is (some? (ctk/get-swap-slot blue1))) diff --git a/common/test/common_tests/logic/component_creation_test.cljc b/common/test/common_tests/logic/component_creation_test.cljc index 59ec29806..daf1565f8 100644 --- a/common/test/common_tests/logic/component_creation_test.cljc +++ b/common/test/common_tests/logic/component_creation_test.cljc @@ -15,14 +15,14 @@ (t/use-fixtures :each thi/test-fixture) (t/deftest test-add-component-from-single-shape - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (thf/add-sample-shape :shape1 :type :frame)) page (thf/current-page file) shape1 (thf/get-shape file :shape1) - ;; Action + ;; ==== Action [_ component-id changes] (cll/generate-add-component (pcb/empty-changes) [shape1] @@ -35,11 +35,11 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get component (thf/get-component-by-id file' component-id) root (thf/get-shape-by-id file' (:main-instance-id component))] - ;; Check + ;; ==== Check (t/is (some? component)) (t/is (some? root)) (t/is (= (:component-id root) (:id component))))) diff --git a/common/test/common_tests/logic/components_touched_test.cljc b/common/test/common_tests/logic/components_touched_test.cljc index e20827c1e..d409c8d5f 100644 --- a/common/test/common_tests/logic/components_touched_test.cljc +++ b/common/test/common_tests/logic/components_touched_test.cljc @@ -16,7 +16,7 @@ (t/use-fixtures :each thi/test-fixture) (t/deftest test-touched-when-changing-attribute - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-simple-component-with-copy :component1 :main-root @@ -27,7 +27,7 @@ page (thf/current-page file) copy-root (thf/get-shape file :copy-root) - ;; Action + ;; ==== Action update-fn (fn [shape] (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) @@ -39,13 +39,13 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy-root' (thf/get-shape file' :copy-root) copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root'))) fills' (:fills copy-child') fill' (first fills')] - ;; Check + ;; ==== Check (t/is (= (count fills') 1)) (t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-opacity fill') 1)) @@ -53,7 +53,7 @@ (t/is (= (:touched copy-child') #{:fill-group})))) (t/deftest test-not-touched-when-adding-shape - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-simple-component-with-copy :component1 :main-root @@ -64,7 +64,8 @@ page (thf/current-page file) copy-root (thf/get-shape file :copy-root) - ;; Action + ;; ==== 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. changes (cls/generate-relocate-shapes (pcb/empty-changes) @@ -77,16 +78,16 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy-root' (thf/get-shape file' :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-child') nil)))) (t/deftest test-touched-when-deleting-shape - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-simple-component-with-copy :component1 :main-root @@ -96,7 +97,8 @@ page (thf/current-page file) copy-root (thf/get-shape file :copy-root) - ;; Action + ;; ==== Action + ;; IMPORTANT: as modifying copies structure is now forbidden, this action will not ;; delete the child shape, but hide it (thus setting the visibility group). [_all-parents changes] @@ -109,16 +111,16 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy-root' (thf/get-shape file' :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-child') #{:visibility-group})))) (t/deftest test-not-touched-when-moving-shape - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-component-with-many-children-and-copy :component1 :main-root @@ -130,7 +132,8 @@ copy-root (thf/get-shape file :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 ;; will not have any effect, and so the parent shape won't also be touched. changes (cls/generate-relocate-shapes (pcb/empty-changes) @@ -143,16 +146,16 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy-root' (thf/get-shape file' :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-child') nil)))) (t/deftest test-touched-when-changing-upper - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-nested-component-with-copy :component1 :main1-root @@ -166,7 +169,7 @@ page (thf/current-page file) copy2-root (thf/get-shape file :copy2-root) - ;; Action + ;; ==== Action update-fn (fn [shape] (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) @@ -178,19 +181,19 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy2-root' (thf/get-shape file' :copy2-root) fills' (:fills copy2-root') fill' (first fills')] - ;; Check + ;; ==== Check (t/is (= (count fills') 1)) (t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-opacity fill') 1)) (t/is (= (:touched copy2-root') #{:fill-group})))) (t/deftest test-touched-when-changing-lower - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (tho/add-nested-component-with-copy :component1 :main1-root @@ -204,7 +207,7 @@ page (thf/current-page file) copy2-root (thf/get-shape file :copy2-root) - ;; Action + ;; ==== Action update-fn (fn [shape] (assoc shape :fills (thf/sample-fills-color :fill-color "#fabada"))) @@ -216,13 +219,13 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get copy2-root' (thf/get-shape file' :copy2-root) copy2-child' (thf/get-shape-by-id file' (first (:shapes copy2-root'))) fills' (:fills copy2-child') fill' (first fills')] - ;; Check + ;; ==== Check (t/is (= (count fills') 1)) (t/is (= (:fill-color fill') "#fabada")) (t/is (= (:fill-opacity fill') 1)) diff --git a/common/test/common_tests/logic/swap_and_reset_test.cljc b/common/test/common_tests/logic/swap_and_reset_test.cljc index 535315297..ba9746c3a 100644 --- a/common/test/common_tests/logic/swap_and_reset_test.cljc +++ b/common/test/common_tests/logic/swap_and_reset_test.cljc @@ -19,19 +19,22 @@ ;; Related .penpot file: common/test/cases/swap-and-reset.penpot (t/deftest test-simple-swap - (let [;; Setup - file - (-> (thf/sample-file :file1) - (thc/add-simple-component-with-copy :component-1 :component-1-main-root :component-1-main-child :component-1-copy-root) - (thc/add-simple-component :component-2 :component-2-root :component-2-child)) + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thc/add-simple-component-with-copy :component-1 + :component-1-main-root + :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 (thf/get-component file :component-1) component-2 (thf/get-component file :component-2) page (thf/current-page file) - ;; Action - [new-shape all-parents changes] + ;; ==== Action + [new-shape _all-parents changes] (cll/generate-component-swap (pcb/empty-changes) (:objects page) component-1-copy-root @@ -45,16 +48,16 @@ file' (thf/apply-changes file changes) - ;; Get + ;; ==== Get 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 (= (:id component-2) (:component-id swapped))) (t/is (= (:id file) (:component-file swapped))))) (t/deftest test-swap-nested - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (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)) page (thf/current-page file) - component-1 (thf/get-component file :component-1) component-2 (thf/get-component file :component-2) - component-3 (thf/get-component file :component-3) copy (->> @@ -78,8 +79,8 @@ libraries {(:id file) file} - ;; Action - [new-shape all-parents changes] + ;; ==== Action + [new-shape _all-parents changes] (cll/generate-component-swap (pcb/empty-changes) (:objects page) copy @@ -95,7 +96,7 @@ libraries' {(:id file') file'} page' (thf/current-page file') - ;; Get + ;; ==== Get swapped (thf/get-shape-by-id file' (:id new-shape)) component-1-copy-root (thf/get-shape file' :component-1-copy-root) slot (-> (ctf/find-swap-slot swapped @@ -104,7 +105,7 @@ libraries') (ctk/build-swap-slot-group))] - ;; Check + ;; ==== Check (t/is (not= (:component-id copy) (:component-id swapped))) (t/is (= (:id component-2) (:component-id 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/deftest test-swap-and-reset-override - (let [;; Setup + (let [;; ==== Setup file (-> (thf/sample-file :file1) (thc/add-simple-component :component-1 :component-1-main-root :component-1-main-child) @@ -133,8 +134,8 @@ first (thf/get-shape-by-id file)) - ;; Action - [new-shape all-parents changes-swap] + ;; ==== Action + [new-shape _all-parents changes-swap] (cll/generate-component-swap (pcb/empty-changes) (:objects page) copy @@ -158,17 +159,15 @@ true) file' (thf/apply-changes file changes) - page' (thf/current-page file') - ;; Get + + ;; ==== Get reset (->> (thf/get-shape file' :component-container-instance) :shapes 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 (nil? (ctk/get-swap-slot reset)))))