From 94667f5b06e1d7aecbfb2398de941e24e9cf32f1 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Tue, 29 Sep 2026 15:53:53 +0200 Subject: [PATCH] :wrench: Validate shapes after updating a variant property value generate-update-property-value now validates the main instance of the component and its variant container once the new value is set. Add tests that corrupt the 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 | 10 ++++- .../logic/variant_properties_test.cljc | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index ad48a06140..40f894ca06 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -95,11 +95,17 @@ props (:variant-properties component) name (-> props (update pos assoc :value value) - ctv/properties-to-name)] + ctv/properties-to-name) + + ids-to-validate [main-id (:variant-id component)]] (-> changes (pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value) {:apply-changes-local-library? true}) - (pcb/update-shapes [main-id] #(assoc % :variant-name name)))) + (pcb/update-shapes [main-id] #(assoc % :variant-name name)) + (pcb/validate-shapes (pcb/get-page-id changes) + ids-to-validate + (str "generate-update-property-value: " component-id + " pos: " pos " value: " value)))) changes)))) (defn generate-set-variant-error diff --git a/common/test/common_tests/logic/variant_properties_test.cljc b/common/test/common_tests/logic/variant_properties_test.cljc index 404e459d51..78447bf3b8 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -756,3 +756,42 @@ (t/is (str/includes? (:hint error) "generate-remove-property")) (t/is (contains? (error-codes error) :invalid-variant-properties))))) + +#?(:cljs + (t/deftest test-update-property-value-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))) + page (thf/current-page file) + c01-id (:id (thc/get-component file :c01)) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id page)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (clvp/generate-update-property-value c01-id 0 "NewValue")) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-update-property-value")) + (t/is (contains? (error-codes error) :variant-component-bad-id))))) + +#?(:cljs + (t/deftest test-update-property-value-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"}]})) + page (thf/current-page file) + c01-id (:id (thc/get-component file :c01)) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id page)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (clvp/generate-update-property-value c01-id 0 "NewValue")) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-update-property-value")) + (t/is (contains? (error-codes error) :invalid-variant-properties)))))