🔧 Validate shapes after reordering variant properties

generate-reorder-variant-poperties now validates the variant container
when the reorder changes something. All the components of the variant
change, so validating the container checks every main instance and that
all of them keep the same order of properties. A reorder that changes
nothing still returns the same changes, with no validation.

Check with thf/validates-shapes-last? that the function validates the
expected page and container.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Eva Marco 2026-09-30 16:09:13 +02:00 committed by Andrés Moya
parent 116ca85ea2
commit f2c026dd5d
2 changed files with 52 additions and 19 deletions

View File

@ -135,22 +135,35 @@
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)]
;; Nothing to validate if the order did not change
(if (identical? changes changes')
changes
;; All the components of the variant change, so validate the
;; container, which checks every main instance and that all of them
;; keep the same order of properties
(pcb/validate-shapes changes'
(pcb/get-page-id changes')
[variant-id]
(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

@ -432,7 +432,8 @@
comp01' (thc/get-component file' :c01)]
(t/is (= "Property 2" (-> comp01' :variant-properties first :name)))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name)))))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name)))
(t/is (thf/validates-shapes-last? changes (:id page) [v-id]))))
(t/deftest test-reorder-variant-properties-clamped-pos
(let [file (-> (thf/sample-file :file1)
@ -449,13 +450,32 @@
file' (thf/apply-changes file changes)
comp01' (thc/get-component file' :c01)]
(t/is (= "Property 2" (-> comp01' :variant-properties first :name)))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name))))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name)))
(t/is (thf/validates-shapes-last? changes (:id page) [v-id])))
(let [changes (clvp/generate-reorder-variant-poperties base-changes v-id 1 -1)
file' (thf/apply-changes file changes)
comp01' (thc/get-component file' :c01)]
(t/is (= "Property 2" (-> comp01' :variant-properties first :name)))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name))))))
(t/is (= "Property 1" (-> comp01' :variant-properties last :name)))
(t/is (thf/validates-shapes-last? changes (:id page) [v-id])))))
(t/deftest test-reorder-variant-properties-validates-container
(let [file (-> (thf/sample-file :file1)
(thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02))
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))]
;; All the components of the variant change, so validate the container,
;; which checks every main instance and that all of them keep the same
;; order of properties
(t/is (thf/validates-shapes-last? changes (:id page) [v-id]))))
;; =============================================================================
;; generate-add-new-property tests