🔧 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 <noreply@anthropic.com>
This commit is contained in:
Eva Marco 2026-09-29 15:53:53 +02:00
parent 79851eef0e
commit 94667f5b06
2 changed files with 47 additions and 2 deletions

View File

@ -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

View File

@ -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)))))