diff --git a/backend/test/backend_tests/binfile_test.clj b/backend/test/backend_tests/binfile_test.clj index b60357c2d0..8a82249c80 100644 --- a/backend/test/backend_tests/binfile_test.clj +++ b/backend/test/backend_tests/binfile_test.clj @@ -3331,7 +3331,7 @@ (assoc ::bfc/team-id (:default-team-id profile)) (assoc ::bfc/input input))] (case version - 1 (vec (v1/import-files! cfg)) + 1 (:file-ids (v1/import-files! cfg)) 3 (:file-ids (v3/import-files! cfg))))) (defn- import-error diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 1e2b36da72..493a87336d 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -94,6 +94,10 @@ [container shape-id f] (update-in container [:objects shape-id] f)) +(defn get-container-root + [container] + (d/seek #(or (nil? (:parent-id %)) (= (:parent-id %) uuid/zero)) (shapes-seq container))) + (defn get-direct-children [container shape] (map #(get-shape container %) (:shapes shape))) diff --git a/common/test/common_tests/logic/comp_flex_interactions_test.cljc b/common/test/common_tests/logic/comp_flex_interactions_test.cljc index bb30ac8743..e9636d7d67 100644 --- a/common/test/common_tests/logic/comp_flex_interactions_test.cljc +++ b/common/test/common_tests/logic/comp_flex_interactions_test.cljc @@ -10,6 +10,8 @@ [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.logic.libraries :as cll] + [app.common.logic.shapes :as cls] + [app.common.logic.variants :as clv] [app.common.math :as mth] [app.common.test-helpers.components :as thc] [app.common.test-helpers.compositions :as tho] @@ -149,22 +151,12 @@ [file library shape-label new-component-label] (let [shape (ths/get-shape file shape-label) page (thf/current-page file) - keep-props-values (select-keys shape ctk/swap-keep-attrs) libraries {(:id library) library (:id file) file} id-new (:id (thc/get-component library new-component-label)) - [_ _ changes] (cll/generate-component-swap + [_ changes _] (clv/generate-component-swap-in-place (pcb/empty-changes nil (:id page)) - (:objects page) - shape - (:data library) - page - libraries - id-new - 0 - nil - keep-props-values - false)] + page libraries (:data library) shape id-new false)] (thf/apply-changes file changes))) (defn- setup-library-with-absolute-nested-icon @@ -200,13 +192,13 @@ ;; ==== Check (t/is (true? (:layout-item-absolute swapped))) - (t/is (some? (ctk/get-swap-slot swapped))) + (t/is (ctk/swapped? swapped)) (t/is (= (thi/id :icon-b) (:component-id swapped))) - (t/is (some? (ctk/get-swap-slot swapped'))) + (t/is (ctk/swapped? swapped')) (t/is (= (thi/id :icon-b) (:component-id swapped'))) (t/is (true? (:layout-item-absolute swapped'))))) -(t/deftest test-sync-library-propagates-slot-absolute-to-swapped-nested +(t/deftest test-sync-library-propagates-position-absolute-to-swapped-nested (let [;; ==== Setup library (setup-library-with-absolute-nested-icon) file (-> (thf/sample-file :file) @@ -223,7 +215,7 @@ swapped' (ths/get-shape file' :copy-nested-head)] ;; ==== Check - (t/is (some? (ctk/get-swap-slot swapped'))) + (t/is (ctk/swapped? swapped')) (t/is (= (thi/id :icon-b) (:component-id swapped'))) (t/is (not (true? (:layout-item-absolute swapped')))))) @@ -257,7 +249,7 @@ ;; ==== Check (t/is (= margin (:layout-item-margin sibling'))) (t/is (true? (:layout-item-absolute swapped'))) - (t/is (some? (ctk/get-swap-slot swapped'))))) + (t/is (ctk/swapped? swapped')))) (defn- setup-library-with-icon-slot "Library: icon A, icon B, and a flex board whose `:slot` frame holds an diff --git a/frontend/test/frontend_tests/logic/comp_move_swapped_copies_test.cljs b/frontend/test/frontend_tests/logic/comp_move_swapped_copies_test.cljs index 2f650c0ba3..9f38d7fb8f 100644 --- a/frontend/test/frontend_tests/logic/comp_move_swapped_copies_test.cljs +++ b/frontend/test/frontend_tests/logic/comp_move_swapped_copies_test.cljs @@ -872,7 +872,7 @@ (t/is (not (ctk/swapped? copied-blue1'))))))))) -(t/deftest test-keep-inherited-swap-slot-copy-paste-nested-copy-to-root +(t/deftest test-keep-inherited-swap-group-copy-paste-nested-copy-to-root (t/async done (let [;; ==== Setup @@ -934,12 +934,13 @@ ;; ==== Check ;; the copied icon now refers to the icon main, where blue - ;; does not exist, so the copied blue must keep the swap slot - ;; inherited from :blue-copy-title + ;; does not exist, so the copied blue must keep the position + ;; reference inherited from :blue-copy-title and its swap group. (t/is (some? copied-icon')) (t/is (= (:shape-ref copied-icon') (cthi/id :frame-icon))) (t/is (some? copied-blue')) - (t/is (= (ctk/get-swap-slot copied-blue') (cthi/id :red-copy-icon))) + (t/is (= (:shape-ref copied-blue') (cthi/id :red-copy-icon))) + (t/is (ctk/swapped? copied-blue')) ;; the file must be valid after the paste (t/is (nil? errors)))))))) @@ -985,7 +986,7 @@ (t/is (contains? (:touched copied-red') :fill-group)) (t/is (= (:touched red') (:touched copied-red'))))))))) -(t/deftest test-remove-swap-slot-copy-paste-nested-swapped-copy-to-root +(t/deftest test-remove-swap-group-copy-paste-nested-swapped-copy-to-root (t/async done (let [;; ==== Setup (sample file as is) @@ -1014,6 +1015,7 @@ copied-blue' (find-copied-shape blue' page' uuid/zero)] ;; ==== Check - ;; the copied blue has no swap-id + ;; The copied blue refers to its own main and has no swap override. (t/is (some? copied-blue')) - (t/is (nil? (ctk/get-swap-slot copied-blue'))))))))) + (t/is (not (ctk/swapped? copied-blue'))) + (t/is (= (:shape-ref copied-blue') (cthi/id :frame-blue)))))))))