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