0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -05:00

Add tests for reset components

This commit is contained in:
Andrés Moya 2024-05-07 17:01:01 +02:00
parent dd62653d4b
commit caefaf6016
3 changed files with 387 additions and 599 deletions

View file

@ -0,0 +1,343 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns common-tests.logic.comp-reset-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.logic.libraries :as cll]
[app.common.logic.shapes :as cls]
[clojure.test :as t]
[common-tests.helpers.components :as thc]
[common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi]
[common-tests.helpers.shapes :as ths]))
(t/use-fixtures :each thi/test-fixture)
(t/deftest test-reset-after-changing-attribute
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
:main-root
:main-child
:copy-root
:main-child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
;; ==== Action
update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root)
update-fn
(:objects page)
{})
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child')
fill' (first fills')]
;; ==== Check
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-reset-from-library
(let [;; ==== Setup
library (-> (thf/sample-file :library :is-shared true)
(tho/add-simple-component :component1 :main-root :main-child
:child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
file (-> (thf/sample-file :file)
(thc/instantiate-component :component1 :copy-root :library library))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
;; ==== Action
update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root)
update-fn
(:objects page)
{})
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf
(:id library) library}
page-mdf
(:id copy-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child')
fill' (first fills')]
;; ==== Check
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-reset-after-adding-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
:main-root
:main-child
:copy-root)
(ths/add-sample-shape :free-shape))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-root)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
0 ; to-index
#{(thi/id :free-shape)}) ; ids
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-reset-after-deleting-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
:main-root
:main-child
:copy-root))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action will not
;; delete the child shape, but hide it (thus setting the visibility group).
[_all-parents changes]
(cls/generate-delete-shapes (pcb/empty-changes)
file
page
(:objects page)
(set (:shapes copy-root))
{:components-v2 true})
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-reset-after-moving-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-component-with-many-children-and-copy :component1
:main-root
[:main-child1 :main-child2 :main-child3]
:copy-root)
(ths/add-sample-shape :free-shape))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
copy-child1 (ths/get-shape-by-id file (first (:shapes copy-root)))
;; ==== Action
;; IMPORTANT: as modifying copies structure is now forbidden, this action
;; will not have any effect, and so the parent shape won't also be touched.
changes (cls/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(:parent-id copy-child1)} ; parents
(thi/id :copy-root) ; parent-id
(:id page) ; page-id
2 ; to-index
#{(:id copy-child1)}) ; ids
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))]
;; ==== Check
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-reset-after-changing-upper
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-nested-component-with-copy :component1
:main1-root
:main1-child
:component2
:main2-root
:main2-nested-head
:copy2-root
:main2-root-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root)
;; ==== Action
update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
#{(:id copy2-root)}
update-fn
(:objects page)
{})
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy2-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy2-root' (ths/get-shape file' :copy2-root)
fills' (:fills copy2-root')
fill' (first fills')]
;; ==== Check
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#abcdef"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy2-root') nil))))
(t/deftest test-reset-after-changing-lower
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-nested-component-with-copy :component1
:main1-root
:main1-child
:component2
:main2-root
:main2-nested-head
:copy2-root))
page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root)
;; ==== Action
update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy2-root)
update-fn
(:objects page)
{})
file-mdf (thf/apply-changes file changes)
page-mdf (thf/current-page file-mdf)
changes (cll/generate-reset-component (pcb/empty-changes)
file-mdf
{(:id file-mdf) file-mdf}
page-mdf
(:id copy2-root)
true)
file' (thf/apply-changes file changes)
;; ==== Get
copy2-root' (ths/get-shape file' :copy2-root)
copy2-child' (ths/get-shape-by-id file' (first (:shapes copy2-root')))
fills' (:fills copy2-child')
fill' (first fills')]
;; ==== Check
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#FFFFFF"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy2-root') nil))
(t/is (= (:touched copy2-child') nil))))

View file

@ -9,6 +9,7 @@
[app.common.files.changes-builder :as pcb]
[app.common.logic.shapes :as cls]
[clojure.test :as t]
[common-tests.helpers.components :as thc]
[common-tests.helpers.compositions :as tho]
[common-tests.helpers.files :as thf]
[common-tests.helpers.ids-map :as thi]
@ -53,6 +54,44 @@
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') #{:fill-group}))))
(t/deftest test-touched-from-library
(let [;; ==== Setup
library (-> (thf/sample-file :library :is-shared true)
(tho/add-simple-component :component1 :main-root :main-child
:child-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
file (-> (thf/sample-file :file)
(thc/instantiate-component :component1 :copy-root :library library))
page (thf/current-page file)
copy-root (ths/get-shape file :copy-root)
;; ==== Action
update-fn (fn [shape]
(assoc shape :fills (ths/sample-fills-color :fill-color "#fabada")))
changes (cls/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root)
update-fn
(:objects page)
{})
file' (thf/apply-changes file changes)
;; ==== Get
copy-root' (ths/get-shape file' :copy-root)
copy-child' (ths/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child')
fill' (first fills')]
;; ==== Check
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') #{:fill-group}))))
(t/deftest test-not-touched-when-adding-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
@ -87,7 +126,7 @@
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') nil))))
(t/deftest test-touched-when-deleting-shape
(t/deftest test-not-touched-when-deleting-shape
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
@ -165,8 +204,8 @@
:main2-root
:main2-nested-head
:copy2-root
:root2-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
:main2-root-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root)
@ -202,9 +241,7 @@
:component2
:main2-root
:main2-nested-head
:copy2-root
:nested-head-params {:fills (ths/sample-fills-color
:fill-color "#abcdef")}))
:copy2-root))
page (thf/current-page file)
copy2-root (ths/get-shape file :copy2-root)
@ -231,4 +268,4 @@
(t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1))
(t/is (= (:touched copy2-root') nil))
(t/is (= (:touched copy2-child') #{:fill-group}))))
(t/is (= (:touched copy2-child') #{:fill-group}))))

View file

@ -21,598 +21,6 @@
(t/use-fixtures :each
{:before thp/reset-idmap!})
;; === Test reset changes ======================
(t/deftest test-reset-changes
(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)))
[instance1 shape1']
(thl/resolve-instance 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
(: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 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')]
(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
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"
:fill-color clr/white
:fill-opacity 1})
(thp/make-component :main1 :component1
[(thp/id :shape1)])
(thp/instantiate-component :instance1
(thp/id :component1))
(thp/sample-shape :shape2 :circle
{:name "Circle 1"}))
instance1 (thp/get-shape state :instance1)
shape2 (thp/get-shape state :shape2)
store (the/prepare-store state done
(fn [new-state]
;; Expected shape tree:
;;
;; [Page]
;; 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 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))))
(t/deftest test-reset-children-delete
(t/async done
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"})
(thp/sample-shape :shape2 :rect
{:name "Rect 2"})
(thp/make-component :main1 :component1
[(thp/id :shape1)
(thp/id :shape2)])
(thp/instantiate-component :instance1
(thp/id :component1)))
[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
;; 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 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))))
(t/deftest test-reset-children-move
(t/async done
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"})
(thp/sample-shape :shape2 :rect
{:name "Rect 2"})
(thp/sample-shape :shape3 :rect
{:name "Rect 3"})
(thp/make-component :main1 :component1
[(thp/id :shape1)
(thp/id :shape2)
(thp/id :shape3)])
(thp/instantiate-component :instance1
(thp/id :component1)))
[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
;; 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 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))))
(t/deftest test-reset-from-lib
(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 :instance1 :component1
[(thp/id :shape1)])
(thp/move-to-library :lib1 "Library 1")
(thp/sample-page)
(thp/instantiate-component :instance2
(thp/id :component1)
(thp/id :lib1)))
[instance2 shape2]
(thl/resolve-instance state (thp/id :instance2))
store (the/prepare-store state done
(fn [new-state]
;; Expected shape tree:
;;
;; [Page]
;; Root Frame
;; Rect 1 #--> <Library 1> Rect 1
;; Rect 1 ---> <Library 1> Rect 1
;;
(let [[[group shape1] [c-group c-shape1] _component]
(thl/resolve-instance-and-main
new-state
(:id instance2))]
(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)))))]
(ptk/emit!
store
(dch/update-shapes [(:id shape2)]
(fn [shape]
(merge shape {:fill-color clr/test
:fill-opacity 0.5})))
(dwl/reset-component (:id instance2))
:the/end))))
(t/deftest test-reset-nested-upper
(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/frame-shapes :frame1
[(thp/id :instance1)
(thp/id :shape2)])
(thp/make-component :main2 :component2
[(thp/id :frame1)])
(thp/instantiate-component :instance2
(thp/id :component2)))
[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
;; 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))]
(t/is (= (:name instance2) "Board"))
(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) "Board"))
(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')]
(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
;; (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/frame-shapes :frame1
;; [(thp/id :instance1)
;; (thp/id :shape2)])
;; (thp/make-component :instance2 :component2
;; [(thp/id :frame1)])
;; (thp/instantiate-component :instance2
;; (thp/id :component2)))
;;
;; [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
;; ;; 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))]
;;
;; (t/is (= (:name instance2) "Board"))
;; (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) "Board"))
;; (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')]
;; (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
(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/frame-shapes :frame1
[(thp/id :instance1)
(thp/id :shape2)])
(thp/make-component :instance2 :component2
[(thp/id :frame1)])
(thp/instantiate-component :instance2
(thp/id :component2)))
[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
;; 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))]
(t/is (= (:name instance2) "Board"))
(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) "Board"))
(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')]
(fn [shape]
(merge shape {:fill-color clr/test
:fill-opacity 0.5})))
(dwl/update-component (:id instance2))
(dwl/reset-component (:id instance1))
:the/end))))
;; === Test update component ======================
(t/deftest test-update-component