From d4c01ae0b1165eff90063d155250b7809bb3bdab Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Wed, 30 Sep 2026 11:28:19 +0200 Subject: [PATCH] :wrench: Validate shapes after updating a variant property value generate-update-property-value now validates the main instance of the component once the new value is set. The change only touches that component and its main instance, so validating the whole variant container would also check the variants that did not change. Add thf/validates-shapes-last?, a test helper that checks that the last redo change is a :validate-shapes change for the expected page and shapes, and use it to test the function. Register variant-properties-test in the runner so that it also runs on JS. AI-assisted-by: claude-opus-5-5 --- .../app/common/logic/variant_properties.cljc | 6 ++++- common/src/app/common/test_helpers/files.cljc | 9 ++++++++ .../logic/variant_properties_test.cljc | 23 +++++++++++++++++-- common/test/common_tests/runner.cljc | 2 ++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index 673e73cfe1..a4755a89ce 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -99,7 +99,11 @@ (-> 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) + [main-id] + (str "generate-update-property-value: " component-id + " pos: " pos " value: " value)))) changes)))) (defn generate-set-variant-error diff --git a/common/src/app/common/test_helpers/files.cljc b/common/src/app/common/test_helpers/files.cljc index 448e0d2562..5df70cb004 100644 --- a/common/src/app/common/test_helpers/files.cljc +++ b/common/src/app/common/test_helpers/files.cljc @@ -75,6 +75,15 @@ (validate-file! file') file')) +(defn validates-shapes-last? + "Check that the last redo change in `changes` is a :validate-shapes change + for the page `page-id` and exactly the shapes `shape-ids`, in any order." + [changes page-id shape-ids] + (let [change (last (:redo-changes changes))] + (and (= :validate-shapes (:type change)) + (= page-id (:page-id change)) + (= (set shape-ids) (set (:shape-ids change)))))) + ;; ----- Pages (defn sample-page diff --git a/common/test/common_tests/logic/variant_properties_test.cljc b/common/test/common_tests/logic/variant_properties_test.cljc index f73214236a..660758f019 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -249,7 +249,9 @@ ;; ==== Check (t/is (= (-> comp01' :variant-properties first :value) "NewValue1")) - (t/is (= (-> comp02' :variant-properties first :value) "NewValue2")))) + (t/is (= (-> comp02' :variant-properties first :value) "NewValue2")) + ;; The last call validates the main instance of comp02 + (t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp02)])))) (t/deftest test-update-property-value-duplicate-value (let [file (-> (thf/sample-file :file1) @@ -274,7 +276,24 @@ comp02' (thc/get-component file' :c02)] (t/is (= "SharedValue" (-> comp01' :variant-properties first :value))) - (t/is (= "SharedValue" (-> comp02' :variant-properties first :value))))) + (t/is (= "SharedValue" (-> comp02' :variant-properties first :value))) + ;; The last call validates the main instance of comp02 + (t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp02)])))) + +(t/deftest test-update-property-value-validates-main + (let [file (-> (thf/sample-file :file1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02)) + page (thf/current-page file) + comp01 (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 (:id comp01) 0 "NewValue"))] + + ;; Only the main instance of the updated component changes + (t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp01)])))) ;; ============================================================================= ;; generate-set-variant-error tests diff --git a/common/test/common_tests/runner.cljc b/common/test/common_tests/runner.cljc index 17f7d1c687..acba4ceab5 100644 --- a/common/test/common_tests/runner.cljc +++ b/common/test/common_tests/runner.cljc @@ -78,6 +78,7 @@ [common-tests.logic.text-touched-test] [common-tests.logic.token-apply-test] [common-tests.logic.token-test] + [common-tests.logic.variant-properties-test] [common-tests.logic.variants-switch-test] [common-tests.logic.variants-test] [common-tests.math-test] @@ -186,6 +187,7 @@ 'common-tests.logic.text-touched-test 'common-tests.logic.token-apply-test 'common-tests.logic.token-test + 'common-tests.logic.variant-properties-test 'common-tests.logic.variants-switch-test 'common-tests.logic.variants-test 'common-tests.math-test