mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 21:41:38 +02:00
🎉 Update tests
This commit is contained in:
parent
0711fa700b
commit
b91f1959b4
4 changed files with 2289 additions and 2022 deletions
|
@ -1,24 +1,18 @@
|
|||
(ns frontend-tests.state-components-test
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.libraries-helpers :as dwlh]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[beicon.core :as rx]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[clojure.stacktrace :as stk]
|
||||
[frontend-tests.helpers.events :as the]
|
||||
[frontend-tests.helpers.libraries :as thl]
|
||||
[frontend-tests.helpers.pages :as thp]
|
||||
[linked.core :as lks]
|
||||
[potok.core :as ptk]))
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.types.container :as ctn]
|
||||
[app.common.types.file :as ctf]
|
||||
[app.main.data.workspace :as dw]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.events :as the]
|
||||
[frontend-tests.helpers.libraries :as thl]
|
||||
[frontend-tests.helpers.pages :as thp]
|
||||
[linked.core :as lks]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before thp/reset-idmap!})
|
||||
|
@ -37,7 +31,8 @@
|
|||
;; Uncomment to debug
|
||||
;; (ctf/dump-tree (get new-state :workspace-data)
|
||||
;; (get new-state :current-page-id)
|
||||
;; (get new-state :workspace-libraries))
|
||||
;; (get new-state :workspace-libraries)
|
||||
;; false true)
|
||||
|
||||
; Expected shape tree:
|
||||
;
|
||||
|
@ -54,8 +49,8 @@
|
|||
|
||||
[[group shape1] [c-group c-shape1] component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
|
@ -73,40 +68,6 @@
|
|||
(dwl/add-component)
|
||||
:the/end)))))
|
||||
|
||||
;; Remove definitely when we ensure that the other method works
|
||||
;; well in more advanced tests.
|
||||
#_(t/deftest test-add-component-from-single-shape
|
||||
(t/async
|
||||
done
|
||||
(let [state (-> thp/initial-state
|
||||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"}))]
|
||||
|
||||
(->> state
|
||||
(the/do-update (dw/select-shape (thp/id :shape1)))
|
||||
(the/do-watch-update dwl/add-component)
|
||||
(rx/do
|
||||
(fn [new-state]
|
||||
(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))
|
||||
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name group) "Component 1"))
|
||||
(t/is (= (:name component) "Component 1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-group) "Component 1"))
|
||||
|
||||
(thl/is-from-file group file))))
|
||||
|
||||
(rx/subs done #(throw %))))))
|
||||
|
||||
(t/deftest test-add-component-from-several-shapes
|
||||
(t/async
|
||||
done
|
||||
|
@ -120,17 +81,14 @@
|
|||
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
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Component 1
|
||||
; Rect 1
|
||||
; Rect-2
|
||||
;
|
||||
; [Component 1]
|
||||
; page1 / Component 1
|
||||
;
|
||||
(let [shape1 (thp/get-shape new-state :shape1)
|
||||
|
||||
|
@ -138,8 +96,8 @@
|
|||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
new-state
|
||||
(:parent-id shape1))
|
||||
|
||||
file (wsh/get-local-file new-state)]
|
||||
|
||||
|
@ -174,38 +132,36 @@
|
|||
(thp/id :shape2)]))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group #--> Group
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect-2 ---> Rect-2
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group
|
||||
; Rect 1
|
||||
; Rect-2
|
||||
;
|
||||
; [Group]
|
||||
; page1 / Group
|
||||
;
|
||||
; [Group]
|
||||
; Group
|
||||
; 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))
|
||||
(let [[[group shape1 shape2]
|
||||
[c-group c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(thp/id :group1))
|
||||
|
||||
file (wsh/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"))
|
||||
(t/is (= (:name component) "Group"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
(t/is (= (:name c-group) "Group"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect-2"))
|
||||
(t/is (= (:name group) "Group"))
|
||||
(t/is (= (:name component) "Group"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect-2"))
|
||||
(t/is (= (:name c-group) "Group"))
|
||||
|
||||
(thl/is-from-file group file))))]
|
||||
(thl/is-from-file group file))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -220,42 +176,39 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [[[instance1 shape1]
|
||||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(thp/id :instance1)
|
||||
true)
|
||||
new-state
|
||||
(thp/id :main1)
|
||||
true)
|
||||
|
||||
[[instance2 instance1' shape1']
|
||||
[c-instance2 c-instance1' c-shape1']
|
||||
component2]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id instance1))]
|
||||
new-state
|
||||
(:parent-id instance1))]
|
||||
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name instance1) "Rect 1"))
|
||||
|
@ -273,7 +226,7 @@
|
|||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :instance1))
|
||||
(dw/select-shape (thp/id :main1))
|
||||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
|
@ -284,34 +237,34 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
main1 (thp/get-shape state :main1)
|
||||
|
||||
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 (wsh/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 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Renamed component]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [libs (wsh/get-libraries new-state)
|
||||
component (ctf/get-component libs
|
||||
(:component-file main1)
|
||||
(:component-id main1))]
|
||||
(t/is (= (:name component)
|
||||
"Renamed component")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwl/rename-component (:component-id instance1) "Renamed component")
|
||||
:the/end))))
|
||||
store
|
||||
(dwl/rename-component (:component-id main1) "Renamed component")
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-duplicate-component
|
||||
(t/async
|
||||
|
@ -320,28 +273,28 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
main1 (thp/get-shape state :main1)
|
||||
component-id (:component-id main1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; page1 / Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [new-component-id (->> (get-in new-state
|
||||
[:workspace-data
|
||||
|
@ -354,20 +307,20 @@
|
|||
[c-instance1 c-shape1]
|
||||
component1]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:id instance1))
|
||||
new-state
|
||||
(:id main1))
|
||||
|
||||
[[c-component2 c-shape2]
|
||||
component2]
|
||||
(thl/resolve-component
|
||||
new-state
|
||||
new-component-id)]
|
||||
new-state
|
||||
new-component-id)]
|
||||
|
||||
(t/is (= (:name component2) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwl/duplicate-component {:id component-id})
|
||||
(dwl/duplicate-component thp/current-file-id component-id)
|
||||
:the/end))))
|
||||
|
||||
(t/deftest test-delete-component
|
||||
|
@ -377,13 +330,13 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
main1 (thp/get-shape state :main1)
|
||||
component-id (:component-id main1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
|
@ -391,21 +344,19 @@
|
|||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect-2
|
||||
; Rect 1
|
||||
;
|
||||
(let [[instance1 shape1]
|
||||
(let [[main1 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))
|
||||
(:id main1))
|
||||
|
||||
libs (wsh/get-libraries new-state)
|
||||
component (cph/get-component libs
|
||||
(:component-file instance1)
|
||||
(:component-id instance1))]
|
||||
component (ctf/get-component libs
|
||||
(:component-file main1)
|
||||
(:component-id main1))]
|
||||
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1))
|
||||
(t/is (nil? main1))
|
||||
(t/is (nil? shape1))
|
||||
(t/is (nil? component)))))]
|
||||
|
||||
(ptk/emit!
|
||||
|
@ -421,46 +372,45 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)]))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
component-id (thp/id :component-1)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (thp/id :component1)
|
||||
main1 (thp/get-shape state :main1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance2 shape2]
|
||||
[c-instance2 c-shape2]
|
||||
[[instance1 shape2]
|
||||
[c-instance1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
new-state
|
||||
new-instance-id)]
|
||||
|
||||
(t/is (not= (:id instance1) (:id instance2)))
|
||||
(t/is (not= (:id main1) (:id instance1)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Rect 1"))
|
||||
(t/is (= (:name instance1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name c-instance2) "Rect 1"))
|
||||
(t/is (= (:name c-instance1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1"))
|
||||
(t/is (= (:component-file instance2)
|
||||
(t/is (= (:component-file instance1)
|
||||
thp/current-file-id)))))]
|
||||
|
||||
(ptk/emit!
|
||||
|
@ -477,13 +427,13 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/move-to-library :lib1 "Library 1")
|
||||
(thp/sample-page))
|
||||
|
||||
library-id (thp/id :lib1)
|
||||
component-id (thp/id :component-1)
|
||||
component-id (thp/id :component1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
|
@ -498,19 +448,19 @@
|
|||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance2 shape2]
|
||||
[c-instance2 c-shape2]
|
||||
[[instance1 shape2]
|
||||
[c-instance1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
new-instance-id)]
|
||||
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance2) "Rect 1"))
|
||||
(t/is (= (:name instance1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name c-instance2) "Rect 1"))
|
||||
(t/is (= (:name c-instance1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1"))
|
||||
(t/is (= (:component-file instance2) library-id)))))]
|
||||
(t/is (= (:component-file instance1) library-id)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -526,32 +476,34 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
[(thp/id :shape1)]))
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/instantiate-component :instance1
|
||||
(thp/id :component1)))
|
||||
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
component-id (:component-id instance1)
|
||||
instance1 (thp/get-shape state :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 1
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [[instance2 shape1]
|
||||
(thl/resolve-noninstance
|
||||
new-state
|
||||
(:id instance1))]
|
||||
|
||||
(t/is (some? instance1))
|
||||
(t/is (some? shape1)))))]
|
||||
(t/is (some? instance2))
|
||||
(t/is (some? shape1)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
|
@ -566,28 +518,21 @@
|
|||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"}))
|
||||
|
||||
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 #--> Group
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Group]
|
||||
; Group
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
; page1 / Rect 1
|
||||
;
|
||||
; [Group]
|
||||
; page1 / Group
|
||||
;
|
||||
(let [page (thp/current-page new-state)
|
||||
shape1 (thp/get-shape new-state :shape1)
|
||||
|
@ -623,46 +568,41 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/group-shapes :group1
|
||||
[(thp/id :instance1)])
|
||||
(thp/make-component :instance2 :component-2
|
||||
[(thp/id :group1)]))
|
||||
(thp/make-component :main2 :component-2
|
||||
[(thp/id :main1)]))
|
||||
|
||||
file (wsh/get-local-file state)
|
||||
instance1 (thp/get-shape state :instance1)
|
||||
instance2 (thp/get-shape state :instance2)
|
||||
component-id (:component-id instance2)
|
||||
main1 (thp/get-shape state :main1)
|
||||
main2 (thp/get-shape state :main2)
|
||||
component-id (:component-id main2)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
; Rect 1 #--> Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; Rect 1
|
||||
; Rect 1 @--> Rect 1
|
||||
; Rect 1 ---> Rect 1
|
||||
; page1 / Rect 1
|
||||
;
|
||||
; [Rect 1]
|
||||
; page1 / Rect 1
|
||||
;
|
||||
(let [new-instance-id (-> new-state
|
||||
wsh/lookup-selected
|
||||
first)
|
||||
|
||||
[[instance3 shape3 shape4]
|
||||
[c-instance3 c-shape3 c-shape4]
|
||||
[[instance1 shape1 shape2]
|
||||
[c-instance1 c-shape1 c-shape2]
|
||||
component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
|
@ -670,19 +610,19 @@
|
|||
|
||||
; TODO: get and check the instance inside component [Rect-2]
|
||||
|
||||
(t/is (not= (:id instance1) (:id instance3)))
|
||||
(t/is (not= (:id main1) (:id instance1)))
|
||||
(t/is (= (:id component) component-id))
|
||||
(t/is (= (:name instance3) "Rect 1"))
|
||||
(t/is (= (:name shape3) "Rect 1"))
|
||||
(t/is (= (:name shape4) "Rect 1"))
|
||||
(t/is (= (:name c-instance3) "Rect 1"))
|
||||
(t/is (= (:name c-shape3) "Rect 1"))
|
||||
(t/is (= (:name c-shape4) "Rect 1")))))]
|
||||
(t/is (= (:name instance1) "Rect 1"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
(t/is (= (:name shape2) "Rect 1"))
|
||||
(t/is (= (:name c-instance1) "Rect 1"))
|
||||
(t/is (= (:name c-shape1) "Rect 1"))
|
||||
(t/is (= (:name c-shape2) "Rect 1")))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dwl/instantiate-component (:id file)
|
||||
(:component-id instance2)
|
||||
(:component-id main2)
|
||||
(gpt/point 100 100))
|
||||
:the/end))))
|
||||
|
||||
|
@ -693,38 +633,36 @@
|
|||
(thp/sample-page)
|
||||
(thp/sample-shape :shape1 :rect
|
||||
{:name "Rect 1"})
|
||||
(thp/make-component :instance1 :component-1
|
||||
(thp/make-component :main1 :component1
|
||||
[(thp/id :shape1)])
|
||||
(thp/move-to-library :lib1 "Library 1")
|
||||
(thp/sample-page)
|
||||
(thp/instantiate-component :instance2
|
||||
(thp/id :component-1)
|
||||
(thp/instantiate-component :instance1
|
||||
(thp/id :component1)
|
||||
(thp/id :lib1)))
|
||||
|
||||
library-id (thp/id :lib1)
|
||||
component-id (thp/id :component-1)
|
||||
file (wsh/get-local-file state)
|
||||
library-id (thp/id :lib1)
|
||||
|
||||
store (the/prepare-store state done
|
||||
(fn [new-state]
|
||||
; Expected shape tree:
|
||||
;
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group #--> Group
|
||||
; Rect 1 @--> <Library 1> Rect 1
|
||||
; Rect 1 ---> <Library 1> Rect 1
|
||||
; [Page]
|
||||
; Root Frame
|
||||
; Group
|
||||
; Rect 1 #--> <Library 1> Rect 1
|
||||
; Rect 1 ---> <Library 1> Rect 1
|
||||
;
|
||||
; [Group]
|
||||
; page1 / Group
|
||||
;
|
||||
; [Group]
|
||||
; Group
|
||||
; Rect 1 @--> <Library 1> Rect 1
|
||||
; Rect 1 ---> <Library 1> Rect 1
|
||||
;
|
||||
(let [instance2 (thp/get-shape new-state :instance2)
|
||||
(let [instance1 (thp/get-shape new-state :instance1)
|
||||
|
||||
[[group1 shape1 shape2] [c-group1 c-shape1 c-shape2] component]
|
||||
[[group1 shape1 shape2] [c-group1 c-shape1 c-shape2] _component]
|
||||
(thl/resolve-instance-and-main
|
||||
new-state
|
||||
(:parent-id instance2))]
|
||||
(:parent-id instance1))]
|
||||
|
||||
(t/is (= (:name group1) "Group"))
|
||||
(t/is (= (:name shape1) "Rect 1"))
|
||||
|
@ -735,14 +673,13 @@
|
|||
(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-group1) (:id file)))
|
||||
(t/is (= (:component-file c-shape1) library-id))
|
||||
(t/is (= (:component-file c-shape2) nil)))))]
|
||||
|
||||
(ptk/emit!
|
||||
store
|
||||
(dw/select-shape (thp/id :instance2))
|
||||
(dw/select-shape (thp/id :instance1))
|
||||
dwg/group-selected
|
||||
(dwl/add-component)
|
||||
:the/end))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue