mirror of
https://github.com/penpot/penpot.git
synced 2026-09-09 21:49:10 +00:00
✨ Add variants advanced retrieve tests (#7183)
This commit is contained in:
parent
9de3910526
commit
dfe0f64c7c
@ -307,6 +307,7 @@
|
|||||||
|
|
||||||
file' (thf/apply-changes file changes)]
|
file' (thf/apply-changes file changes)]
|
||||||
(when new-shape-label
|
(when new-shape-label
|
||||||
|
(thi/rm-id! (:id new-shape))
|
||||||
(thi/set-id! new-shape-label (:id new-shape)))
|
(thi/set-id! new-shape-label (:id new-shape)))
|
||||||
(if propagate-fn
|
(if propagate-fn
|
||||||
(propagate-fn file')
|
(propagate-fn file')
|
||||||
|
|||||||
@ -21,6 +21,10 @@
|
|||||||
[label id]
|
[label id]
|
||||||
(swap! idmap assoc label id))
|
(swap! idmap assoc label id))
|
||||||
|
|
||||||
|
(defn rm-id!
|
||||||
|
[id]
|
||||||
|
(swap! idmap #(into {} (remove (comp #{id} val) %))))
|
||||||
|
|
||||||
(defn new-id!
|
(defn new-id!
|
||||||
[label]
|
[label]
|
||||||
(let [id (uuid/next)]
|
(let [id (uuid/next)]
|
||||||
|
|||||||
@ -56,6 +56,22 @@
|
|||||||
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value2"}]}))))
|
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value2"}]}))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn add-variant-with-copy
|
||||||
|
[file variant-label component1-label root1-label component2-label root2-label child1-label child2-label component-copy-label]
|
||||||
|
(let [file (ths/add-sample-shape file variant-label :type :frame :is-variant-container true)
|
||||||
|
variant-id (thi/id variant-label)]
|
||||||
|
(-> file
|
||||||
|
(ths/add-sample-shape root2-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value2")
|
||||||
|
(ths/add-sample-shape root1-label :type :frame :parent-label variant-label :variant-id variant-id :variant-name "Value1")
|
||||||
|
(thc/instantiate-component component-copy-label child1-label :parent-label root1-label)
|
||||||
|
(thc/instantiate-component component-copy-label child2-label :parent-label root2-label)
|
||||||
|
(thc/make-component component1-label root1-label)
|
||||||
|
(thc/update-component component1-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value1"}]})
|
||||||
|
(thc/make-component component2-label root2-label)
|
||||||
|
(thc/update-component component2-label {:variant-id variant-id :variant-properties [{:name "Property 1" :value "Value2"}]}))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn add-variant-with-text
|
(defn add-variant-with-text
|
||||||
[file variant-label component1-label root1-label component2-label root2-label child1-label child2-label text1 text2
|
[file variant-label component1-label root1-label component2-label root2-label child1-label child2-label text1 text2
|
||||||
& {:keys [text1-params text2-params]}]
|
& {:keys [text1-params text2-params]}]
|
||||||
|
|||||||
@ -1122,4 +1122,143 @@
|
|||||||
;; No second line
|
;; No second line
|
||||||
(t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "50"))
|
(t/is (= (get-in copy-structure-mixed-t' font-size-path-0) "50"))
|
||||||
(t/is (= (get-in copy-structure-mixed-t' text-path-0) "bye"))
|
(t/is (= (get-in copy-structure-mixed-t' text-path-0) "bye"))
|
||||||
(t/is (nil? (get-in copy-structure-mixed-t' font-size-path-1)))))
|
(t/is (nil? (get-in copy-structure-mixed-t' font-size-path-1)))))
|
||||||
|
|
||||||
|
|
||||||
|
(t/deftest test-switch-variant-for-other-with-same-nested-component
|
||||||
|
(let [;; ==== Setup
|
||||||
|
file (-> (thf/sample-file :file1)
|
||||||
|
(tho/add-simple-component :external01 :external01-root :external01-child)
|
||||||
|
(tho/add-simple-component :external02 :external02-root :external02-child)
|
||||||
|
(thv/add-variant-with-copy
|
||||||
|
:v01 :c01 :m01 :c02 :m02 :cp01 :cp02 :external01)
|
||||||
|
|
||||||
|
(thc/instantiate-component :c01
|
||||||
|
:copy01
|
||||||
|
:children-labels [:copy-cp01]))
|
||||||
|
|
||||||
|
page (thf/current-page file)
|
||||||
|
copy01 (ths/get-shape file :copy01)
|
||||||
|
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||||
|
copy-cp01-rect-id (-> copy-cp01 :shapes first)
|
||||||
|
|
||||||
|
|
||||||
|
;; On :copy-cp01, change the width of the rect
|
||||||
|
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||||
|
#{copy-cp01-rect-id}
|
||||||
|
(fn [shape]
|
||||||
|
(assoc shape :width 25))
|
||||||
|
(:objects page)
|
||||||
|
{})
|
||||||
|
file (thf/apply-changes file changes)
|
||||||
|
copy-cp01-rect (ths/get-shape-by-id file copy-cp01-rect-id)
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
;; Switch :c01 for :c02
|
||||||
|
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||||
|
copy02 (ths/get-shape file' :copy02)
|
||||||
|
copy-cp02' (ths/get-shape-by-id file' (-> copy02 :shapes first))
|
||||||
|
copy-cp02-rect' (ths/get-shape-by-id file' (-> copy-cp02' :shapes first))]
|
||||||
|
|
||||||
|
;; The width of copy-cp01-rect was 25
|
||||||
|
(t/is (= (:width copy-cp01-rect) 25))
|
||||||
|
|
||||||
|
;; The width of copy-cp02-rect' is 25 (change is preserved)
|
||||||
|
(t/is (= (:width copy-cp02-rect') 25))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(t/deftest test-switch-variant-that-has-swaped-copy
|
||||||
|
(let [;; ==== Setup
|
||||||
|
file (-> (thf/sample-file :file1)
|
||||||
|
(tho/add-simple-component :external01 :external01-root :external01-child)
|
||||||
|
(tho/add-simple-component :external02 :external02-root :external02-child)
|
||||||
|
(thv/add-variant-with-copy
|
||||||
|
:v01 :c01 :m01 :c02 :m02 :cp01 :cp02 :external01)
|
||||||
|
|
||||||
|
(thc/instantiate-component :c01
|
||||||
|
:copy01
|
||||||
|
:children-labels [:copy-cp01]))
|
||||||
|
|
||||||
|
copy01 (ths/get-shape file :copy01)
|
||||||
|
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||||
|
external02 (thc/get-component file :external02)
|
||||||
|
|
||||||
|
;; On :c01, swap the copy of :external01 for a copy of :external02
|
||||||
|
file (-> file
|
||||||
|
(tho/swap-component copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||||
|
copy-cp02 (ths/get-shape file :copy-cp02)
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
;; Switch :c01 for :c02
|
||||||
|
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||||
|
|
||||||
|
|
||||||
|
copy02' (ths/get-shape file' :copy02)
|
||||||
|
copy-cp02' (ths/get-shape file' :copy-cp02)]
|
||||||
|
(thf/dump-file file')
|
||||||
|
;;copy-cp02 is a copy of external02
|
||||||
|
(t/is (= (:component-id copy-cp02) (:id external02)))
|
||||||
|
;;copy-01 had copy-cp02 as child
|
||||||
|
(t/is (= (-> copy01 :shapes first) (:id copy-cp02)))
|
||||||
|
|
||||||
|
;;copy-cp02' is a copy of external02
|
||||||
|
(t/is (= (:component-id copy-cp02') (:id external02)))
|
||||||
|
;;copy-02' had copy-cp02' as child
|
||||||
|
(t/is (= (-> copy02' :shapes first) (:id copy-cp02')))))
|
||||||
|
|
||||||
|
|
||||||
|
(t/deftest test-switch-variant-that-has-swaped-copy-with-changed-attr
|
||||||
|
(let [;; ==== Setup
|
||||||
|
file (-> (thf/sample-file :file1)
|
||||||
|
(tho/add-simple-component :external01 :external01-root :external01-child)
|
||||||
|
(tho/add-simple-component :external02 :external02-root :external02-child)
|
||||||
|
(thv/add-variant-with-copy
|
||||||
|
:v01 :c01 :m01 :c02 :m02 :cp01 :cp02 :external01)
|
||||||
|
|
||||||
|
(thc/instantiate-component :c01
|
||||||
|
:copy01
|
||||||
|
:children-labels [:copy-cp01]))
|
||||||
|
|
||||||
|
page (thf/current-page file)
|
||||||
|
copy01 (ths/get-shape file :copy01)
|
||||||
|
copy-cp01 (ths/get-shape file :copy-cp01)
|
||||||
|
external02 (thc/get-component file :external02)
|
||||||
|
|
||||||
|
;; On :c01, swap the copy of :external01 for a copy of :external02
|
||||||
|
file (-> file
|
||||||
|
(tho/swap-component copy-cp01 :external02 {:new-shape-label :copy-cp02 :keep-touched? false}))
|
||||||
|
copy-cp02 (ths/get-shape file :copy-cp02)
|
||||||
|
copy-cp02-rect-id (-> copy-cp02 :shapes first)
|
||||||
|
|
||||||
|
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
|
||||||
|
#{copy-cp02-rect-id}
|
||||||
|
(fn [shape]
|
||||||
|
(assoc shape :width 25))
|
||||||
|
(:objects page)
|
||||||
|
{})
|
||||||
|
file (thf/apply-changes file changes)
|
||||||
|
copy-cp02-rect (ths/get-shape-by-id file copy-cp02-rect-id)
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
;; Switch :c01 for :c02
|
||||||
|
file' (tho/swap-component file copy01 :c02 {:new-shape-label :copy02 :keep-touched? true})
|
||||||
|
|
||||||
|
|
||||||
|
copy02' (ths/get-shape file' :copy02)
|
||||||
|
copy-cp02' (ths/get-shape file' :copy-cp02)
|
||||||
|
copy-cp02-rect' (ths/get-shape-by-id file' (-> copy-cp02' :shapes first))]
|
||||||
|
(thf/dump-file file')
|
||||||
|
;;copy-cp02 is a copy of external02
|
||||||
|
(t/is (= (:component-id copy-cp02) (:id external02)))
|
||||||
|
;;copy-01 had copy-cp02 as child
|
||||||
|
(t/is (= (-> copy01 :shapes first) (:id copy-cp02)))
|
||||||
|
;; The width of copy-cp02-rect was 25
|
||||||
|
(t/is (= (:width copy-cp02-rect) 25))
|
||||||
|
|
||||||
|
;;copy-cp02' is a copy of external02
|
||||||
|
(t/is (= (:component-id copy-cp02') (:id external02)))
|
||||||
|
;;copy-02' had copy-cp02' as child
|
||||||
|
(t/is (= (-> copy02' :shapes first) (:id copy-cp02')))
|
||||||
|
;; The width of copy-cp02-rect' is 25 (change is preserved)
|
||||||
|
(t/is (= (:width copy-cp02-rect') 25))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user