🔧 Validate shapes after reordering variant properties

generate-reorder-variant-poperties now validates the main instances and
the variant container, but only when the reorder changed something, so
a no-op still returns the same changes. Add tests that corrupt a 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 16:01:26 +02:00
parent e625fc8600
commit 4cb36153af
2 changed files with 64 additions and 16 deletions

View File

@ -138,22 +138,31 @@
changes
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (cfv/find-variant-components data objects variant-id)]
(reduce (fn [changes component]
(let [props (:variant-properties component)
props' (d/reorder props from-pos to-space-between-pos)
main-id (:main-instance-id component)
name (ctv/properties-to-name props')]
(if (not= props props')
(-> changes
(pcb/update-component (:id component)
#(assoc % :variant-properties props')
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id]
#(assoc % :variant-name name)))
changes)))
changes
related-components))))
related-components (cfv/find-variant-components data objects variant-id)
changes' (reduce (fn [changes component]
(let [props (:variant-properties component)
props' (d/reorder props from-pos to-space-between-pos)
main-id (:main-instance-id component)
name (ctv/properties-to-name props')]
(if (not= props props')
(-> changes
(pcb/update-component (:id component)
#(assoc % :variant-properties props')
{:apply-changes-local-library? true})
(pcb/update-shapes [main-id]
#(assoc % :variant-name name)))
changes)))
changes
related-components)]
(if (identical? changes changes')
changes
(let [ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)]
(pcb/validate-shapes changes'
(pcb/get-page-id changes')
ids-to-validate
(str "generate-reorder-variant-poperties: " variant-id
" from: " from-pos " to: " to-space-between-pos)))))))
(defn generate-add-new-property
"Add a new variant property to all components in the variant and their respective main instances.

View File

@ -834,3 +834,42 @@
(t/is (str/includes? (:hint error) "generate-set-variant-error"))
(t/is (contains? (error-codes error) :invalid-variant-properties)))))
#?(:cljs
(t/deftest test-reorder-variant-properties-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)))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clvp/generate-reorder-variant-poperties v-id 0 2))
error (validation-error file changes)]
(t/is (str/includes? (:hint error) "generate-reorder-variant-poperties"))
(t/is (contains? (error-codes error) :variant-component-bad-id)))))
#?(:cljs
(t/deftest test-reorder-variant-properties-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"}]}))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clvp/generate-reorder-variant-poperties v-id 0 2))
error (validation-error file changes)]
(t/is (str/includes? (:hint error) "generate-reorder-variant-poperties"))
(t/is (contains? (error-codes error) :invalid-variant-properties)))))