mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 14:00:37 +00:00
🔧 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:
parent
79851eef0e
commit
94667f5b06
@ -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
|
||||
|
||||
@ -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)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user