💄 Add indentation fixes on frontend tests

This commit is contained in:
Andrey Antukh 2023-07-11 17:19:01 +02:00
parent dae5e71fa1
commit 42aee56c36
3 changed files with 2566 additions and 2558 deletions

View file

@ -19,21 +19,28 @@
;; ---- Helpers to manage global events ;; ---- Helpers to manage global events
(defn on-error
[cause]
(js/console.log "[CAUSE]:" (.-stack cause))
(js/console.log "[DATA]:" (pr-str (ex-data cause))))
(defn prepare-store (defn prepare-store
"Create a store with the given initial state. Wait until "Create a store with the given initial state. Wait until
a :the/end event occurs, and then call the function with a :the/end event occurs, and then call the function with
the final state at this point." the final state at this point."
[state done completed-cb] [state done completed-cb]
(let [store (ptk/store {:state state}) (let [store (ptk/store {:state state :on-error on-error})
stream (ptk/input-stream store) stream (ptk/input-stream store)
stream (->> stream stream (->> stream
(rx/take-until (rx/filter #(= :the/end %) stream)) (rx/take-until (rx/filter #(= :the/end %) stream))
(rx/last) (rx/last)
(rx/do (rx/do (fn []
(fn []
(completed-cb @store))) (completed-cb @store)))
(rx/subs done #(throw %)))] (rx/subs (fn [_] (done))
(fn [cause]
(js/console.log "[error]:" cause))
(fn [_]
(js/console.log "[complete]"))))]
store)) store))
;; Remove definitely when we ensure that the above method works ;; Remove definitely when we ensure that the above method works

File diff suppressed because it is too large Load diff

View file

@ -15,6 +15,9 @@
[linked.core :as lks] [linked.core :as lks]
[potok.core :as ptk])) [potok.core :as ptk]))
(.on js/process "uncaughtException" (fn [cause]
(js/console.log "EE" cause)))
(t/use-fixtures :each (t/use-fixtures :each
{:before thp/reset-idmap!}) {:before thp/reset-idmap!})
@ -35,17 +38,17 @@
;; (get new-state :workspace-libraries) ;; (get new-state :workspace-libraries)
;; false true) ;; false true)
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; 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
; ;;
(let [shape1 (thp/get-shape new-state :shape1) (let [shape1 (thp/get-shape new-state :shape1)
[[group shape1] [c-group c-shape1] component] [[group shape1] [c-group c-shape1] component]
@ -81,16 +84,16 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Component 1 ;; Component 1
; Rect 1 ;; Rect 1
; Rect-2 ;; Rect-2
; ;;
; [Component 1] ;; [Component 1]
; page1 / Component 1 ;; page1 / Component 1
; ;;
(let [shape1 (thp/get-shape new-state :shape1) (let [shape1 (thp/get-shape new-state :shape1)
[[group shape1 shape2] [[group shape1 shape2]
@ -134,17 +137,17 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Group ;; Group
; Rect 1 ;; Rect 1
; Rect-2 ;; Rect-2
; ;;
; [Group] ;; [Group]
; page1 / Group ;; page1 / Group
; ;;
(let [[[group shape1 shape2] (let [[[group shape1 shape2]
[c-group c-shape1 c-shape2] [c-group c-shape1 c-shape2]
component] component]
@ -182,20 +185,20 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [[[instance1 shape1] (let [[[instance1 shape1]
[c-instance1 c-shape1] [c-instance1 c-shape1]
component1] component1]
@ -245,16 +248,16 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; ;;
; [Renamed component] ;; [Renamed component]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [libs (wsh/get-libraries new-state) (let [libs (wsh/get-libraries new-state)
component (ctf/get-component libs component (ctf/get-component libs
(:component-file main1) (:component-file main1)
@ -282,21 +285,21 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; 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]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [new-component-id (->> (get-in new-state (let [new-component-id (->> (get-in new-state
[:workspace-data [:workspace-data
:components]) :components])
@ -325,27 +328,24 @@
:the/end)))) :the/end))))
(t/deftest test-delete-component (t/deftest test-delete-component
(t/async (t/async done
done
(let [state (-> thp/initial-state (let [state (-> thp/initial-state
(thp/sample-page) (thp/sample-page)
(thp/sample-shape :shape1 :rect (thp/sample-shape :shape1 :rect {:name "Rect 1"})
{:name "Rect 1"}) (thp/make-component :main1 :component1 [(thp/id :shape1)])
(thp/make-component :main1 :component1 (thp/instantiate-component :instance1 (thp/id :component1)))
[(thp/id :shape1)])
(thp/instantiate-component :instance1
(thp/id :component1)))
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Rect 1 #--> ? ;; Rect 1 #--> ?
; Rect 1 ---> ? ;; Rect 1 ---> ?
; ;;;
(let [[main1 shape1] (let [
[main1 shape1]
(thl/resolve-noninstance (thl/resolve-noninstance
new-state new-state
(thp/id :main1)) (thp/id :main1))
@ -383,10 +383,11 @@
(t/is (some? (:objects component3))) (t/is (some? (:objects component3)))
(t/is (= (:name saved-main1) "Rect 1")) (t/is (= (:name saved-main1) "Rect 1"))
(t/is (= (:name saved-shape2) "Rect 1")))))] (t/is (= (:name saved-shape2) "Rect 1"))
(ptk/emit! )))
store ]
(ptk/emit! store
(dwl/delete-component {:id (thp/id :component1)}) (dwl/delete-component {:id (thp/id :component1)})
:the/end)))) :the/end))))
@ -404,18 +405,18 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; 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]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [[[instance1 shape2] [c-instance1 c-shape2] component1] (let [[[instance1 shape2] [c-instance1 c-shape2] component1]
(thl/resolve-instance-and-main (thl/resolve-instance-and-main
new-state new-state
@ -457,18 +458,18 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; 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]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [new-instance-id (-> new-state (let [new-instance-id (-> new-state
wsh/lookup-selected wsh/lookup-selected
first) first)
@ -513,13 +514,13 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Rect 1 #--> <Library 1> Rect 1 ;; Rect 1 #--> <Library 1> Rect 1
; Rect 1 ---> <Library 1> Rect 1 ;; Rect 1 ---> <Library 1> Rect 1
; ;;
(let [new-instance-id (-> new-state (let [new-instance-id (-> new-state
wsh/lookup-selected wsh/lookup-selected
first) first)
@ -561,18 +562,18 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [[instance2 shape1] (let [[instance2 shape1]
(thl/resolve-noninstance (thl/resolve-noninstance
new-state new-state
@ -596,20 +597,20 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Group ;; Group
; Rect 1 ;; Rect 1
; Rect 1 ;; Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
; [Group] ;; [Group]
; page1 / Group ;; page1 / Group
; ;;
(let [page (thp/current-page new-state) (let [page (thp/current-page new-state)
shape1 (thp/get-shape new-state :shape1) shape1 (thp/get-shape new-state :shape1)
parent1 (ctn/get-shape page (:parent-id shape1)) parent1 (ctn/get-shape page (:parent-id shape1))
@ -656,23 +657,23 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; 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
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
; [Rect 1] ;; [Rect 1]
; page1 / Rect 1 ;; page1 / Rect 1
; ;;
(let [new-instance-id (-> new-state (let [new-instance-id (-> new-state
wsh/lookup-selected wsh/lookup-selected
first) first)
@ -684,7 +685,7 @@
new-state new-state
new-instance-id)] new-instance-id)]
; TODO: get and check the instance inside component [Rect-2] ;; TODO: get and check the instance inside component [Rect-2]
(t/is (not= (:id main1) (:id instance1))) (t/is (not= (:id main1) (:id instance1)))
(t/is (= (:id component) component-id)) (t/is (= (:id component) component-id))
@ -722,17 +723,17 @@
store (the/prepare-store state done store (the/prepare-store state done
(fn [new-state] (fn [new-state]
; Expected shape tree: ;; Expected shape tree:
; ;;
; [Page] ;; [Page]
; Root Frame ;; Root Frame
; Group ;; Group
; Rect 1 #--> <Library 1> Rect 1 ;; Rect 1 #--> <Library 1> Rect 1
; Rect 1 ---> <Library 1> Rect 1 ;; Rect 1 ---> <Library 1> Rect 1
; ;;
; [Group] ;; [Group]
; page1 / Group ;; page1 / Group
; ;;
(let [instance1 (thp/get-shape new-state :instance1) (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]