0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-20 19:51:23 -05:00

🎉 Add more tests for components

This commit is contained in:
Andrés Moya 2021-02-05 09:32:37 +01:00 committed by Andrey Antukh
parent 884410c0d8
commit d6f3efb358
3 changed files with 185 additions and 45 deletions

View file

@ -1,4 +1,4 @@
(ns app.test-library-sync
(ns app.test-components-basic
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
[clojure.stacktrace :as stk]
@ -17,50 +17,6 @@
(t/use-fixtures :each
{:before thp/reset-idmap!})
(t/deftest test-create-page
(t/testing "create page"
(let [state (-> thp/initial-state
(thp/sample-page))
page (thp/current-page state)]
(t/is (= (:name page) "page1")))))
(t/deftest test-create-shape
(t/testing "create shape"
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"}))
shape (thp/get-shape state :shape1)]
(t/is (= (:name shape) "Rect 1")))))
(t/deftest synctest
(t/testing "synctest"
(let [state {:workspace-local {:color-for-rename "something"}}
new-state (->> state
(the/do-update
dwl/clear-color-for-rename))]
(t/is (= (get-in new-state [:workspace-local :color-for-rename])
nil)))))
(t/deftest asynctest
(t/testing "asynctest"
(t/async done
(let [state {}
color {:color "#ffffff"}]
(->> state
(the/do-watch-update
(dwl/add-recent-color color))
(rx/map
(fn [new-state]
(t/is (= (get-in new-state [:workspace-file
:data
:recent-colors])
[color]))
(t/is (= (get-in new-state [:workspace-data
:recent-colors])
[color]))))
(rx/subs done done))))))
(t/deftest test-add-component-from-single-shape
(t/async done
(try

View file

@ -0,0 +1,123 @@
(ns app.test-components-sync
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
[clojure.stacktrace :as stk]
[beicon.core :as rx]
[linked.core :as lks]
[app.test-helpers.events :as the]
[app.test-helpers.pages :as thp]
[app.test-helpers.libraries :as thl]
[app.common.geom.point :as gpt]
[app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.main.data.workspace.common :as dwc]
[app.main.data.workspace.libraries :as dwl]
[app.main.data.workspace.libraries-helpers :as dwlh]))
(t/use-fixtures :each
{:before thp/reset-idmap!})
(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 "#ffffff"
:fill-opacity 1})
(thp/make-component :instance1
[(thp/id :shape1)]))
shape1 (thp/get-shape state :shape1)
instance1 (thp/get-shape state :instance1)
update-shape (fn [shape]
(merge shape {:fill-color "#fabada"
:fill-opacity 0.5}))]
(->> state
(the/do-watch-update (dwc/update-shapes [(:id shape1)]
update-shape))
(rx/do
(fn [new-state]
(let [shape1 (thp/get-shape new-state :shape1)
[[group shape1] [c-group c-shape1] component]
(thl/resolve-instance-and-master
new-state
(:id instance1))
file (dwlh/get-local-file new-state)]
(t/is (= (:fill-color shape1) "#fabada"))
(t/is (= (:fill-opacity shape1) 0.5))
(t/is (= (:touched shape1) #{:fill-group}))
(t/is (= (:fill-color c-shape1) "#ffffff"))
(t/is (= (:fill-opacity c-shape1) 1))
(t/is (= (:touched c-shape1) nil)))))
(rx/subs
done
#(do
(println (.-stack %))
(done)))))
(catch :default e
(println (.-stack e))
(done)))))
(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 "#ffffff"
:fill-opacity 1})
(thp/make-component :instance1
[(thp/id :shape1)]))
shape1 (thp/get-shape state :shape1)
instance1 (thp/get-shape state :instance1)
update-shape (fn [shape]
(merge shape {:fill-color "#fabada"
:fill-opacity 0.5}))]
(->> state
(the/do-watch-update (dwc/update-shapes [(:id shape1)]
update-shape))
(rx/mapcat #(the/do-watch-update
(dwl/reset-component (:id instance1)) %))
(rx/do
(fn [new-state]
(let [shape1 (thp/get-shape new-state :shape1)
[[group shape1] [c-group c-shape1] component]
(thl/resolve-instance-and-master
new-state
(:id instance1))
file (dwlh/get-local-file new-state)]
(t/is (= (:fill-color shape1) "#ffffff"))
(t/is (= (:fill-opacity shape1) 1))
(t/is (= (:touched shape1) nil))
(t/is (= (:fill-color c-shape1) "#ffffff"))
(t/is (= (:fill-opacity c-shape1) 1))
(t/is (= (:touched c-shape1) nil)))))
(rx/subs
done
#(do
(println (.-stack %))
(done)))))
(catch :default e
(println (.-stack e))
(done)))))

View file

@ -0,0 +1,61 @@
(ns app.test-shapes
(:require [cljs.test :as t :include-macros true]
[cljs.pprint :refer [pprint]]
[clojure.stacktrace :as stk]
[beicon.core :as rx]
[linked.core :as lks]
[app.test-helpers.events :as the]
[app.test-helpers.pages :as thp]
[app.test-helpers.libraries :as thl]
[app.common.geom.point :as gpt]
[app.common.data :as d]
[app.common.pages.helpers :as cph]
[app.main.data.workspace.libraries :as dwl]))
(t/use-fixtures :each
{:before thp/reset-idmap!})
(t/deftest test-create-page
(t/testing "create page"
(let [state (-> thp/initial-state
(thp/sample-page))
page (thp/current-page state)]
(t/is (= (:name page) "page1")))))
(t/deftest test-create-shape
(t/testing "create shape"
(let [state (-> thp/initial-state
(thp/sample-page)
(thp/sample-shape :shape1 :rect
{:name "Rect 1"}))
shape (thp/get-shape state :shape1)]
(t/is (= (:name shape) "Rect 1")))))
(t/deftest synctest
(t/testing "synctest"
(let [state {:workspace-local {:color-for-rename "something"}}
new-state (->> state
(the/do-update
dwl/clear-color-for-rename))]
(t/is (= (get-in new-state [:workspace-local :color-for-rename])
nil)))))
(t/deftest asynctest
(t/testing "asynctest"
(t/async done
(let [state {}
color {:color "#ffffff"}]
(->> state
(the/do-watch-update
(dwl/add-recent-color color))
(rx/map
(fn [new-state]
(t/is (= (get-in new-state [:workspace-file
:data
:recent-colors])
[color]))
(t/is (= (get-in new-state [:workspace-data
:recent-colors])
[color]))))
(rx/subs done done))))))