diff --git a/frontend/test/frontend_tests/helpers/libraries.cljs b/frontend/test/frontend_tests/helpers/libraries.cljs index c00776136d..b7a24f5050 100644 --- a/frontend/test/frontend_tests/helpers/libraries.cljs +++ b/frontend/test/frontend_tests/helpers/libraries.cljs @@ -9,6 +9,7 @@ [app.common.pages.helpers :as cph] [app.common.types.component :as ctk] [app.common.types.container :as ctn] + [app.common.types.file :as ctf] [app.main.data.workspace.state-helpers :as wsh] [cljs.pprint :refer [pprint]] [cljs.test :as t :include-macros true] @@ -16,6 +17,29 @@ ;; ---- Helpers to manage libraries and synchronization +(defn is-main-instance-root + [shape] + (t/is (nil? (:shape-ref shape))) + (t/is (some? (:component-id shape))) + (t/is (= (:component-root? shape) true))) + +(defn is-main-instance-subroot + [shape] + (t/is (some? (:component-id shape))) ; shape-ref may or may be not nil + (t/is (= (:component-root? shape) true))) + +(defn is-main-instance-child + [shape] + (t/is (nil? (:component-id shape))) ; shape-ref may or may be not nil + (t/is (nil? (:component-file shape))) + (t/is (nil? (:component-root? shape)))) + +(defn is-main-instance-inner + [shape] + (if (some? (:component-id shape)) + (is-main-instance-subroot shape) + (is-main-instance-child shape))) + (defn is-instance-root [shape] (t/is (some? (:shape-ref shape))) @@ -58,27 +82,25 @@ (defn resolve-instance "Get the shape with the given id and all its children, and verify that they are a well constructed instance tree." - [state root-inst-id] - (let [page (thp/current-page state) - root-inst (ctn/get-shape page root-inst-id) - shapes-inst (cph/get-children-with-self (:objects page) - root-inst-id)] - (is-instance-root (first shapes-inst)) - (run! is-instance-inner (rest shapes-inst)) + [state root-id] + (let [page (thp/current-page state) + shapes (cph/get-children-with-self (:objects page) + root-id)] + (is-instance-root (first shapes)) + (run! is-instance-inner (rest shapes)) - shapes-inst)) + shapes)) (defn resolve-noninstance "Get the shape with the given id and all its children, and verify that they are not a component instance." - [state root-inst-id] - (let [page (thp/current-page state) - root-inst (ctn/get-shape page root-inst-id) - shapes-inst (cph/get-children-with-self (:objects page) - root-inst-id)] - (run! is-noninstance shapes-inst) + [state root-id] + (let [page (thp/current-page state) + shapes (cph/get-children-with-self (:objects page) + root-id)] + (run! is-noninstance shapes) - shapes-inst)) + shapes)) (defn resolve-instance-and-main "Get the shape with the given id and all its children, and also @@ -87,38 +109,39 @@ (resolve-instance-and-main state root-inst-id false)) ([state root-inst-id subinstance?] - (let [page (thp/current-page state) - root-inst (ctn/get-shape page root-inst-id) + (let [page (thp/current-page state) + root-inst (ctn/get-shape page root-inst-id) + main-instance? (:main-instance? root-inst) - libs (wsh/get-libraries state) - component (cph/get-component libs (:component-id root-inst)) + libs (wsh/get-libraries state) + component (ctf/get-component libs (:component-id root-inst)) + library (ctf/get-component-library libs 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) + shapes-inst (cph/get-children-with-self (:objects page) root-inst-id) + shapes-main (ctf/get-component-shapes (:data library) component) + 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 - (ctn/get-shape component (:shape-ref shape))] - + (let [main-shape (ctf/get-ref-shape (:data library) component shape)] (t/is (some? main-shape))))] ;; Validate that the instance tree is well constructed - (if subinstance? - (is-instance-subroot (first shapes-inst)) - (is-instance-root (first shapes-inst))) - (run! is-instance-inner (rest shapes-inst)) - (t/is (= (count shapes-inst) - (count shapes-main) - (count unique-refs))) - (run! main-exists? shapes-inst) + (if main-instance? + (do + (if subinstance? + (is-main-instance-subroot (first shapes-inst)) + (is-main-instance-root (first shapes-inst))) + (run! is-main-instance-inner (rest shapes-inst))) + (do + (if subinstance? + (is-instance-subroot (first shapes-inst)) + (is-instance-root (first shapes-inst))) + (run! is-instance-inner (rest shapes-inst)))) + + (t/is (= (count shapes-inst) (count shapes-main))) + (when-not main-instance? + (t/is (= (count shapes-inst) (count unique-refs))) + (run! main-exists? shapes-inst)) [shapes-inst shapes-main component]))) @@ -131,24 +154,11 @@ root-inst (ctn/get-shape page root-inst-id) libs (wsh/get-libraries state) - component (cph/get-component libs (:component-id root-inst)) + component (ctf/get-component libs (:component-id root-inst)) + library (ctf/get-component-library libs 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 - (ctn/get-shape component (:shape-ref shape))] - - (t/is (some? main-shape))))] + shapes-main (ctf/get-component-shapes (:data library) component)] ;; Validate that the instance tree is well constructed (is-instance-root (first shapes-inst)) @@ -158,14 +168,12 @@ (defn resolve-component "Get the component with the given id and all its shapes." [state component-id] - (let [page (thp/current-page state) - libs (wsh/get-libraries state) - component (cph/get-component libs component-id) - root-main (ctk/get-component-root component) - shapes-main (cph/get-children-with-self (:objects component) (:id root-main))] + (let [libs (wsh/get-libraries state) + component (ctf/get-component libs component-id) + library (ctf/get-component-library libs component) + shapes-main (ctf/get-component-shapes (:data library) component)] ;; Validate that the component tree is well constructed (run! is-noninstance shapes-main) [shapes-main component])) - diff --git a/frontend/test/frontend_tests/helpers/pages.cljs b/frontend/test/frontend_tests/helpers/pages.cljs index 6129eea42c..cc565e59f9 100644 --- a/frontend/test/frontend_tests/helpers/pages.cljs +++ b/frontend/test/frontend_tests/helpers/pages.cljs @@ -7,20 +7,14 @@ (ns frontend-tests.helpers.pages (:require [app.common.geom.point :as gpt] - [app.common.geom.shapes :as gsh] [app.common.pages :as cp] [app.common.pages.helpers :as cph] [app.common.types.shape :as cts] [app.common.uuid :as uuid] - [app.main.data.workspace :as dw] [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.state-helpers :as wsh] - [beicon.core :as rx] - [cljs.pprint :refer [pprint]] - [cljs.test :as t :include-macros true] - [potok.core :as ptk])) + [app.main.data.workspace.state-helpers :as wsh])) ;; ---- Helpers to manage pages and objects @@ -32,10 +26,12 @@ :workspace-layout layout/default-layout :workspace-global layout/default-global :workspace-data {:id current-file-id + :options {:components-v2 true} :components {} :pages [] :pages-index {}} - :workspace-libraries {}}) + :workspace-libraries {} + :features {:components-v2 true}}) (def ^:private idmap (atom {})) @@ -56,6 +52,11 @@ (let [page (current-page state)] (get-in page [:objects (id label)]))) +(defn get-children + [state label] + (let [page (current-page state)] + (cph/get-children (:objects page) (id label)))) + (defn sample-page ([state] (sample-page state {})) ([state {:keys [id name] :as props @@ -106,7 +107,7 @@ objects (wsh/lookup-page-objects state (:id page)) shapes (dwg/shapes-for-grouping objects shape-ids) - [group component-root changes] + [group component-id changes] (dwlh/generate-add-component nil shapes (:objects page) @@ -115,7 +116,7 @@ true)] (swap! idmap assoc instance-label (:id group) - component-label (:id component-root)) + component-label component-id) (update state :workspace-data cp/process-changes (:redo-changes changes)))) @@ -148,7 +149,9 @@ assoc library-id {:id library-id :name name :data {:id library-id + :options (:options data) + :pages (:pages data) + :pages-index (:pages-index data) :components (:components data)}}) (update :workspace-data assoc :components {} :pages [] :pages-index {})))) - diff --git a/frontend/test/frontend_tests/state_components_sync_test.cljs b/frontend/test/frontend_tests/state_components_sync_test.cljs index 538a809e9e..9517c93be4 100644 --- a/frontend/test/frontend_tests/state_components_sync_test.cljs +++ b/frontend/test/frontend_tests/state_components_sync_test.cljs @@ -3,27 +3,19 @@ ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; ;; Copyright (c) KALEIDOS INC - + (ns frontend-tests.state-components-sync-test (:require [app.common.colors :as clr] - [app.common.data :as d] - [app.common.geom.point :as gpt] - [app.common.pages.helpers :as cph] - [app.common.types.container :as ctn] [app.main.data.workspace :as dw] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.libraries :as dwl] - [app.main.data.workspace.libraries-helpers :as dwlh] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.state-helpers :as wsh] - [beicon.core :as rx] - [cljs.pprint :refer [pprint]] [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 @@ -33,848 +25,871 @@ (t/deftest test-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)])) + (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))) - shape1 (thp/get-shape state :shape1) + [_group1 shape1'] + (thl/resolve-instance state (thp/id :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 + ; Rect 1 + ; Rect 1 #--> Rect 1 + ; Rect 1* ---> Rect 1 + ; #{:fill-group} + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[group shape1] [c-group c-shape1] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1))] - store (the/prepare-store state done - (fn [new-state] - ; Expected shape tree: - ; - ; [Page] - ; Root Frame - ; Rect 1 #--> Rect 1 - ; Rect 1* ---> Rect 1 (color, opacity) - ; #{:fill-group} - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - (let [[[group shape1] [c-group c-shape1] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance1))] + (t/is (= (:name group) "Rect 1")) + (t/is (= (:touched group) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:touched shape1) #{:fill-group})) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:touched shape1) #{:fill-group})) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - - (t/is (= (:name c-group) "Rect 1")) - (t/is (= (:touched c-group) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (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/is (= (:name c-group) "Rect 1")) + (t/is (= (:touched c-group) nil)) + (t/is (= (:name c-shape1) "Rect 1")) + (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')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + :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"})) + (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) + 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 * #--> Rect 1 - ; #{:shapes-group} - ; Circle 1 - ; Rect 1 ---> Rect 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - (let [[[group shape1 shape2] [c-group c-shape1] component] - (thl/resolve-instance-and-main-allow-dangling - new-state - (thp/id :instance1))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Rect 1 + ; Rect 1 + ; Rect 1* #--> Rect 1 + ; #{:shapes-group} + ; Circle 1 + ; Rect 1 ---> Rect 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[group shape1 shape2] [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 (= (:touched group) #{:shapes-group})) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:shape-ref shape1) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (not= (:shape-ref shape2) nil)) + (t/is (= (:name group) "Rect 1")) + (t/is (= (:touched group) #{:shapes-group})) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (not= (:shape-ref shape2) 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)))))] + (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) - :the/end))))) + (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)])) + (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))) - shape1 (thp/get-shape state :shape1) + [_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* #--> Component 1 - ; #{:shapes-group} - ; Rect 2 ---> Rect 2 - ; - ; [Component 1] - ; Component 1 - ; Rect 1 - ; Rect 2 - ; - (let [[[group shape2] [c-group c-shape2 c-shape3] component] - (thl/resolve-instance-and-main-allow-dangling - new-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) #{:shapes-group})) - (t/is (not= (:shape-ref group) nil)) - (t/is (= (:name shape2) "Rect 2")) - (t/is (= (:touched shape2) nil)) - (t/is (not= (:shape-ref shape2) nil)) + (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-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:shape-ref c-shape2) nil)) - (t/is (= (:name c-shape3) "Rect 2")) - (t/is (= (:touched c-shape3) nil)) - (t/is (= (:shape-ref c-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)))))] - (ptk/emit! - store - (dwsh/delete-shapes #{(:id shape1)}) - :the/end))))) + (ptk/emit! + store + (dwsh/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)])) + (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))) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) + [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* #--> 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 [[[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))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Component 1 + ; Rect 1 + ; Rect 2 + ; Rect 3 + ; Component 1* #--> Component 1 + ; #{:shapes-group} + ; Rect 2 ---> Rect 2 + ; Rect 1 ---> Rect 1 + ; Rect 3 ---> Rect 3 + ; + ; [Component 1] + ; page1 / 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 (= (:touched group) #{:shapes-group})) - (t/is (= (:name shape1) "Rect 2")) - (t/is (= (:touched shape1) nil)) - (t/is (not= (:shape-ref shape1) nil)) - (t/is (= (:name shape2) "Rect 1")) - (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 group) "Component 1")) + (t/is (= (:touched group) #{:shapes-group})) + (t/is (= (:name shape1) "Rect 2")) + (t/is (= (:touched shape1) nil)) + (t/is (not= (:shape-ref shape1) nil)) + (t/is (= (:name shape2) "Rect 1")) + (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)))))] + (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 instance1) 2) - :the/end))))) + (ptk/emit! + store + (dw/relocate-shapes #{(:id shape1')} (:id group1') 2) + :the/end)))) (t/deftest test-touched-from-lib - (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/move-to-library :lib1 "Library 1") - (thp/sample-page) - (thp/instantiate-component :instance2 - (thp/id :component-1) - (thp/id :lib1))) + (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/move-to-library :lib1 "Library 1") + (thp/sample-page) + (thp/instantiate-component :instance1 + (thp/id :component1) + (thp/id :lib1))) - [instance2 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [_group1 shape1'] + (thl/resolve-instance state (thp/id :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 #--> Rect 1 + ; Rect 1* ---> Rect 1 + ; #{:fill-group} + ; + (let [[[group shape1] [c-group c-shape1] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1))] - store (the/prepare-store state done - (fn [new-state] - ; Expected shape tree: - ; - ; [Page] - ; Root Frame - ; Rect 1 #--> Rect 1 - ; Rect 1* ---> Rect 1 (color, opacity) - ; #{:fill-group} - ; - (let [[[group shape1] [c-group c-shape1] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name group) "Rect 1")) + (t/is (= (:touched group) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:touched shape1) #{:fill-group})) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:touched shape1) #{:fill-group})) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:name c-group) "Rect 1")) + (t/is (= (:touched c-group) nil)) + (t/is (= (:name c-shape1) "Rect 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/white)) + (t/is (= (:fill-opacity c-shape1) 1)))))] - (t/is (= (:name c-group) "Rect 1")) - (t/is (= (:touched c-group) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (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 shape2)] update-fn) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + :the/end)))) (t/deftest test-touched-nested-upper - (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :main2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [_instance2 _instance1 shape1' _shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1* ---> Circle 1 + ; #{:fill-group} + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 - ; Circle 1* ---> Circle 1 (color, opacity) - ; #{:fill-group} - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) #{:fill-group})) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/white)) + (t/is (= (:fill-opacity shape2) 1)) - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/white)) + (t/is (= (:fill-opacity c-shape2) 1)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) #{:fill-group})) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) - - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + :the/end)))) (t/deftest test-touched-nested-lower-near (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :instance2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [_instance2 _instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1* ---> Rect 1 + ; #{:fill-group} + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 (color, opacity) - ; #{:fill-group} - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) #{:fill-group})) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/white)) + (t/is (= (:fill-opacity c-shape2) 1)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) #{:fill-group})) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:fill-opacity shape2) 0.5)) - - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + :the/end)))) (t/deftest test-touched-nested-lower-remote (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :instance2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [instance2 _instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1* ---> Rect 1 + ; #{:fill-group} + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 (color, opacity) - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1* ---> Rect 1 (color, opacity) - ; #{:fill-group} - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) #{:fill-group})) + (t/is (= (:fill-color c-shape2) clr/test)) + (t/is (= (:fill-opacity c-shape2) 0.5)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:fill-opacity shape2) 0.5)) + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component (:id instance2)) + :the/end)))) - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) #{:fill-group})) - (t/is (= (:fill-color c-shape2) clr/test)) - (t/is (= (:fill-opacity c-shape2) 0.5)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance2)) - :the/end))))) - -; === Test reset changes ====================== +;; ; === Test reset changes ====================== (t/deftest test-reset-changes (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)])) + (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))) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) + [instance1 shape1'] + (thl/resolve-instance state (thp/id :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 + ; Rect 1 + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[group shape1] [c-group c-shape1] _component] + (thl/resolve-instance-and-main + new-state + (:id instance1))] - 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-1 - ; Rect 1 - ; - (let [[[group shape1] [c-group c-shape1] component] - (thl/resolve-instance-and-main - new-state - (:id instance1))] + (t/is (= (:name group) "Rect 1")) + (t/is (= (:touched group) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:fill-color shape1) clr/white)) + (t/is (= (:fill-opacity shape1) 1)) + (t/is (= (:touched shape1) nil)) - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:fill-color shape1) clr/white)) - (t/is (= (:fill-opacity shape1) 1)) - (t/is (= (:touched shape1) nil)) + (t/is (= (:name c-group) "Rect 1")) + (t/is (= (:touched c-group) nil)) + (t/is (= (:name c-shape1) "Rect 1")) + (t/is (= (:fill-color c-shape1) clr/white)) + (t/is (= (:fill-opacity c-shape1) 1)) + (t/is (= (:touched c-shape1) nil)))))] - (t/is (= (:name c-group) "Rect 1")) - (t/is (= (:touched c-group) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (t/is (= (:fill-color c-shape1) clr/white)) - (t/is (= (:fill-opacity c-shape1) 1)) - (t/is (= (:touched c-shape1) nil)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - (dwl/reset-component (:id instance1)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (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"})) + (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) + 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 #--> Rect 1 - ; Rect 1 ---> Rect 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - (let [[[group shape1] [c-group c-shape1] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance1))] + 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] + ; page1 / Rect 1 + ; + (let [[[group shape1] [c-group c-shape1] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1))] - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (not= (:shape-ref group) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:touched shape1) nil)) - (t/is (not= (:shape-ref shape1) nil)) + (t/is (= (:name group) "Rect 1")) + (t/is (= (:touched group) nil)) + (t/is (not= (:shape-ref group) nil)) + (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)))))] + (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) - (dwl/reset-component (:id instance1)) - :the/end))))) + (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)])) + (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))) - instance1 (thp/get-shape state :instance1) - shape1 (thp/get-shape state :shape1) + [instance1 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 #--> Component 1 - ; Rect 1 ---> Rect 1 - ; Rect 2 ---> Rect 2 - ; - ; [Component 1] - ; Component 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 :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 + ; 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 + 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 (= (: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 group) "Component 1")) + (t/is (= (:touched group) nil)) + (t/is (not= (:shape-ref group) nil)) + (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 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-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)}) - (dwl/reset-component (:id instance1)) - :the/end))))) + (ptk/emit! + store + (dwsh/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)])) + (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))) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) + [instance1 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 #--> 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 [[[group shape1 shape2 shape3] [c-group c-shape1 c-shape2 c-shape3] component] - (thl/resolve-instance-and-main - new-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 + ; Rect 3 + ; Component 1 #--> Component 1 + ; Rect 1 ---> Rect 1 + ; Rect 2 ---> Rect 2 + ; Rect 3 ---> Rect 3 + ; + ; [Component 1] + ; page1 / Component 1 + ; + (let [[[group shape1 shape2 shape3] [c-group c-shape1 c-shape2 c-shape3] _component] + (thl/resolve-instance-and-main + 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 (= (: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 group) "Component 1")) + (t/is (= (:touched group) nil)) + (t/is (not= (:shape-ref group) nil)) + (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)))))] + (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 instance1) 2) - (dwl/reset-component (:id instance1)) - :the/end))))) + (ptk/emit! + store + (dw/relocate-shapes #{(:id shape1')} (:id instance1) 2) + (dwl/reset-component (:id instance1)) + :the/end)))) (t/deftest test-reset-from-lib (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/make-component :instance1 :component1 [(thp/id :shape1)]) (thp/move-to-library :lib1 "Library 1") (thp/sample-page) (thp/instantiate-component :instance2 - (thp/id :component-1) + (thp/id :component1) (thp/id :lib1))) [instance2 shape2] (thl/resolve-instance state (thp/id :instance2)) - 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: @@ -884,10 +899,10 @@ ; Rect 1 #--> Rect 1 ; Rect 1 ---> Rect 1 ; - (let [[[group shape1] [c-group c-shape1] component] + (let [[[group shape1] [c-group c-shape1] _component] (thl/resolve-instance-and-main - new-state - (:id instance2))] + new-state + (:id instance2))] (t/is (= (:name group) "Rect 1")) (t/is (= (:touched group) nil)) @@ -905,1048 +920,1352 @@ (ptk/emit! store - (dch/update-shapes [(:id shape2)] update-fn) + (dch/update-shapes [(:id shape2)] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) (dwl/reset-component (:id instance2)) - :the/end))))) + :the/end)))) (t/deftest test-reset-nested-upper (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :main2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [instance2 _instance1 shape1' _shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/white)) + (t/is (= (:fill-opacity shape2) 1)) - ; TODO: get and check the instance inside component [Group] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/white)) + (t/is (= (:fill-opacity c-shape2) 1)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) - - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - (dwl/reset-component (:id instance2)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/reset-component (:id instance2)) + :the/end)))) (t/deftest test-reset-nested-lower-near (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :instance2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [instance2 instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 (color, opacity) - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/white)) + (t/is (= (:fill-opacity shape2) 1)) - ; TODO: get and check the instance inside component [Group] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/white)) + (t/is (= (:fill-opacity c-shape2) 1)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) - - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance1)) - (dwl/reset-component (:id instance2)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component (:id instance1)) + (dwl/reset-component (:id instance2)) + :the/end)))) (t/deftest test-reset-nested-lower-remote (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :instance2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [instance2 instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1* ---> Rect 1 + ; #{:fill-group} + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; (remote-synced) + ; Rect 1 ---> Rect 1 + ; (remote-synced) + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - 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 - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 (color, opacity) - ; #{:fill-group} - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/white)) + (t/is (= (:fill-opacity shape2) 1)) - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) #{:fill-group})) + (t/is (= (:fill-color c-shape2) clr/test)) + (t/is (= (:fill-opacity c-shape2) 0.5)))))] - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component (:id instance2)) + (dwl/reset-component (:id instance1)) + :the/end)))) - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) #{:fill-group})) - (t/is (= (:fill-color c-shape2) clr/test)) - (t/is (= (:fill-opacity c-shape2) 0.5)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance2)) - (dwl/reset-component (:id instance1)) - :the/end))))) - -; === Test update component ====================== +;; ; === Test update component ====================== (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)]) - (thp/instantiate-component :instance2 - (thp/id :component-1))) + (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/instantiate-component :instance2 + (thp/id :component1))) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) - instance2 (thp/get-shape state :instance2) + [instance1 shape1'] + (thl/resolve-instance state (thp/id :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 + ; Rect 1 + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 <== (not updated) + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[main1 shape1] [c-main1 c-shape1] component1] + (thl/resolve-instance-and-main + new-state + (thp/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 (color, opacity) - ; Rect 1-2 - ; Rect 1 ---> Rect 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 (color, opacity) - ; - (let [[[instance1 shape1] [c-instance1 c-shape1] component1] - (thl/resolve-instance-and-main - new-state - (:id instance1)) + [[instance1 shape2] [c-instance1 c-shape2] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - [[instance2 shape2] [c-instance2 c-shape2] component2] - (thl/resolve-instance-and-main - new-state - (:id instance2))] + [[instance2 shape3] [c-instance2 c-shape3] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:touched shape1) nil)) + (t/is (= (:name main1) "Rect 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) - (t/is (= (:name instance2) "Rect 1")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) - (t/is (= (:touched shape2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) (:id c-shape1))) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (t/is (= (:fill-color c-shape1) clr/test)) - (t/is (= (:fill-opacity c-shape1) 0.5)) - (t/is (= (:touched c-shape1) nil)) + (t/is (= (:name instance2) "Rect 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape3) "Rect 1")) + (t/is (= (:fill-color shape3) clr/white)) + (t/is (= (:fill-opacity shape3) 1)) + (t/is (= (:touched shape3) nil)) + (t/is (= (:shape-ref shape3) (:id c-shape1))) - (t/is (= component1 component2)) - (t/is (= c-instance2 c-instance1)) - (t/is (= c-shape2 c-shape1)))))] + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape2 c-shape1)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape3 c-shape1)))))] - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - (dwl/update-component (:id instance1)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (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))) + (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/instantiate-component :instance2 + (thp/id :component1))) - file (wsh/get-local-file state) + file (wsh/get-local-file state) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) - instance2 (thp/get-shape state :instance2) + [instance1 shape1'] + (thl/resolve-instance state (thp/id :instance1)) - update-fn (fn [shape] - (merge shape {:fill-color clr/test - :fill-opacity 0.5})) + [_instance2 _shape1''] + (thl/resolve-instance state (thp/id :instance2)) - store (the/prepare-store state done - (fn [new-state] - ; Expected shape tree: - ; - ; [Page] - ; Root Frame - ; Rect 1 #--> Rect 1 - ; Rect 1 ---> Rect 1 (color, opacity) - ; Rect 1 #--> Rect 1 - ; Rect 1 ---> Rect 1 (color, opacity) - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 (color, opacity) - ; - (let [[[instance1 shape1] [c-instance1 c-shape1] component1] - (thl/resolve-instance-and-main - new-state - (:id instance1)) + 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] + ; page1 / Rect 1 + ; + (let [[[main1 shape1] [c-main1 c-shape1] component1] + (thl/resolve-instance-and-main + new-state + (thp/id :main1)) - [[instance2 shape2] [c-instance2 c-shape2] component2] - (thl/resolve-instance-and-main - new-state - (:id instance2))] + [[instance1 shape2] [c-instance1 c-shape2] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:touched shape1) nil)) + [[instance2 shape3] [c-instance2 c-shape3] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - (t/is (= (:name instance2) "Rect 1")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:fill-opacity shape2) 0.5)) - (t/is (= (:touched shape2) nil)) + (t/is (= (:name main1) "Rect 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (t/is (= (:fill-color c-shape1) clr/test)) - (t/is (= (:fill-opacity c-shape1) 0.5)) - (t/is (= (:touched c-shape1) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) (:id c-shape1))) - (t/is (= component1 component2)) - (t/is (= c-instance2 c-instance1)) - (t/is (= c-shape2 c-shape1)))))] + (t/is (= (:name instance2) "Rect 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape3) "Rect 1")) + (t/is (= (:fill-color shape3) clr/test)) + (t/is (= (:fill-opacity shape3) 0.5)) + (t/is (= (:touched shape3) nil)) + (t/is (= (:shape-ref shape3) (:id c-shape1))) - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - (dwl/update-component-sync (:id instance1) (:id file)) - :the/end))))) + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape2 c-shape1)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape3 c-shape1)))))] + + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (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))) + (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/instantiate-component :instance2 + (thp/id :component1))) - file (wsh/get-local-file state) + file (wsh/get-local-file state) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) - instance2 (thp/get-shape state :instance2) + [instance1 shape1'] + (thl/resolve-instance state (thp/id :instance1)) - shape2 (ctn/get-shape (wsh/lookup-page state) - (first (:shapes instance2))) + [_instance2 shape1''] + (thl/resolve-instance state (thp/id :instance2)) - update-fn1 (fn [shape] - (merge shape {:fill-color clr/test - :stroke-width 0.5})) + 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 + ; #{:stroke-group} + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[main1 shape1] [c-main1 c-shape1] component1] + (thl/resolve-instance-and-main + new-state + (thp/id :main1)) - update-fn2 (fn [shape] - (merge shape {:stroke-width 0.2})) + [[instance1 shape2] [c-instance1 c-shape2] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - store (the/prepare-store state done - (fn [new-state] - ; Expected shape tree: - ; - ; [Page] - ; Root Frame - ; Rect 1 #--> Rect 1 - ; Rect 1 ---> Rect 1 (color, stroke) - ; Rect 1 #--> Rect 1 - ; Rect 1* ---> Rect 1 (color, stroke2) - ; #{:stroke-group} - ; - ; [Rect 1] - ; Rect 1-1 - ; Rect 1 (color, stroke) - ; - (let [[[instance1 shape1] [c-instance1 c-shape1] component1] - (thl/resolve-instance-and-main - new-state - (:id instance1)) + [[instance2 shape3] [c-instance2 c-shape3] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - [[instance2 shape2] [c-instance2 c-shape2] component2] - (thl/resolve-instance-and-main - new-state - (:id instance2))] + (t/is (= (:name main1) "Rect 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:stroke-width shape1) 0.5)) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:stroke-width shape1) 0.5)) - (t/is (= (:touched shape1) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:stroke-width shape2) 0.5)) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) (:id c-shape1))) - (t/is (= (:name instance2) "Rect 1")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:stroke-width shape2) 0.2)) - (t/is (= (:touched shape2) #{:stroke-group})) + (t/is (= (:name instance2) "Rect 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape3) "Rect 1")) + (t/is (= (:fill-color shape3) clr/test)) + (t/is (= (:stroke-width shape3) 0.2)) + (t/is (= (:touched shape3) #{:stroke-group})) + (t/is (= (:shape-ref shape3) (:id c-shape1))) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (t/is (= (:fill-color c-shape1) clr/test)) - (t/is (= (:stroke-width c-shape1) 0.5)) - (t/is (= (:touched c-shape1) nil)) + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape2 c-shape1)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape3 c-shape1)))))] - (t/is (= component1 component2)) - (t/is (= c-instance2 c-instance1)) - (t/is (= c-shape2 c-shape1)))))] - - (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))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :stroke-width 0.5}))) + (dch/update-shapes [(:id shape1'')] + (fn [shape] + (merge shape {:stroke-width 0.2}))) + (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"})) + (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/instantiate-component :instance2 + (thp/id :component1)) + (thp/sample-shape :shape2 :circle + {:name "Circle 1"})) - file (wsh/get-local-file state) + file (wsh/get-local-file state) - instance1 (thp/get-shape state :instance1) - shape2 (thp/get-shape state :shape2) + 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 #--> Rect 1 - ; Circle 1 ---> Circle 1 - ; Rect 1 ---> Rect 1 - ; - ; [Rect 1] - ; Rect 1 - ; Circle 1 - ; Rect 1 - ; - (let [[[group shape1 shape2] - [c-group c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance1))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Rect 1 + ; Circle 1 + ; Rect 1 + ; Rect 1 #--> Rect 1 + ; Circle 1 ---> Circle 1 + ; Rect 1 ---> Rect 1 + ; Rect 1 #--> Rect 1 + ; Circle 1 ---> Circle 1 + ; Rect 1 ---> Rect 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + (let [[[main1 shape1 shape2] + [c-main1 c-shape1 c-shape2] component1] + (thl/resolve-instance-and-main + new-state + (thp/id :main1)) - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (not= (:shape-ref group) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (not= (:shape-ref shape1) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (not= (:shape-ref shape2) nil)) + [[instance1 shape3 shape4] + [c-instance1 c-shape3 c-shape4] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - (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) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:shape-ref c-shape1) nil)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:shape-ref c-shape2) nil)))))] + [[instance2 shape5 shape6] + [c-instance2 c-shape5 c-shape6] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - (ptk/emit! - store - (dw/relocate-shapes #{(:id shape2)} (:id instance1) 0) - (dwl/update-component-sync (:id instance1) (:id file)) - :the/end))))) + (t/is (= (:name main1) "Rect 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) nil)) + + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape3) "Circle 1")) + (t/is (= (:touched shape3) nil)) + (t/is (= (:shape-ref shape3) (:id c-shape1))) + (t/is (= (:name shape4) "Rect 1")) + (t/is (= (:touched shape4) nil)) + (t/is (= (:shape-ref shape4) (:id c-shape2))) + + (t/is (= (:name instance2) "Rect 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape5) "Circle 1")) + (t/is (= (:touched shape5) nil)) + (t/is (= (:shape-ref shape5) (:id c-shape1))) + (t/is (= (:name shape6) "Rect 1")) + (t/is (= (:touched shape6) nil)) + (t/is (= (:shape-ref shape4) (:id c-shape2))) + + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-shape2 shape2)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape3 c-shape1)) + (t/is (= c-shape4 c-shape2)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape5 c-shape1)) + (t/is (= c-shape6 c-shape2)))))] + + (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)])) + (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)) + (thp/instantiate-component :instance2 + (thp/id :component1))) - file (wsh/get-local-file state) + file (wsh/get-local-file state) - instance1 (thp/get-shape state :instance1) - shape1 (thp/get-shape state :shape1) + [instance1 shape1' _shape2'] + (thl/resolve-instance state (thp/id :instance1)) - 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 [[[group shape2] [c-group c-shape2] component] - (thl/resolve-instance-and-main - new-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 + ; Rect 2 ---> Rect 2 + ; Component 1 #--> Component 1 + ; Rect 1 ---> Rect 1 + ; Rect 2 ---> Rect 2 + ; + ; [Component 1] + ; page1 / Component 1 + ; + (let [[[main1 shape1 shape2] + [c-main1 c-shape1 c-shape2] component1] + (thl/resolve-instance-and-main + new-state + (thp/id :main1)) - (t/is (= (:name group) "Component 1")) - (t/is (= (:touched group) nil)) - (t/is (not= (:shape-ref group) nil)) - (t/is (= (:name shape2) "Rect 2")) - (t/is (= (:touched shape2) nil)) - (t/is (not= (:shape-ref shape2) nil)) + [[instance1 shape3 shape4] + [c-instance1 c-shape3 c-shape4] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - (t/is (= (:name c-group) "Component 1")) - (t/is (= (:touched c-group) nil)) - (t/is (= (:shape-ref c-group) nil)) - (t/is (= (:name c-shape2) "Rect 2")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:shape-ref c-shape2) nil)))))] + [[instance2 shape5 shape6] + [c-instance2 c-shape5 c-shape6] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - (ptk/emit! - store - (dwsh/delete-shapes #{(:id shape1)}) - (dwl/update-component-sync (:id instance1) (:id file)) - :the/end))))) + (t/is (= (:name main1) "Component 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:hidden shape1) true)) ; Instance shapes are not deleted but hidden + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) + (t/is (= (:name shape2) "Rect 2")) + (t/is (= (:hidden shape2) nil)) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) nil)) + + (t/is (= (:name instance1) "Component 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape3) "Rect 1")) + (t/is (= (:hidden shape3) true)) + (t/is (= (:touched shape3) nil)) + (t/is (= (:shape-ref shape3) (:id c-shape1))) + (t/is (= (:name shape4) "Rect 2")) + (t/is (= (:hidden shape4) nil)) + (t/is (= (:touched shape4) nil)) + (t/is (= (:shape-ref shape4) (:id c-shape2))) + + (t/is (= (:name instance2) "Component 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape5) "Rect 1")) + (t/is (= (:hidden shape5) true)) + (t/is (= (:touched shape5) nil)) + (t/is (= (:shape-ref shape5) (:id c-shape1))) + (t/is (= (:name shape6) "Rect 2")) + (t/is (= (:hidden shape6) nil)) + (t/is (= (:touched shape6) nil)) + (t/is (= (:shape-ref shape6) (:id c-shape2))) + + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-shape2 shape2)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape3 c-shape1)) + (t/is (= c-shape4 c-shape2)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape5 c-shape1)) + (t/is (= c-shape6 c-shape2)))))] + + (ptk/emit! + store + (dwsh/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)])) + (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)) + (thp/instantiate-component :instance2 + (thp/id :component1))) - file (wsh/get-local-file state) + file (wsh/get-local-file state) - shape1 (thp/get-shape state :shape1) - instance1 (thp/get-shape state :instance1) + [instance1 shape1' _shape2' _shape3'] + (thl/resolve-instance state (thp/id :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 [[[group shape1 shape2 shape3] [c-group c-shape1 c-shape2 c-shape3] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance1))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Component 1 + ; Rect 2 + ; Rect 1 + ; Rect 3 + ; Component 1 #--> Component 1 + ; Rect 2 ---> Rect 2 + ; Rect 1 ---> Rect 1 + ; Rect 3 ---> Rect 3 + ; Component 1 #--> Component 1 + ; Rect 2 ---> Rect 2 + ; Rect 1 ---> Rect 1 + ; Rect 3 ---> Rect 3 + ; + ; [Component 1] + ; page1 / Component 1 + ; + (let [[[main1 shape1 shape2 shape3] + [c-main1 c-shape1 c-shape2 c-shape3] component1] + (thl/resolve-instance-and-main + new-state + (thp/id :main1)) - (t/is (= (:name group) "Component 1")) - (t/is (= (:touched group) nil)) - (t/is (not= (:shape-ref group) nil)) - (t/is (= (:touched shape1) nil)) - (t/is (not= (:shape-ref shape1) nil)) - (t/is (= (:name shape1) "Rect 2")) - (t/is (= (:touched shape2) nil)) - (t/is (not= (:shape-ref shape2) nil)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape3) nil)) - (t/is (not= (:shape-ref shape3) nil)) - (t/is (= (:name shape3) "Rect 3")) + [[instance1 shape4 shape5 shape6] + [c-instance1 c-shape4 c-shape5 c-shape6] component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) - (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 2")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:shape-ref c-shape1) nil)) - (t/is (= (:name c-shape2) "Rect 1")) - (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)))))] + [[instance2 shape7 shape8 shape9] + [c-instance2 c-shape7 c-shape8 c-shape9] component3] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - (ptk/emit! - store - (dw/relocate-shapes #{(:id shape1)} (:id instance1) 2) - (dwl/update-component-sync (:id instance1) (:id file)) - :the/end))))) + (t/is (= (:name main1) "Component 1")) + (t/is (= (:touched main1) nil)) + (t/is (= (:shape-ref main1) nil)) + (t/is (= (:name shape1) "Rect 2")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:shape-ref shape1) nil)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:shape-ref shape2) nil)) + (t/is (= (:name shape3) "Rect 3")) + (t/is (= (:touched shape3) nil)) + (t/is (= (:shape-ref shape3) nil)) + + (t/is (= (:name instance1) "Component 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:shape-ref instance1) (:id c-main1))) + (t/is (= (:name shape4) "Rect 2")) + (t/is (= (:touched shape4) nil)) + (t/is (= (:shape-ref shape4) (:id c-shape1))) + (t/is (= (:name shape5) "Rect 1")) + (t/is (= (:touched shape5) nil)) + (t/is (= (:shape-ref shape5) (:id c-shape2))) + (t/is (= (:name shape6) "Rect 3")) + (t/is (= (:touched shape6) nil)) + (t/is (= (:shape-ref shape6) (:id c-shape3))) + + (t/is (= (:name instance2) "Component 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:shape-ref instance2) (:id c-main1))) + (t/is (= (:name shape7) "Rect 2")) + (t/is (= (:touched shape7) nil)) + (t/is (= (:shape-ref shape7) (:id c-shape1))) + (t/is (= (:name shape8) "Rect 1")) + (t/is (= (:touched shape8) nil)) + (t/is (= (:shape-ref shape8) (:id c-shape2))) + (t/is (= (:name shape9) "Rect 3")) + (t/is (= (:touched shape9) nil)) + (t/is (= (:shape-ref shape9) (:id c-shape3))) + + (t/is (= component1 component2 component3)) + (t/is (= c-main1 main1)) + (t/is (= c-shape1 shape1)) + (t/is (= c-shape2 shape2)) + (t/is (= c-shape3 shape3)) + (t/is (= c-instance1 c-main1)) + (t/is (= c-shape4 c-shape4)) + (t/is (= c-shape5 c-shape5)) + (t/is (= c-shape6 c-shape6)) + (t/is (= c-instance2 c-main1)) + (t/is (= c-shape7 c-shape7)) + (t/is (= c-shape8 c-shape8)) + (t/is (= c-shape9 c-shape9)))))] + + (ptk/emit! + store + (dw/relocate-shapes #{(:id shape1')} (:id instance1) 2) + (dwl/update-component-sync (:id instance1) (:id file)) + :the/end)))) (t/deftest test-update-from-lib (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/move-to-library :lib1 "Library 1") - (thp/sample-page) - (thp/instantiate-component :instance2 - (thp/id :component-1) - (thp/id :lib1))) + (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/move-to-library :lib1 "Library 1") + (thp/sample-page) + (thp/instantiate-component :instance1 + (thp/id :component1) + (thp/id :lib1)) + (thp/instantiate-component :instance2 + (thp/id :component1) + (thp/id :lib1))) - [instance2 shape2] - (thl/resolve-instance state (thp/id :instance2)) + [instance1 shape1'] + (thl/resolve-instance state (thp/id :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 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; + (let [[[instance1 shape1] [c-instance1 c-shape1] _component1] + (thl/resolve-instance-and-main + new-state + (thp/id :instance1)) + + [[instance2 shape2] [_c-instance2 _c-shape2] _component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2))] - store (the/prepare-store state done - (fn [new-state] - ; Expected shape tree: - ; - ; [Page] - ; Root Frame - ; Rect 1 #--> Rect 1 (color, opacity) - ; Rect 1 ---> Rect 1 - ; - (let [[[group shape1] [c-group c-shape1] component] - (thl/resolve-instance-and-main - new-state - (:id instance2))] + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Rect 1")) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:touched shape1) nil)) - (t/is (= (:name group) "Rect 1")) - (t/is (= (:touched group) nil)) - (t/is (= (:name shape1) "Rect 1")) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:touched shape1) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Rect 1")) + (t/is (= (:fill-color c-shape1) clr/test)) + (t/is (= (:fill-opacity c-shape1) 0.5)) + (t/is (= (:touched c-shape1) nil)) - (t/is (= (:name c-group) "Rect 1")) - (t/is (= (:touched c-group) nil)) - (t/is (= (:name c-shape1) "Rect 1")) - (t/is (= (:fill-color c-shape1) clr/test)) - (t/is (= (:fill-opacity c-shape1) 0.5)) - (t/is (= (:touched c-shape1) nil)))))] + (t/is (= (:name instance2) "Rect 1")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) + (t/is (= (:touched shape2) nil)))))] - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance2)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component-sync (:id instance1) (thp/id :lib1)) + :the/end)))) (t/deftest test-update-nested-upper (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :main2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2)) + (thp/instantiate-component :instance3 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + file (wsh/get-local-file state) - update-fn (fn [shape] - (merge shape {:fill-color clr/test - :fill-opacity 0.5})) + [instance2 _instance1 shape1' _shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 - ; Circle 1 ---> Circle 1 (color, opacity) - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 (color, opacity) - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Rect 1 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component1] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2)) + + [[instance4 instance3 shape3 shape4] + [_c-instance4 _c-instance3 _c-shape3 _c-shape4] _component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance3))] - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/test)) + (t/is (= (:fill-opacity shape1) 0.5)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/white)) + (t/is (= (:fill-opacity shape2) 1)) - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/test)) - (t/is (= (:fill-opacity shape1) 0.5)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/white)) - (t/is (= (:fill-opacity shape2) 1)) + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/test)) + (t/is (= (:fill-opacity c-shape1) 0.5)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/white)) + (t/is (= (:fill-opacity c-shape2) 1)) - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/test)) - (t/is (= (:fill-opacity c-shape1) 0.5)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] + (t/is (= (:name instance4) "Group")) + (t/is (= (:touched instance4) nil)) + (t/is (= (:name instance3) "Rect 1")) + (t/is (= (:touched instance3) nil)) + (t/is (= (:name shape3) "Circle 1")) + (t/is (= (:touched shape3) nil)) + (t/is (= (:fill-color shape3) clr/test)) + (t/is (= (:fill-opacity shape3) 0.5)) + (t/is (= (:name shape4) "Rect 1")) + (t/is (= (:touched shape4) nil)) + (t/is (= (:fill-color shape4) clr/white)) + (t/is (= (:fill-opacity shape4) 1)))))] - (ptk/emit! - store - (dch/update-shapes [(:id shape1)] update-fn) - (dwl/update-component (:id instance2)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape1')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component-sync (:id instance2) (:id file)) + :the/end)))) (t/deftest test-update-nested-lower-near (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :main2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2)) + (thp/instantiate-component :instance3 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + file (wsh/get-local-file state) - update-fn (fn [shape] - (merge shape {:fill-color clr/test - :fill-opacity 0.5})) + [instance2 instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 (color, opacity) - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 (color, opacity) - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Rect 1 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component1] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2)) + + [[instance4 instance3 shape3 shape4] + [_c-instance4 _c-instance3 _c-shape3 _c-shape4] _component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance3))] - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:fill-opacity shape2) 0.5)) + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/test)) + (t/is (= (:fill-opacity c-shape2) 0.5)) - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/test)) - (t/is (= (:fill-opacity c-shape2) 0.5)))))] + (t/is (= (:name instance4) "Group")) + (t/is (= (:touched instance4) nil)) + (t/is (= (:name instance3) "Rect 1")) + (t/is (= (:touched instance3) nil)) + (t/is (= (:name shape3) "Circle 1")) + (t/is (= (:touched shape3) nil)) + (t/is (= (:fill-color shape3) clr/black)) + (t/is (= (:fill-opacity shape3) 0)) + (t/is (= (:name shape4) "Rect 1")) + (t/is (= (:touched shape4) nil)) + (t/is (= (:fill-color shape4) clr/test)) + (t/is (= (:fill-opacity shape4) 0.5)))))] - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance1)) - (dwl/update-component (:id instance2)) - :the/end))))) + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component (:id instance1)) + (dwl/update-component-sync (:id instance2) (:id file)) + :the/end)))) (t/deftest test-update-nested-lower-remote (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" - :fill-color clr/black - :fill-opacity 0}) - (thp/group-shapes :group1 - [(thp/id :instance1) - (thp/id :shape2)]) - (thp/make-component :instance2 :component-2 - [(thp/id :group1)])) + (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" + :fill-color clr/black + :fill-opacity 0}) + (thp/group-shapes :group1 + [(thp/id :instance1) + (thp/id :shape2)]) + (thp/make-component :main2 :component2 + [(thp/id :group1)]) + (thp/instantiate-component :instance2 + (thp/id :component2)) + (thp/instantiate-component :instance3 + (thp/id :component2))) - [instance2 instance1 shape1 shape2] - (thl/resolve-instance state (thp/id :instance2)) + file (wsh/get-local-file state) - update-fn (fn [shape] - (merge shape {:fill-color clr/test - :fill-opacity 0.5})) + [_instance2 instance1 _shape1' shape2'] + (thl/resolve-instance state (thp/id :instance2)) - 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 (color, opacity) - ; Circle 1 ---> Circle 1 - ; - ; [Rect 1] - ; Rect 1 - ; Rect 1 (color, opacity) - ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 1 ---> Rect 1 - ; Circle 1 - ; - (let [[[instance2 instance1 shape1 shape2] - [c-instance2 c-instance1 c-shape1 c-shape2] component] - (thl/resolve-instance-and-main - new-state - (thp/id :instance2))] + store (the/prepare-store state done + (fn [new-state] + ; Expected shape tree: + ; + ; [Page] + ; Root Frame + ; Rect 1 + ; Rect 1 + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; (remote-synced) + ; Rect 1 ---> Rect 1 + ; (remote-synced) + ; Circle 1 ---> Circle 1 + ; Group #--> Group + ; Rect 1 @--> Rect 1 + ; Rect 1 ---> Rect 1 + ; Circle 1 ---> Circle 1 + ; + ; [Rect 1] + ; page1 / Rect 1 + ; + ; [Group] + ; page1 / Group + ; + (let [[[instance2 instance1 shape1 shape2] + [c-instance2 c-instance1 c-shape1 c-shape2] _component1] + (thl/resolve-instance-and-main + new-state + (thp/id :instance2)) + + [[instance4 instance3 shape3 shape4] + [_c-instance4 _c-instance3 _c-shape3 _c-shape4] _component2] + (thl/resolve-instance-and-main + new-state + (thp/id :instance3))] - ; TODO: get and check the instance inside component [Group 1] + (t/is (= (:name instance2) "Group")) + (t/is (= (:touched instance2) nil)) + (t/is (= (:name instance1) "Rect 1")) + (t/is (= (:touched instance1) nil)) + (t/is (= (:name shape1) "Circle 1")) + (t/is (= (:touched shape1) nil)) + (t/is (= (:fill-color shape1) clr/black)) + (t/is (= (:fill-opacity shape1) 0)) + (t/is (= (:name shape2) "Rect 1")) + (t/is (= (:touched shape2) nil)) + (t/is (= (:fill-color shape2) clr/test)) + (t/is (= (:fill-opacity shape2) 0.5)) - (t/is (= (:name instance2) "Group")) - (t/is (= (:touched instance2) nil)) - (t/is (= (:name instance1) "Rect 1")) - (t/is (= (:touched instance1) nil)) - (t/is (= (:name shape1) "Circle 1")) - (t/is (= (:touched shape1) nil)) - (t/is (= (:fill-color shape1) clr/black)) - (t/is (= (:fill-opacity shape1) 0)) - (t/is (= (:name shape2) "Rect 1")) - (t/is (= (:touched shape2) nil)) - (t/is (= (:fill-color shape2) clr/test)) - (t/is (= (:fill-opacity shape2) 0.5)) + (t/is (= (:name c-instance2) "Group")) + (t/is (= (:touched c-instance2) nil)) + (t/is (= (:name c-instance1) "Rect 1")) + (t/is (= (:touched c-instance1) nil)) + (t/is (= (:name c-shape1) "Circle 1")) + (t/is (= (:touched c-shape1) nil)) + (t/is (= (:fill-color c-shape1) clr/black)) + (t/is (= (:fill-opacity c-shape1) 0)) + (t/is (= (:name c-shape2) "Rect 1")) + (t/is (= (:touched c-shape2) nil)) + (t/is (= (:fill-color c-shape2) clr/test)) + (t/is (= (:fill-opacity c-shape2) 0.5)) - (t/is (= (:name c-instance2) "Group")) - (t/is (= (:touched c-instance2) nil)) - (t/is (= (:name c-instance1) "Rect 1")) - (t/is (= (:touched c-instance1) nil)) - (t/is (= (:name c-shape1) "Circle 1")) - (t/is (= (:touched c-shape1) nil)) - (t/is (= (:fill-color c-shape1) clr/black)) - (t/is (= (:fill-opacity c-shape1) 0)) - (t/is (= (:name c-shape2) "Rect 1")) - (t/is (= (:touched c-shape2) nil)) - (t/is (= (:fill-color c-shape2) clr/white)) - (t/is (= (:fill-opacity c-shape2) 1)))))] - - (ptk/emit! - store - (dch/update-shapes [(:id shape2)] update-fn) - (dwl/update-component (:id instance1)) - :the/end))))) + (t/is (= (:name instance4) "Group")) + (t/is (= (:touched instance4) nil)) + (t/is (= (:name instance3) "Rect 1")) + (t/is (= (:touched instance3) nil)) + (t/is (= (:name shape3) "Circle 1")) + (t/is (= (:touched shape3) nil)) + (t/is (= (:fill-color shape3) clr/black)) + (t/is (= (:fill-opacity shape3) 0)) + (t/is (= (:name shape4) "Rect 1")) + (t/is (= (:touched shape4) nil)) + (t/is (= (:fill-color shape4) clr/test)) + (t/is (= (:fill-opacity shape4) 0.5)))))] + (ptk/emit! + store + (dch/update-shapes [(:id shape2')] + (fn [shape] + (merge shape {:fill-color clr/test + :fill-opacity 0.5}))) + (dwl/update-component-sync (:id instance1) (:id file)) + :the/end)))) diff --git a/frontend/test/frontend_tests/state_components_test.cljs b/frontend/test/frontend_tests/state_components_test.cljs index e0bfdfe840..333b3823f5 100644 --- a/frontend/test/frontend_tests/state_components_test.cljs +++ b/frontend/test/frontend_tests/state_components_test.cljs @@ -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 @--> Rect 1 - ; Rect 1 ---> Rect 1 + ; [Page] + ; Root Frame + ; Group + ; Rect 1 #--> Rect 1 + ; Rect 1 ---> Rect 1 + ; + ; [Group] + ; page1 / Group ; - ; [Group] - ; Group - ; Rect 1 @--> Rect 1 - ; Rect 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)))) -