diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index deffb5c805..22f75c87bd 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -223,7 +223,9 @@ (- (:y rect) (:y first-shape) 30)) :prefix prefix :wrapper? (empty? prefix)}) - (generate-move-into $ (set (rest ids)) variant-id 0) + ;; one move per main, in the order of `ids`, so the property values it + ;; generates follow that order + (reduce #(generate-move-into %1 #{%2} variant-id 0) $ (rest ids)) ;; the members in the order of `ids`: the board's children go the other ;; way, and a change of parent at index 0 reverses the shapes it takes (let [children (set (get-in (pcb/get-objects $) [variant-id :shapes])) diff --git a/common/test/common_tests/logic/variants_test.cljc b/common/test/common_tests/logic/variants_test.cljc index 1775b04c31..de9473b70f 100644 --- a/common/test/common_tests/logic/variants_test.cljc +++ b/common/test/common_tests/logic/variants_test.cljc @@ -453,6 +453,28 @@ (t/is (= "Value 3" (:variant-name (ths/get-shape file' :m03)))))) + +(t/deftest test-combine-as-variants-same-name-values-follow-combine-order + ;; The combine order differs from the layer order of the mains + (let [file (-> (thf/sample-file :file1) + (tho/add-simple-component :c01 :m01 :r01 + :root-params {:name "Tag" :x 0 :y 0 :width 100 :height 80}) + (tho/add-simple-component :c02 :m02 :r02 + :root-params {:name "Tag" :x 150 :y 0 :width 100 :height 80}) + (tho/add-simple-component :c03 :m03 :r03 + :root-params {:name "Tag" :x 300 :y 0 :width 100 :height 80})) + page (thf/current-page file) + changes (-> (pcb/empty-changes nil (:id page)) + (pcb/with-objects (:objects page)) + (pcb/with-library-data (:data file)) + (clv/generate-combine-as-variants [(thi/id :m03) (thi/id :m01) (thi/id :m02)] + (uuid/next))) + file' (thf/apply-changes file changes) + values (mapv #(-> (thc/get-component file' %) :variant-properties first :value) + [:c03 :c01 :c02])] + + (t/is (= ["Value 1" "Value 2" "Value 3"] values)))) + (t/deftest test-duplicate-variant-container (let [;; ==== Setup file (-> (thf/sample-file :file1)