📎 Restore migration and test compatibility after rebase

Keep the container root helper used by the main-instance name migration.
Adapt imported-file ids and component swap tests to the current APIs, and
check copied swaps through their position refs and swap groups.

AI-assisted-by: gpt-6
This commit is contained in:
alonso.torres 2026-10-27 15:22:28 +01:00
parent a88f53874d
commit c7e8ff8d47
4 changed files with 23 additions and 25 deletions

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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)))))))))