diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index 13a382f696..0c19718641 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -339,7 +339,10 @@ ;; We must avoid that destiny frame is inside the component frame (nil? (get component-children (:id %))) ;; We must avoid that destiny frame is inside a copy - (not (ctk/in-component-copy? %)))})) + (not (ctk/in-component-copy? %)) + ;; We must avoid that destiny frame is a variant container, + ;; because their children must be variant mains + (not (ctk/is-variant-container? %)))})) frame (get-shape page frame-id) component-frame (get-component-shape objects frame {:allow-main? true}) diff --git a/common/test/common_tests/logic/variants_test.cljc b/common/test/common_tests/logic/variants_test.cljc index 60133e6355..43cb163c1e 100644 --- a/common/test/common_tests/logic/variants_test.cljc +++ b/common/test/common_tests/logic/variants_test.cljc @@ -303,3 +303,37 @@ (t/is (not (nil? container))) ;; The variant containew is nil after the deletion (t/is (nil? container')))) + + +(t/deftest test-instantiate-component-over-variant-container + ;; When a component is instantiated at a position over a variant container, + ;; the new copy must not become a child of the container (its children can + ;; only be variant mains) + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02)) + container (ths/get-shape file :v01) + page (thf/current-page file) + + ;; ==== Action + ;; Instantiate at a position inside the variant container, without + ;; an explicit parent, so the destiny frame is chosen by position + [new-shape changes] + (cll/generate-instantiate-component (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page))) + (:objects page) + (:id file) + (thi/id :c01) + (gpt/point (:x container) (:y container)) + page + {(:id file) file}) + + file' (thf/apply-changes file changes) + + ;; ==== Get + new-shape' (ths/get-shape-by-id file' (:id new-shape))] + + ;; ==== Check + (thf/validate-file! file') + (t/is (some? new-shape')) + (t/is (not= (:parent-id new-shape') (:id container)))))