Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hirunatan committed Apr 30, 2024
1 parent a2cde10 commit 88d2772
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 85 deletions.
112 changes: 92 additions & 20 deletions common/test/common_tests/logic/components_touched_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@

(t/deftest test-touched-when-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 (thf/sample-fills-color
:fill-color "#abcdef")}))
page (thf/current-page file)
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
:main-root
:main-child
:copy-root
:main-child-params {:fills (thf/sample-fills-color
:fill-color "#abcdef")}))
page (thf/current-page file)
copy-root (thf/get-shape file :copy-root)

;; Action
changes (cflh/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root)
#(assoc % :fills (thf/sample-fills-color
:fill-color "#fabada"))
(:objects page)
{})
update-fn (fn [shape]
(assoc shape :fills (thf/sample-fills-color :fill-color "#fabada")))

changes (cflh/generate-update-shapes (pcb/empty-changes nil (:id page))
(:shapes copy-root)
update-fn
(:objects page)
{})

file' (thf/apply-changes file changes)
file' (thf/apply-changes file changes)

;; Get
copy-root' (thf/get-shape file' :copy-root)
copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))
fills' (:fills copy-child')
fill' (first fills')]
fills' (:fills copy-child')
fill' (first fills')]

;; Check
(t/is (= (count fills') 1))
Expand Down Expand Up @@ -78,10 +80,80 @@
#{}
#{})

file' (thf/apply-changes file changes)
file' (thf/apply-changes file changes)

;; Get
copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/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-touched-when-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 (thf/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]
(cflh/generate-delete-shapes (pcb/empty-changes)
file
page
(:objects page)
(set (:shapes copy-root))
{:components-v2 true})

file' (thf/apply-changes file changes)

;; Get
copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))]

;; Check
(t/is (= (:touched copy-root') nil))
(t/is (= (:touched copy-child') #{:visibility-group}))))

(t/deftest test-not-touched-when-moving-shape
(let [;; Setup
file (-> (thf/sample-file :file1)
(tho/add-simple-component-with-copy :component1
:main-root
:main-child
:copy-root)
(thf/add-sample-shape :free-shape))

page (thf/current-page file)

;; 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 (cflh/generate-relocate-shapes (pcb/empty-changes)
(:objects page)
#{(thi/id :copy-root)}
(thi/id :copy-root)
(:id page)
0
#{(thi/id :free-shape)}
#{}
#{}
#{}
#{}
#{}
#{})

file' (thf/apply-changes file changes)

;; Get
copy-root' (thf/get-shape file' :copy-root)
copy-root' (thf/get-shape file' :copy-root)
copy-child' (thf/get-shape-by-id file' (first (:shapes copy-root')))]

;; Check
Expand Down
65 changes: 0 additions & 65 deletions frontend/test/frontend_tests/state_components_sync_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,6 @@

;; === Test touched ======================

(t/deftest test-touched-children-delete
(t/async done
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"})
(thp/sample-shape :shape2 :rect
{:name "Rect 2"})
(thp/make-component :main1 :component1
[(thp/id :shape1)
(thp/id :shape2)])
(thp/instantiate-component :instance1
(thp/id :component1)))

[_group1 shape1']
(thl/resolve-instance state (thp/id :instance1))

store (the/prepare-store state done
(fn [new-state]
;; Expected shape tree:
;;;
;; [Page]
;; Root Frame
;; Component 1
;; Rect 1
;; Rect 2
;; Component 1 #--> Component 1
;; Rect 1* ---> Rect 1
;; #{:visibility-group}
;; Rect 2 ---> Rect 2
;;;
;; [Component 1]
;; page1 / Component 1
;;
(let [[[group shape1 shape2] [c-group c-shape1 c-shape2] _component]
(thl/resolve-instance-and-main-allow-dangling
new-state
(thp/id :instance1))]

(t/is (= (:name group) "Component 1"))
(t/is (= (:touched group) nil))
(t/is (not= (:shape-ref group) nil))
(t/is (= (:name shape1) "Rect 1"))
(t/is (= (:hidden shape1) true)) ; Instance shapes are not deleted but hidden
(t/is (= (:touched shape1) #{:visibility-group}))
(t/is (not= (:shape-ref shape1) nil))
(t/is (= (:name shape2) "Rect 2"))
(t/is (= (:touched shape2) nil))
(t/is (not= (:shape-ref shape2) nil))

(t/is (= (:name c-group) "Component 1"))
(t/is (= (:touched c-group) nil))
(t/is (= (:shape-ref c-group) nil))
(t/is (= (:name c-shape1) "Rect 1"))
(t/is (= (:touched c-shape1) nil))
(t/is (= (:shape-ref c-shape1) nil))
(t/is (= (:name c-shape2) "Rect 2"))
(t/is (= (:touched c-shape2) nil))
(t/is (= (:shape-ref c-shape2) nil)))))]

(ptk/emit!
store
(dwsh/delete-shapes #{(:id shape1')})
:the/end))))

(t/deftest test-touched-children-move
(t/async done
(let [state (-> thp/initial-state
Expand Down

0 comments on commit 88d2772

Please sign in to comment.