From e625fc86007c19bb8deee1da2348eba1200c3cda Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Tue, 29 Sep 2026 15:59:05 +0200 Subject: [PATCH] :wrench: Validate shapes after setting a variant error generate-set-variant-error now validates the main instance of the component and its variant container. The validator has no rule for :variant-error itself, so the new tests 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 | 9 ++++- .../logic/variant_properties_test.cljc | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index 40f894ca06..d74bbd59ee 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -117,11 +117,16 @@ (let [data (pcb/get-library-data changes) component (ctcl/get-component data component-id true)] (if component - (let [main-id (:main-instance-id component)] + (let [main-id (:main-instance-id component) + ids-to-validate [main-id (:variant-id component)]] (-> changes (pcb/update-shapes [main-id] (if (nil? value) #(dissoc % :variant-error) - #(assoc % :variant-error value))))) + #(assoc % :variant-error value))) + (pcb/validate-shapes (pcb/get-page-id changes) + ids-to-validate + (str "generate-set-variant-error: " component-id + " value: " value)))) changes)))) (defn generate-reorder-variant-poperties diff --git a/common/test/common_tests/logic/variant_properties_test.cljc b/common/test/common_tests/logic/variant_properties_test.cljc index 78447bf3b8..0b715e8bcb 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -795,3 +795,42 @@ (t/is (str/includes? (:hint error) "generate-update-property-value")) (t/is (contains? (error-codes error) :invalid-variant-properties))))) + +#?(:cljs + (t/deftest test-set-variant-error-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-set-variant-error c01-id "bad=value")) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-set-variant-error")) + (t/is (contains? (error-codes error) :variant-component-bad-id))))) + +#?(:cljs + (t/deftest test-set-variant-error-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-set-variant-error c01-id "bad=value")) + + error (validation-error file changes)] + + (t/is (str/includes? (:hint error) "generate-set-variant-error")) + (t/is (contains? (error-codes error) :invalid-variant-properties)))))