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

View File

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

View File

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