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 once the new value is set. The change only touches that component and its main instance, so validating the whole variant container would also check the variants that did not change. Add thf/validates-shapes-last?, a test helper that checks that the last redo change is a :validate-shapes change for the expected page and shapes, and use it to test the function. Register variant-properties-test in the runner so that it also runs on JS. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
6e0a9e89d0
commit
d4c01ae0b1
@ -99,7 +99,11 @@
|
||||
(-> 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)
|
||||
[main-id]
|
||||
(str "generate-update-property-value: " component-id
|
||||
" pos: " pos " value: " value))))
|
||||
changes))))
|
||||
|
||||
(defn generate-set-variant-error
|
||||
|
||||
@ -75,6 +75,15 @@
|
||||
(validate-file! file')
|
||||
file'))
|
||||
|
||||
(defn validates-shapes-last?
|
||||
"Check that the last redo change in `changes` is a :validate-shapes change
|
||||
for the page `page-id` and exactly the shapes `shape-ids`, in any order."
|
||||
[changes page-id shape-ids]
|
||||
(let [change (last (:redo-changes changes))]
|
||||
(and (= :validate-shapes (:type change))
|
||||
(= page-id (:page-id change))
|
||||
(= (set shape-ids) (set (:shape-ids change))))))
|
||||
|
||||
;; ----- Pages
|
||||
|
||||
(defn sample-page
|
||||
|
||||
@ -249,7 +249,9 @@
|
||||
|
||||
;; ==== Check
|
||||
(t/is (= (-> comp01' :variant-properties first :value) "NewValue1"))
|
||||
(t/is (= (-> comp02' :variant-properties first :value) "NewValue2"))))
|
||||
(t/is (= (-> comp02' :variant-properties first :value) "NewValue2"))
|
||||
;; The last call validates the main instance of comp02
|
||||
(t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp02)]))))
|
||||
|
||||
(t/deftest test-update-property-value-duplicate-value
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
@ -274,7 +276,24 @@
|
||||
comp02' (thc/get-component file' :c02)]
|
||||
|
||||
(t/is (= "SharedValue" (-> comp01' :variant-properties first :value)))
|
||||
(t/is (= "SharedValue" (-> comp02' :variant-properties first :value)))))
|
||||
(t/is (= "SharedValue" (-> comp02' :variant-properties first :value)))
|
||||
;; The last call validates the main instance of comp02
|
||||
(t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp02)]))))
|
||||
|
||||
(t/deftest test-update-property-value-validates-main
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02))
|
||||
page (thf/current-page file)
|
||||
comp01 (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 (:id comp01) 0 "NewValue"))]
|
||||
|
||||
;; Only the main instance of the updated component changes
|
||||
(t/is (thf/validates-shapes-last? changes (:id page) [(:main-instance-id comp01)]))))
|
||||
|
||||
;; =============================================================================
|
||||
;; generate-set-variant-error tests
|
||||
|
||||
@ -78,6 +78,7 @@
|
||||
[common-tests.logic.text-touched-test]
|
||||
[common-tests.logic.token-apply-test]
|
||||
[common-tests.logic.token-test]
|
||||
[common-tests.logic.variant-properties-test]
|
||||
[common-tests.logic.variants-switch-test]
|
||||
[common-tests.logic.variants-test]
|
||||
[common-tests.math-test]
|
||||
@ -186,6 +187,7 @@
|
||||
'common-tests.logic.text-touched-test
|
||||
'common-tests.logic.token-apply-test
|
||||
'common-tests.logic.token-test
|
||||
'common-tests.logic.variant-properties-test
|
||||
'common-tests.logic.variants-switch-test
|
||||
'common-tests.logic.variants-test
|
||||
'common-tests.math-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user