0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🎉 Add more tests for components

This commit is contained in:
Andrés Moya 2021-02-04 17:29:12 +01:00 committed by Andrey Antukh
parent cdab9ff69c
commit 884410c0d8
2 changed files with 106 additions and 2 deletions

View file

@ -52,6 +52,33 @@
(t/is (= (:component-file shape)
(:id file))))
(defn resolve-instance
[state root-inst-id]
(let [page (thp/current-page state)
root-inst (cph/get-shape page root-inst-id)
shapes-inst (cph/get-object-with-children
root-inst-id
(:objects page))]
;; Validate that the instance tree is well constructed
(t/is (is-instance-root (first shapes-inst)))
(run! is-instance-child (rest shapes-inst))
shapes-inst))
(defn resolve-noninstance
[state root-inst-id]
(let [page (thp/current-page state)
root-inst (cph/get-shape page root-inst-id)
shapes-inst (cph/get-object-with-children
root-inst-id
(:objects page))]
;; Validate that the tree is not an instance
(run! is-noninstance shapes-inst)
shapes-inst))
(defn resolve-instance-and-master
[state root-inst-id]
(let [page (thp/current-page state)

View file

@ -288,6 +288,48 @@
(println (.-stack e))
(done)))))
(t/deftest test-delete-component
(t/async done
(try
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"})
(thp/make-component :instance1
[(thp/id :shape1)]))
instance1 (thp/get-shape state :instance1)
component-id (:component-id instance1)]
(->> state
(the/do-watch-update (dwl/delete-component
{:id component-id}))
(rx/do
(fn [new-state]
(let [[instance1 shape1]
(thl/resolve-instance
new-state
(:id instance1))
file (dwlh/get-local-file new-state)
component (cph/get-component
(:component-id instance1)
(:component-file instance1)
file
{})]
(t/is (nil? component)))))
(rx/subs
done
#(do
(println (.-stack %))
(done)))))
(catch :default e
(println (.-stack e))
(done)))))
(t/deftest test-instantiate-component
(t/async done
(try
@ -322,9 +364,9 @@
(t/is (not= (:id instance1) (:id instance2)))
(t/is (= (:id component) component-id))
(t/is (= (:name instance2) "Component-7"))
(t/is (= (:name instance2) "Component-8"))
(t/is (= (:name shape2) "Rect 1"))
(t/is (= (:name c-instance2) "Component-6"))
(t/is (= (:name c-instance2) "Component-7"))
(t/is (= (:name c-shape2) "Rect 1")))))
(rx/subs
@ -337,3 +379,38 @@
(println (.-stack e))
(done)))))
(t/deftest test-detach-component
(t/async done
(try
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"})
(thp/make-component :instance1
[(thp/id :shape1)]))
instance1 (thp/get-shape state :instance1)
component-id (:component-id instance1)]
(->> state
(the/do-watch-update (dwl/detach-component
(:id instance1)))
(rx/do
(fn [new-state]
(let [[instance1 shape1]
(thl/resolve-noninstance
new-state
(:id instance1))]
(t/is (= (:name "Rect 1"))))))
(rx/subs
done
#(do
(println (.-stack %))
(done)))))
(catch :default e
(println (.-stack e))
(done)))))