From 4cb36153afb76dcbce488cc9465ba651552102bf Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Tue, 29 Sep 2026 16:01:26 +0200 Subject: [PATCH] :wrench: Validate shapes after reordering variant properties generate-reorder-variant-poperties now validates the main instances and the variant container, but only when the reorder changed something, so a no-op still returns the same changes. Add tests that corrupt a main instance or the container and expect a validation error. AI-assisted-by: claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 --- .../app/common/logic/variant_properties.cljc | 41 +++++++++++-------- .../logic/variant_properties_test.cljc | 39 ++++++++++++++++++ 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index d74bbd59ee..57aa208965 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -138,22 +138,31 @@ 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)] + (if (identical? changes changes') + changes + (let [ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)] + (pcb/validate-shapes changes' + (pcb/get-page-id changes') + ids-to-validate + (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 0b715e8bcb..81fcd132d7 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -834,3 +834,42 @@ (t/is (str/includes? (:hint error) "generate-set-variant-error")) (t/is (contains? (error-codes error) :invalid-variant-properties))))) + +#?(:cljs + (t/deftest test-reorder-variant-properties-validates-main + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02) + (ths/update-shape :m01 :variant-id (uuid/next))) + 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)) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-reorder-variant-poperties")) + (t/is (contains? (error-codes error) :variant-component-bad-id))))) + +#?(:cljs + (t/deftest test-reorder-variant-properties-validates-container + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02) + (thc/update-component :c02 {:variant-properties [{:name "Other" :value "p1v2"} + {:name "Property 2" :value "p2v2"}]})) + 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)) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-reorder-variant-poperties")) + (t/is (contains? (error-codes error) :invalid-variant-properties)))))