From f2c026dd5d368fab2f3d93b5d69d4a0658edfbf0 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Wed, 30 Sep 2026 16:09:13 +0200 Subject: [PATCH] :wrench: Validate shapes after reordering variant properties generate-reorder-variant-poperties now validates the variant container when the reorder changes something. All the components of the variant change, so validating the container checks every main instance and that all of them keep the same order of properties. A reorder that changes nothing still returns the same changes, with no validation. Check with thf/validates-shapes-last? that the function validates the expected page and container. AI-assisted-by: claude-opus-5-5 --- .../app/common/logic/variant_properties.cljc | 45 ++++++++++++------- .../logic/variant_properties_test.cljc | 26 +++++++++-- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index ad937ac5a0..f38b357167 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -135,22 +135,35 @@ changes (let [data (pcb/get-library-data changes) objects (pcb/get-objects changes) - related-components (cfv/find-variant-components data objects variant-id)] - (reduce (fn [changes component] - (let [props (:variant-properties component) - props' (d/reorder props from-pos to-space-between-pos) - main-id (:main-instance-id component) - name (ctv/properties-to-name props')] - (if (not= props props') - (-> changes - (pcb/update-component (:id component) - #(assoc % :variant-properties props') - {:apply-changes-local-library? true}) - (pcb/update-shapes [main-id] - #(assoc % :variant-name name))) - changes))) - changes - related-components)))) + related-components (cfv/find-variant-components data objects variant-id) + + changes' (reduce (fn [changes component] + (let [props (:variant-properties component) + props' (d/reorder props from-pos to-space-between-pos) + main-id (:main-instance-id component) + name (ctv/properties-to-name props')] + (if (not= props props') + (-> changes + (pcb/update-component (:id component) + #(assoc % :variant-properties props') + {:apply-changes-local-library? true}) + (pcb/update-shapes [main-id] + #(assoc % :variant-name name))) + changes))) + changes + related-components)] + + ;; Nothing to validate if the order did not change + (if (identical? changes changes') + changes + ;; All the components of the variant change, so validate the + ;; container, which checks every main instance and that all of them + ;; keep the same order of properties + (pcb/validate-shapes changes' + (pcb/get-page-id changes') + [variant-id] + (str "generate-reorder-variant-poperties: " variant-id + " from: " from-pos " to: " to-space-between-pos)))))) (defn generate-add-new-property "Add a new variant property to all components in the variant and their respective main instances. diff --git a/common/test/common_tests/logic/variant_properties_test.cljc b/common/test/common_tests/logic/variant_properties_test.cljc index c9de512936..2880ad1a93 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -432,7 +432,8 @@ comp01' (thc/get-component file' :c01)] (t/is (= "Property 2" (-> comp01' :variant-properties first :name))) - (t/is (= "Property 1" (-> comp01' :variant-properties last :name))))) + (t/is (= "Property 1" (-> comp01' :variant-properties last :name))) + (t/is (thf/validates-shapes-last? changes (:id page) [v-id])))) (t/deftest test-reorder-variant-properties-clamped-pos (let [file (-> (thf/sample-file :file1) @@ -449,13 +450,32 @@ file' (thf/apply-changes file changes) comp01' (thc/get-component file' :c01)] (t/is (= "Property 2" (-> comp01' :variant-properties first :name))) - (t/is (= "Property 1" (-> comp01' :variant-properties last :name)))) + (t/is (= "Property 1" (-> comp01' :variant-properties last :name))) + (t/is (thf/validates-shapes-last? changes (:id page) [v-id]))) (let [changes (clvp/generate-reorder-variant-poperties base-changes v-id 1 -1) file' (thf/apply-changes file changes) comp01' (thc/get-component file' :c01)] (t/is (= "Property 2" (-> comp01' :variant-properties first :name))) - (t/is (= "Property 1" (-> comp01' :variant-properties last :name)))))) + (t/is (= "Property 1" (-> comp01' :variant-properties last :name))) + (t/is (thf/validates-shapes-last? changes (:id page) [v-id]))))) + +(t/deftest test-reorder-variant-properties-validates-container + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02)) + v-id (-> (ths/get-shape file :v01) :id) + page (thf/current-page file) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id page)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (clvp/generate-reorder-variant-poperties v-id 0 2))] + + ;; All the components of the variant change, so validate the container, + ;; which checks every main instance and that all of them keep the same + ;; order of properties + (t/is (thf/validates-shapes-last? changes (:id page) [v-id])))) ;; ============================================================================= ;; generate-add-new-property tests