mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 14:00:37 +00:00
🔧 Add tests for restoring variants and property chains
Cover the callers of the variant generators that had no tests with the new validation: restoring a deleted variant into its container, restoring it after its container was deleted, and adding a property and then setting its value, as the workspace properties panel does. Each case runs with valid data and expects no validation error on JS. AI-assisted-by: claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2fc6e33f17
commit
ff58d8c121
@ -744,6 +744,30 @@
|
||||
(t/is (= (mapv :name (:variant-properties c01'))
|
||||
(mapv :name (:variant-properties c03'))))))
|
||||
|
||||
;; The chain that update-properties-names-and-values runs in the workspace
|
||||
;; when the user adds a property with a value
|
||||
(t/deftest test-add-new-property-then-set-its-value
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
|
||||
v-id (-> (ths/get-shape file :v01) :id)
|
||||
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-add-new-property v-id :property-name "Color")
|
||||
(clvp/generate-update-property-value c01-id 1 "Red"))
|
||||
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
comp01' (thc/get-component file' :c01)
|
||||
comp02' (thc/get-component file' :c02)]
|
||||
|
||||
(t/is (= {:name "Color" :value "Red"} (-> comp01' :variant-properties second)))
|
||||
(t/is (= {:name "Color" :value ""} (-> comp02' :variant-properties second)))))
|
||||
|
||||
;; =============================================================================
|
||||
;; validate-shapes failure tests (only run on CLJS, where validation runs)
|
||||
;; =============================================================================
|
||||
|
||||
@ -271,3 +271,83 @@
|
||||
|
||||
(t/is (str/includes? (:hint error) "generate-relocate"))
|
||||
(t/is (contains? (error-codes error) :component-main-external)))))
|
||||
|
||||
(defn- delete-shapes
|
||||
[file labels]
|
||||
(let [page (thf/current-page file)
|
||||
changes (-> (pcb/empty-changes nil)
|
||||
(pcb/with-page page)
|
||||
(pcb/with-library-data (:data file))
|
||||
(pcb/with-objects (:objects page))
|
||||
(#(second (cls/generate-delete-shapes % (into #{} (map thi/id) labels) {}))))]
|
||||
(thf/apply-changes file changes)))
|
||||
|
||||
(defn- restore-changes
|
||||
[file component-label]
|
||||
(let [page (thf/current-page file)]
|
||||
(cll/generate-restore-component (-> (pcb/empty-changes)
|
||||
(pcb/with-library-data (:data file))
|
||||
(pcb/with-objects (:objects page)))
|
||||
(:data file)
|
||||
(thi/id component-label)
|
||||
(:id file)
|
||||
page
|
||||
(:objects page))))
|
||||
|
||||
(t/deftest test-restore-variant-into-its-container
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
|
||||
(delete-shapes [:m01]))
|
||||
|
||||
;; ==== Action
|
||||
changes (restore-changes file :c01)
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
;; ==== Get
|
||||
m01' (ths/get-shape file' :m01)
|
||||
c01' (thc/get-component file' :c01)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (= (thi/id :v01) (:parent-id m01')))
|
||||
(t/is (= (thi/id :v01) (:variant-id m01')))
|
||||
(t/is (= (thi/id :v01) (:variant-id c01')))))
|
||||
|
||||
#?(:cljs
|
||||
(t/deftest test-restore-variant-into-its-container-validates
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
|
||||
(delete-shapes [:m01]))
|
||||
changes (restore-changes file :c01)]
|
||||
|
||||
(t/is (nil? (validation-error file changes))))))
|
||||
|
||||
(t/deftest test-restore-variant-after-deleting-its-container
|
||||
(let [;; ==== Setup
|
||||
file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
|
||||
(delete-shapes [:m01 :m02]))
|
||||
|
||||
;; ==== Action
|
||||
changes (restore-changes file :c01)
|
||||
file' (thf/apply-changes file changes)
|
||||
|
||||
;; ==== Get
|
||||
v01' (ths/get-shape file' :v01)
|
||||
m01' (ths/get-shape file' :m01)
|
||||
c01' (thc/get-component file' :c01)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (nil? v01'))
|
||||
(t/is (some? m01'))
|
||||
(t/is (nil? (:variant-id m01')))
|
||||
(t/is (nil? (:variant-id c01')))))
|
||||
|
||||
#?(:cljs
|
||||
(t/deftest test-restore-variant-after-deleting-its-container-validates
|
||||
(let [file (-> (thf/sample-file :file1)
|
||||
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
|
||||
(delete-shapes [:m01 :m02]))
|
||||
changes (restore-changes file :c01)]
|
||||
|
||||
(t/is (nil? (validation-error file changes))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user