mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 14:11:40 +02:00
✅ Add more tests for touched
This commit is contained in:
parent
a40afd5b63
commit
77d4901db1
3 changed files with 148 additions and 215 deletions
|
@ -23,201 +23,6 @@
|
|||
|
||||
;; === Test touched ======================
|
||||
|
||||
(t/deftest test-touched-children-add
|
||||
(t/async done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"
|
||||
:fill-color clr/white
|
||||
:fill-opacity 1})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance1
|
||||
(thp/id :component1))
|
||||
(thp/sample-shape :shape2 :circle
|
||||
{:name "Circle 1"}))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
shape2 (thp/get-shape state :shape2)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;; [Page: Page 1]
|
||||
;; Root Frame
|
||||
;; {Rect 1}
|
||||
;; Rect1
|
||||
;; Rect 1 #--> Rect 1
|
||||
;; Rect 1 ---> Rect 1
|
||||
;; Circle 1
|
||||
;;
|
||||
;; [Component: Rect 1] core.cljs:200:23
|
||||
;; --> [Page 1] Rect 1
|
||||
|
||||
(let [[[group shape1] [c-group c-shape1] _component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(thp/id :instance1))]
|
||||
|
||||
(t/is (= (:name group) "Rect 1"))
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:touched shape1) nil))
|
||||
(t/is (not= (:shape-ref shape1) nil))
|
||||
|
||||
(t/is (= (:name c-group) "Rect 1"))
|
||||
(t/is (= (:touched c-group) nil))
|
||||
(t/is (= (:shape-ref c-group) nil))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:touched c-shape1) nil))
|
||||
(t/is (= (:shape-ref c-shape1) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape2)} (:id instance1) 0) ;; We cant't change the structure of component copies, so this operation will do nothing
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-touched-children-delete
|
||||
(t/async done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/sample-shape :shape2 :rect
|
||||
{:name "Rect 2"})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)])
|
||||
(thp/instantiate-component :instance1
|
||||
(thp/id :component1)))
|
||||
|
||||
[_group1 shape1']
|
||||
(thl/resolve-instance state (thp/id :instance1))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;;;
|
||||
;; [Page]
|
||||
;; Root Frame
|
||||
;; Component 1
|
||||
;; Rect 1
|
||||
;; Rect 2
|
||||
;; Component 1 #--> Component 1
|
||||
;; Rect 1* ---> Rect 1
|
||||
;; #{:visibility-group}
|
||||
;; Rect 2 ---> Rect 2
|
||||
;;;
|
||||
;; [Component 1]
|
||||
;; page1 / Component 1
|
||||
;;
|
||||
(let [[[group shape1 shape2] [c-group c-shape1 c-shape2] _component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(thp/id :instance1))]
|
||||
|
||||
(t/is (= (:name group) "Component 1"))
|
||||
(t/is (= (:touched group) nil))
|
||||
(t/is (not= (:shape-ref group) nil))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:hidden shape1) true)) ; Instance shapes are not deleted but hidden
|
||||
(t/is (= (:touched shape1) #{:visibility-group}))
|
||||
(t/is (not= (:shape-ref shape1) nil))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (= (:touched shape2) nil))
|
||||
(t/is (not= (:shape-ref shape2) nil))
|
||||
|
||||
(t/is (= (:name c-group) "Component 1"))
|
||||
(t/is (= (:touched c-group) nil))
|
||||
(t/is (= (:shape-ref c-group) nil))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:touched c-shape1) nil))
|
||||
(t/is (= (:shape-ref c-shape1) nil))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
(t/is (= (:touched c-shape2) nil))
|
||||
(t/is (= (:shape-ref c-shape2) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwsh/delete-shapes #{(:id shape1')})
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-touched-children-move
|
||||
(t/async done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/sample-shape :shape2 :rect
|
||||
{:name "Rect 2"})
|
||||
(thp/sample-shape :shape3 :rect
|
||||
{:name "Rect 3"})
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)
|
||||
(thp/id :shape3)])
|
||||
(thp/instantiate-component :instance1
|
||||
(thp/id :component1)))
|
||||
|
||||
[group1' shape1']
|
||||
(thl/resolve-instance state (thp/id :instance1))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
;; Expected shape tree:
|
||||
;; [Page: Page 1]
|
||||
;; Root Frame
|
||||
;; {Component 1} #
|
||||
;; Rect 1
|
||||
;; Rect 2
|
||||
;; Rect 3
|
||||
;; Component 1 #--> Component 1
|
||||
;; Rect 1 ---> Rect 1
|
||||
;; Rect 2 ---> Rect 2
|
||||
;; Rect 3 ---> Rect 3
|
||||
;;
|
||||
;; ========= Local library
|
||||
;;
|
||||
;; [Component: Component 1]
|
||||
;; --> [Page 1] Component 1
|
||||
|
||||
(let [[[group shape1 shape2 shape3]
|
||||
[c-group c-shape1 c-shape2 c-shape3] _component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(thp/id :instance1))]
|
||||
|
||||
(t/is (= (:name group) "Component 1"))
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:touched shape1) nil))
|
||||
(t/is (not= (:shape-ref shape1) nil))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (= (:touched shape2) nil))
|
||||
(t/is (not= (:shape-ref shape2) nil))
|
||||
(t/is (= (:name shape3) "Rect 3"))
|
||||
(t/is (= (:touched shape3) nil))
|
||||
(t/is (not= (:shape-ref shape3) nil))
|
||||
|
||||
(t/is (= (:name c-group) "Component 1"))
|
||||
(t/is (= (:touched c-group) nil))
|
||||
(t/is (= (:shape-ref c-group) nil))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:touched c-shape1) nil))
|
||||
(t/is (= (:shape-ref c-shape1) nil))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
(t/is (= (:touched c-shape2) nil))
|
||||
(t/is (= (:shape-ref c-shape2) nil))
|
||||
(t/is (= (:name c-shape3) "Rect 3"))
|
||||
(t/is (= (:touched c-shape3) nil))
|
||||
(t/is (= (:shape-ref c-shape3) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape1')} (:id group1') 2) ;; We cant't change the structure of component copies, so this operation will do nothing
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-touched-from-lib
|
||||
(t/async
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue