mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 13:58:29 +02:00
🎉 Add more test cases, and some fixes
This commit is contained in:
parent
31bfe3930d
commit
ca56e08459
10 changed files with 1386 additions and 484 deletions
|
@ -31,34 +31,34 @@
|
|||
{:name "Rect-1"}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name group) "Rect-2"))
|
||||
(t/is (= (:name component) "Rect-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-group) "Rect-2"))
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name group) "Rect-2"))
|
||||
(t/is (= (:name component) "Rect-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-group) "Rect-2"))
|
||||
|
||||
(thl/is-from-file group file))))]
|
||||
(thl/is-from-file group file))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -88,7 +88,7 @@
|
|||
new-state
|
||||
(:parent-id shape1))
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name group) "Component-1"))
|
||||
|
@ -109,41 +109,42 @@
|
|||
{:name "Rect-1"})
|
||||
(thp/sample-shape :shape2 :rect
|
||||
{:name "Rect-2"}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1 #--> Component-1
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-2 ---> Rect-2
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect-1
|
||||
; Rect-2
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1 #--> Component-1
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-2 ---> Rect-2
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect-1
|
||||
; Rect-2
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:name group) "Component-1"))
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name shape2) "Rect-2"))
|
||||
(t/is (= (:name component) "Component-1"))
|
||||
(t/is (= (:name c-group) "Component-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
(t/is (= (:name group) "Component-1"))
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name shape2) "Rect-2"))
|
||||
(t/is (= (:name component) "Component-1"))
|
||||
(t/is (= (:name c-group) "Component-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
|
||||
(thl/is-from-file group file))))]
|
||||
(thl/is-from-file group file))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -164,39 +165,40 @@
|
|||
(thp/group-shapes :group1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)]))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group-1 #--> Group-1
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-2 ---> Rect-2
|
||||
;
|
||||
; [Group-1]
|
||||
; Group-1
|
||||
; Rect-1
|
||||
; Rect-2
|
||||
;
|
||||
(let [[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(thp/id :group1))
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group-1 #--> Group-1
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-2 ---> Rect-2
|
||||
;
|
||||
; [Group-1]
|
||||
; Group-1
|
||||
; Rect-1
|
||||
; Rect-2
|
||||
;
|
||||
(let [[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(thp/id :group1))
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name shape2) "Rect-2"))
|
||||
(t/is (= (:name group) "Group-1"))
|
||||
(t/is (= (:name component) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
(t/is (= (:name c-group) "Group-1"))
|
||||
(t/is (= (:name shape1) "Rect-1"))
|
||||
(t/is (= (:name shape2) "Rect-2"))
|
||||
(t/is (= (:name group) "Group-1"))
|
||||
(t/is (= (:name component) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
(t/is (= (:name c-group) "Group-1"))
|
||||
|
||||
(thl/is-from-file group file))))]
|
||||
(thl/is-from-file group file))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -211,29 +213,29 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Renamed component
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Renamed]
|
||||
; Renamed component
|
||||
; Rect-1
|
||||
(let [libs (dwlh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
(t/is (= (:name component)
|
||||
"Renamed component")))))]
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Renamed component
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Renamed]
|
||||
; Renamed component
|
||||
; Rect-1
|
||||
(let [libs (wsh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
(t/is (= (:name component)
|
||||
"Renamed component")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -247,50 +249,50 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [new-component-id (->> (get-in new-state
|
||||
[:workspace-data
|
||||
:components])
|
||||
(keys)
|
||||
(filter #(not= % component-id))
|
||||
(first))
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [new-component-id (->> (get-in new-state
|
||||
[:workspace-data
|
||||
:components])
|
||||
(keys)
|
||||
(filter #(not= % component-id))
|
||||
(first))
|
||||
|
||||
[[instance1 shape1]
|
||||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))
|
||||
[[instance1 shape1]
|
||||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))
|
||||
|
||||
[[c-component2 c-shape2]
|
||||
component2]
|
||||
(thl/resolve-component
|
||||
new-state
|
||||
new-component-id)]
|
||||
[[c-component2 c-shape2]
|
||||
component2]
|
||||
(thl/resolve-component
|
||||
new-state
|
||||
new-component-id)]
|
||||
|
||||
(t/is (= (:name component2) "Rect-2")))))]
|
||||
(t/is (= (:name component2) "Rect-2")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -304,36 +306,36 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [[instance1 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [[instance1 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))
|
||||
|
||||
libs (dwlh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
libs (wsh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1))
|
||||
(t/is (nil? component)))))]
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1))
|
||||
(t/is (nil? component)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -348,50 +350,101 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
file (wsh/get-local-file state)
|
||||
component-id (thp/id :component-1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-3 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-3 #--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance2 shape2]
|
||||
[c-instance2 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
[[instance2 shape2]
|
||||
[c-instance2 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
|
||||
(t/is (not= (:id instance1) (:id instance2)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Rect-3"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name c-instance2) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1")))))]
|
||||
(t/is (not= (:id instance1) (:id instance2)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Rect-3"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name c-instance2) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1"))
|
||||
(t/is (= (:component-file instance2)
|
||||
thp/current-file-id)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwl/instantiate-component (:id file)
|
||||
(:component-id instance1)
|
||||
component-id
|
||||
(gpt/point 100 100))
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-instantiate-component-from-lib
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/move-to-library :lib1 "Library 1")
|
||||
(thp/sample-page))
|
||||
|
||||
library-id (thp/id :lib1)
|
||||
component-id (thp/id :component-1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> <Library 1> Rect-2
|
||||
; Rect-1 ---> <Library 1> Rect-1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance2 shape2]
|
||||
[c-instance2 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Rect-2"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name c-instance2) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1"))
|
||||
(t/is (= (:component-file instance2) library-id)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwl/instantiate-component library-id
|
||||
component-id
|
||||
(gpt/point 100 100))
|
||||
:the/end))))
|
||||
|
||||
|
@ -402,32 +455,32 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [[instance1 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))]
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
(let [[instance1 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1)))))]
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -442,47 +495,47 @@
|
|||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"}))
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
file (wsh/get-local-file state)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group-1 #--> Group-1
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Group-1]
|
||||
; Group-1
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
(let [page (thp/current-page new-state)
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
parent1 (cph/get-shape page (:parent-id shape1))
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group-1 #--> Group-1
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Group-1]
|
||||
; Group-1
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
(let [page (thp/current-page new-state)
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
parent1 (cph/get-shape page (:parent-id shape1))
|
||||
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id parent1))]
|
||||
[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id parent1))]
|
||||
|
||||
(t/is (= (:name group) "Group-1"))
|
||||
(t/is (= (:name shape1) "Rect-2"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name component) "Group-1"))
|
||||
(t/is (= (:name c-group) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1")))))]
|
||||
(t/is (= (:name group) "Group-1"))
|
||||
(t/is (= (:name shape1) "Rect-2"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name component) "Group-1"))
|
||||
(t/is (= (:name c-group) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -499,59 +552,59 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/group-shapes :group1
|
||||
[(thp/id :instance1)])
|
||||
(thp/make-component :instance2
|
||||
(thp/make-component :instance2 :component-2
|
||||
[(thp/id :group1)]))
|
||||
|
||||
file (dwlh/get-local-file state)
|
||||
file (wsh/get-local-file state)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
instance2 (thp/get-shape state :instance2)
|
||||
component-id (:component-id instance2)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-3 #--> Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2 #--> Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
; Rect-3 #--> Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
; [Rect-1]
|
||||
; Rect-2
|
||||
; Rect-1
|
||||
;
|
||||
; [Rect-2]
|
||||
; Rect-2
|
||||
; Rect-2 @--> Rect-2
|
||||
; Rect-1 ---> Rect-1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance3 shape3 shape4]
|
||||
[c-instance3 c-shape3 c-shape4]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
[[instance3 shape3 shape4]
|
||||
[c-instance3 c-shape3 c-shape4]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
|
||||
(t/is (not= (:id instance1) (:id instance3)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance3) "Rect-3"))
|
||||
(t/is (= (:name shape3) "Rect-2"))
|
||||
(t/is (= (:name shape4) "Rect-1"))
|
||||
(t/is (= (:name c-instance3) "Rect-2"))
|
||||
(t/is (= (:name c-shape3) "Rect-2"))
|
||||
(t/is (= (:name c-shape4) "Rect-1")))))]
|
||||
(t/is (not= (:id instance1) (:id instance3)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance3) "Rect-3"))
|
||||
(t/is (= (:name shape3) "Rect-2"))
|
||||
(t/is (= (:name shape4) "Rect-1"))
|
||||
(t/is (= (:name c-instance3) "Rect-2"))
|
||||
(t/is (= (:name c-shape3) "Rect-2"))
|
||||
(t/is (= (:name c-shape4) "Rect-1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -560,3 +613,63 @@
|
|||
(gpt/point 100 100))
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-instantiate-nested-component-from-lib
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect-1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/move-to-library :lib1 "Library 1")
|
||||
(thp/sample-page)
|
||||
(thp/instantiate-component :instance2
|
||||
(thp/id :component-1)
|
||||
(thp/id :lib1)))
|
||||
|
||||
library-id (thp/id :lib1)
|
||||
component-id (thp/id :component-1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group-1 #--> Group-1
|
||||
; Rect-2 @--> <Library 1> Rect-2
|
||||
; Rect-1 ---> <Library 1> Rect-1
|
||||
;
|
||||
; [Group-1]
|
||||
; Group-1
|
||||
; Rect-2 @--> <Library 1> Rect-2
|
||||
; Rect-1 ---> <Library 1> Rect-1
|
||||
;
|
||||
(let [instance2 (thp/get-shape new-state :instance2)
|
||||
|
||||
[[group1 shape1 shape2] [c-group1 c-shape1 c-shape2] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id instance2))]
|
||||
|
||||
(t/is (= (:name group1) "Group-1"))
|
||||
(t/is (= (:name shape1) "Rect-2"))
|
||||
(t/is (= (:name shape2) "Rect-1"))
|
||||
(t/is (= (:name c-group1) "Group-1"))
|
||||
(t/is (= (:name c-shape1) "Rect-2"))
|
||||
(t/is (= (:name c-shape2) "Rect-1"))
|
||||
(t/is (= (:component-file group1) thp/current-file-id))
|
||||
(t/is (= (:component-file shape1) library-id))
|
||||
(t/is (= (:component-file shape2) nil))
|
||||
(t/is (= (:component-file c-group1) nil))
|
||||
(t/is (= (:component-file c-shape1) library-id))
|
||||
(t/is (= (:component-file c-shape2) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :instance2))
|
||||
dwg/group-selected
|
||||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
(ns app.components-sync-test
|
||||
(:require
|
||||
[app.common.colors :as clr]
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.main.data.workspace.changes :as dwc]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.test-helpers.events :as the]
|
||||
[app.test-helpers.libraries :as thl]
|
||||
[app.test-helpers.pages :as thp]
|
||||
[beicon.core :as rx]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[linked.core :as lks]
|
||||
[potok.core :as ptk]))
|
||||
[app.common.colors :as clr]
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.test-helpers.events :as the]
|
||||
[app.test-helpers.libraries :as thl]
|
||||
[app.test-helpers.pages :as thp]
|
||||
[beicon.core :as rx]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[linked.core :as lks]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before thp/reset-idmap!})
|
||||
|
@ -27,37 +31,220 @@
|
|||
{:name "Rect 1"
|
||||
:fill-color clr/white
|
||||
:fill-opacity 1})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
|
||||
update-fn (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1* ---> Rect 1
|
||||
; #{:fill-group}
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (= (:touched instance1) nil))
|
||||
(t/is (= (:touched shape1) #{:fill-group}))
|
||||
(t/is (= (:fill-color shape1) clr/test))
|
||||
(t/is (= (:fill-opacity shape1) 0.5))
|
||||
(t/is (= (:touched c-group) nil))
|
||||
(t/is (= (:touched c-shape1) nil))
|
||||
(t/is (= (:fill-color c-shape1) clr/white))
|
||||
(t/is (= (:fill-opacity c-shape1) 1)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dch/update-shapes [(:id shape1)] update-fn)
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-touched-children-add
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(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]
|
||||
; Root Frame
|
||||
; Rect 1-1* #--> Rect 1-1
|
||||
; #{:shapes-group}
|
||||
; Circle 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1 shape2] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (= (:touched group) #{:shapes-group}))
|
||||
(t/is (nil? (:touched shape1)))
|
||||
(t/is (= (:name shape1) "Circle 1"))
|
||||
(t/is (nil? (:shape-ref shape1)))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape1))))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape2)} (:id instance1) 0)
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-touched-children-delete
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1* #--> Component-1
|
||||
; #{:shapes-group}
|
||||
; Rect 2 ---> Rect 2
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect 1
|
||||
; Rect 2
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape2] [c-group c-shape2] component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (= (:touched group) #{:shapes-group}))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape2))))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwc/delete-shapes #{(:id shape1)})
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-touched-children-move
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)
|
||||
(thp/id :shape3)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
update-shape (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1* #--> Component-1
|
||||
; #{:shapes-group}
|
||||
; Rect 2 ---> Rect 2
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 3 ---> Rect 3
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect 1
|
||||
; Rect 2
|
||||
; Rect 3
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))
|
||||
[[group shape1 shape2 shape3]
|
||||
[c-group c-shape1 c-shape2 c-shape3] component]
|
||||
(thl/resolve-instance-and-main-allow-dangling
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:fill-color shape1) clr/test))
|
||||
(t/is (= (:fill-opacity shape1) 0.5))
|
||||
(t/is (= (:touched shape1) #{:fill-group}))
|
||||
(t/is (= (:fill-color c-shape1) clr/white))
|
||||
(t/is (= (:fill-opacity c-shape1) 1))
|
||||
(t/is (= (:touched c-shape1) nil)))))]
|
||||
(t/is (= (:touched group) #{:shapes-group}))
|
||||
(t/is (nil? (:touched shape1)))
|
||||
(t/is (some? (:shape-ref shape1)))
|
||||
(t/is (= (:name shape1) "Rect 2"))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (nil? (:touched shape3)))
|
||||
(t/is (some? (:shape-ref shape3)))
|
||||
(t/is (= (:name shape3) "Rect 3"))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape1)))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (nil? (:touched c-shape2)))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
(t/is (nil? (:touched c-shape3)))
|
||||
(t/is (= (:name c-shape3) "Rect 3")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwc/update-shapes [(:id shape1)] update-shape)
|
||||
(dw/relocate-shapes #{(:id shape1)} (:id instance1) 2)
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-reset-changes
|
||||
|
@ -69,37 +256,561 @@
|
|||
{:name "Rect 1"
|
||||
:fill-color clr/white
|
||||
:fill-opacity 1})
|
||||
(thp/make-component :instance1
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
update-shape (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
update-fn (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
file (dwlh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:fill-color shape1) clr/white))
|
||||
(t/is (= (:fill-opacity shape1) 1))
|
||||
(t/is (= (:touched shape1) nil))
|
||||
(t/is (= (:fill-color c-shape1) clr/white))
|
||||
(t/is (= (:fill-opacity c-shape1) 1))
|
||||
(t/is (= (:touched c-shape1) nil)))))]
|
||||
(t/is (= (:fill-color shape1) clr/white))
|
||||
(t/is (= (:fill-opacity shape1) 1))
|
||||
(t/is (= (:touched shape1) nil))
|
||||
(t/is (= (:fill-color c-shape1) clr/white))
|
||||
(t/is (= (:fill-opacity c-shape1) 1))
|
||||
(t/is (= (:touched c-shape1) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwc/update-shapes [(:id shape1)] update-shape)
|
||||
(dch/update-shapes [(:id shape1)] update-fn)
|
||||
(dwl/reset-component (:id instance1))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-reset-children-add
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(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]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched instance1)))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (some? (:shape-ref shape1))))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape2)} (:id instance1) 0)
|
||||
(dwl/reset-component (:id instance1))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-reset-children-delete
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched instance1)))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (some? (:shape-ref shape1))))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwc/delete-shapes #{(:id shape1)})
|
||||
(dwl/reset-component (:id instance1))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-reset-children-move
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)
|
||||
(thp/id :shape3)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1 #--> Component-1
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 2 ---> Rect 2
|
||||
; Rect 3 ---> Rect 3
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect 1
|
||||
; Rect 2
|
||||
; Rect 3
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1 shape2 shape3] [c-group c-shape1 c-shape2 c-shape3] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (nil? (:touched shape1)))
|
||||
(t/is (some? (:shape-ref shape1)))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (nil? (:touched shape3)))
|
||||
(t/is (some? (:shape-ref shape3)))
|
||||
(t/is (= (:name shape3) "Rect 3"))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape1)))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (nil? (:touched c-shape2)))
|
||||
(t/is (= (:name c-shape2) "Rect 2"))
|
||||
(t/is (nil? (:touched c-shape3)))
|
||||
(t/is (= (:name c-shape3) "Rect 3")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape1)} (:id instance1) 2)
|
||||
(dwl/reset-component (:id instance1))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-component
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
update-fn (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (= (:fill-color shape1) clr/test))
|
||||
(t/is (= (:fill-opacity shape1) 0.5))
|
||||
(t/is (= (:touched shape1) nil))
|
||||
(t/is (= (:fill-color c-shape1) clr/test))
|
||||
(t/is (= (:fill-opacity c-shape1) 0.5))
|
||||
(t/is (= (:touched c-shape1) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dch/update-shapes [(:id shape1)] update-fn)
|
||||
(dwl/update-component (:id instance1))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-component-and-sync
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance2
|
||||
(thp/id :component-1)))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
update-fn (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:fill-opacity 0.5}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 1-2 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance2 (thp/get-shape state :instance2)
|
||||
|
||||
[[group shape2] [c-group c-shape2] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance2))]
|
||||
|
||||
(t/is (= (:fill-color shape2) clr/test))
|
||||
(t/is (= (:fill-opacity shape2) 0.5))
|
||||
(t/is (= (:touched shape2) nil))
|
||||
(t/is (= (:fill-color c-shape2) clr/test))
|
||||
(t/is (= (:fill-opacity c-shape2) 0.5))
|
||||
(t/is (= (:touched c-shape2) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dch/update-shapes [(:id shape1)] update-fn)
|
||||
(dwl/update-component-sync (:id instance1) (:id file))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-preserve-touched
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance2
|
||||
(thp/id :component-1)))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
instance2 (thp/get-shape state :instance2)
|
||||
|
||||
shape2 (cph/get-shape (wsh/lookup-page state)
|
||||
(first (:shapes instance2)))
|
||||
|
||||
update-fn1 (fn [shape]
|
||||
(merge shape {:fill-color clr/test
|
||||
:stroke-width 0.5}))
|
||||
|
||||
update-fn2 (fn [shape]
|
||||
(merge shape {:stroke-width 0.2}))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 1-2 #--> Rect 1-1
|
||||
; Rect 1* ---> Rect 1
|
||||
; #{:stroke-group}
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance2 (thp/get-shape state :instance2)
|
||||
|
||||
[[group shape2] [c-group c-shape2] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance2))]
|
||||
|
||||
(t/is (= (:fill-color shape2) clr/test))
|
||||
(t/is (= (:stroke-width shape2) 0.2))
|
||||
(t/is (= (:touched shape2 #{:stroke-group})))
|
||||
(t/is (= (:fill-color c-shape2) clr/test))
|
||||
(t/is (= (:stroke-width c-shape2) 0.5))
|
||||
(t/is (= (:touched c-shape2) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dch/update-shapes [(:id shape1)] update-fn1)
|
||||
(dch/update-shapes [(:id shape2)] update-fn2)
|
||||
(dwl/update-component-sync (:id instance1) (:id file))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-children-add
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)])
|
||||
(thp/sample-shape :shape2 :circle
|
||||
{:name "Circle 1"}))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
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]
|
||||
; Root Frame
|
||||
; Rect 1-1 #--> Rect 1-1
|
||||
; Circle 1 ---> Circle 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1-1
|
||||
; Circle 1
|
||||
; Rect 1
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1 shape2] [c-group c-shape1 c-shape2] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (nil? (:touched shape1)))
|
||||
(t/is (= (:name shape1) "Circle 1"))
|
||||
(t/is (some? (:shape-ref shape1)))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape1)))
|
||||
(t/is (= (:name c-shape1) "Circle 1"))
|
||||
(t/is (nil? (:touched c-shape2)))
|
||||
(t/is (= (:name c-shape2) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape2)} (:id instance1) 0)
|
||||
(dwl/update-component-sync (:id instance1) (:id file))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-children-delete
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)]))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1 #--> Component-1
|
||||
; Rect 2 ---> Rect 2
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect 2
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape2] [c-group c-shape2] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (= (:name shape2) "Rect 2"))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape2)))
|
||||
(t/is (= (:name c-shape2) "Rect 2")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwc/delete-shapes #{(:id shape1)})
|
||||
(dwl/update-component-sync (:id instance1) (:id file))
|
||||
:the/end)))))
|
||||
|
||||
(t/deftest test-update-children-move
|
||||
(t/async done
|
||||
(try
|
||||
(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 :instance1 :component-1
|
||||
[(thp/id :shape1)
|
||||
(thp/id :shape2)
|
||||
(thp/id :shape3)]))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
shape1 (thp/get-shape state :shape1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component-1 #--> Component-1
|
||||
; Rect 2 ---> Rect 2
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 3 ---> Rect 3
|
||||
;
|
||||
; [Component-1]
|
||||
; Component-1
|
||||
; Rect 2
|
||||
; Rect 1
|
||||
; Rect 3
|
||||
;
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group shape1 shape2 shape3] [c-group c-shape1 c-shape2 c-shape3] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (nil? (:touched group)))
|
||||
(t/is (nil? (:touched shape1)))
|
||||
(t/is (some? (:shape-ref shape1)))
|
||||
(t/is (= (:name shape1) "Rect 2"))
|
||||
(t/is (nil? (:touched shape2)))
|
||||
(t/is (some? (:shape-ref shape2)))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (nil? (:touched shape3)))
|
||||
(t/is (some? (:shape-ref shape3)))
|
||||
(t/is (= (:name shape3) "Rect 3"))
|
||||
(t/is (nil? (:touched c-group)))
|
||||
(t/is (nil? (:touched c-shape1)))
|
||||
(t/is (= (:name c-shape1) "Rect 2"))
|
||||
(t/is (nil? (:touched c-shape2)))
|
||||
(t/is (= (:name c-shape2) "Rect 1"))
|
||||
(t/is (nil? (:touched c-shape3)))
|
||||
(t/is (= (:name c-shape3) "Rect 3")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/relocate-shapes #{(:id shape1)} (:id instance1) 2)
|
||||
(dwl/update-component-sync (:id instance1) (:id file))
|
||||
:the/end)))))
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.test-helpers.pages :as thp]))
|
||||
|
||||
;; ---- Helpers to manage libraries and synchronization
|
||||
|
@ -85,7 +86,7 @@
|
|||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
|
||||
libs (dwlh/get-libraries state)
|
||||
libs (wsh/get-libraries state)
|
||||
component (cph/get-component libs (:component-id root-inst))
|
||||
|
||||
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
|
||||
|
@ -115,11 +116,44 @@
|
|||
|
||||
[shapes-inst shapes-main component]))
|
||||
|
||||
(defn resolve-instance-and-main-allow-dangling
|
||||
"Get the shape with the given id and all its children, and also
|
||||
the main component and all its shapes. Allows shapes with the
|
||||
corresponding component shape missing."
|
||||
[state root-inst-id]
|
||||
(let [page (thp/current-page state)
|
||||
root-inst (cph/get-shape page root-inst-id)
|
||||
|
||||
libs (wsh/get-libraries state)
|
||||
component (cph/get-component libs (:component-id root-inst))
|
||||
|
||||
shapes-inst (cph/get-children-with-self (:objects page) root-inst-id)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:shape-ref root-inst))
|
||||
|
||||
unique-refs (into #{} (map :shape-ref) shapes-inst)
|
||||
|
||||
main-exists? (fn [shape]
|
||||
(let [component-shape
|
||||
(cph/get-component-shape (:objects page) shape)
|
||||
|
||||
component
|
||||
(cph/get-component libs (:component-id component-shape))
|
||||
|
||||
main-shape
|
||||
(cph/get-shape component (:shape-ref shape))]
|
||||
|
||||
(t/is (some? main-shape))))]
|
||||
|
||||
;; Validate that the instance tree is well constructed
|
||||
(is-instance-root (first shapes-inst))
|
||||
|
||||
[shapes-inst shapes-main component]))
|
||||
|
||||
(defn resolve-component
|
||||
"Get the component with the given id and all its shapes."
|
||||
[state component-id]
|
||||
(let [page (thp/current-page state)
|
||||
libs (dwlh/get-libraries state)
|
||||
libs (wsh/get-libraries state)
|
||||
component (cph/get-component libs component-id)
|
||||
root-main (cph/get-component-root component)
|
||||
shapes-main (cph/get-children-with-self (:objects component) (:id root-main))]
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.layout :as layout]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]))
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]))
|
||||
|
||||
;; ---- Helpers to manage pages and objects
|
||||
|
||||
|
@ -96,19 +96,53 @@
|
|||
cp/process-changes (:redo-changes changes)))))))
|
||||
|
||||
(defn make-component
|
||||
[state label ids]
|
||||
[state instance-label component-label shape-ids]
|
||||
(let [page (current-page state)
|
||||
objects (wsh/lookup-page-objects state (:id page))
|
||||
shapes (dwg/shapes-for-grouping objects ids)
|
||||
shapes (dwg/shapes-for-grouping objects shape-ids)
|
||||
|
||||
[group changes]
|
||||
[group component-root changes]
|
||||
(dwlh/generate-add-component nil
|
||||
shapes
|
||||
(:objects page)
|
||||
(:id page)
|
||||
current-file-id)]
|
||||
|
||||
(swap! idmap assoc label (:id group))
|
||||
(swap! idmap assoc instance-label (:id group)
|
||||
component-label (:id component-root))
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes))))
|
||||
|
||||
(defn instantiate-component
|
||||
([state label component-id]
|
||||
(instantiate-component state label component-id current-file-id))
|
||||
([state label component-id file-id]
|
||||
(let [page (current-page state)
|
||||
libraries (wsh/get-libraries state)
|
||||
|
||||
[new-shape changes]
|
||||
(dwlh/generate-instantiate-component nil
|
||||
file-id
|
||||
component-id
|
||||
(gpt/point 100 100)
|
||||
page
|
||||
libraries)]
|
||||
|
||||
(swap! idmap assoc label (:id new-shape))
|
||||
(update state :workspace-data
|
||||
cp/process-changes (:redo-changes changes)))))
|
||||
|
||||
(defn move-to-library
|
||||
[state label name]
|
||||
(let [library-id (uuid/next)
|
||||
data (get state :workspace-data)]
|
||||
(swap! idmap assoc label library-id)
|
||||
(-> state
|
||||
(update :workspace-libraries
|
||||
assoc library-id {:id library-id
|
||||
:name name
|
||||
:data {:id library-id
|
||||
:components (:components data)}})
|
||||
(update :workspace-data
|
||||
assoc :components {} :pages [] :pages-index {}))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue