mirror of
https://github.com/penpot/penpot.git
synced 2025-06-01 21:21:37 +02:00
✔️ Allow for tests of data module at frontend
This commit is contained in:
parent
87cf91a044
commit
bde62473a4
5 changed files with 110 additions and 4 deletions
61
frontend/tests/app/test_library_sync.cljs
Normal file
61
frontend/tests/app/test_library_sync.cljs
Normal file
|
@ -0,0 +1,61 @@
|
|||
(ns app.test-library-sync
|
||||
(:require [cljs.test :as t :include-macros true]
|
||||
[cljs.pprint :refer [pprint]]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]
|
||||
[app.main.data.workspace.libraries :as dwl]))
|
||||
|
||||
;; ---- Helpers
|
||||
|
||||
(defn do-update
|
||||
[state event cb]
|
||||
(let [new-state (ptk/update event state)]
|
||||
(cb new-state)))
|
||||
|
||||
(defn do-watch
|
||||
[state event cb]
|
||||
(->> (ptk/watch event state nil)
|
||||
(rx/reduce conj [])
|
||||
(rx/subs cb)))
|
||||
|
||||
(defn do-watch-update
|
||||
[state event & cbs]
|
||||
(do-watch state event
|
||||
(fn [events]
|
||||
(t/is (= (count events) (count cbs)))
|
||||
(reduce
|
||||
(fn [new-state [event cb]]
|
||||
(do-update new-state event cb))
|
||||
state
|
||||
(map list events cbs)))))
|
||||
|
||||
;; ---- Tests
|
||||
|
||||
(t/deftest synctest
|
||||
(t/testing "synctest"
|
||||
(let [state {:workspace-local {:color-for-rename "something"}}]
|
||||
(do-update
|
||||
state
|
||||
dwl/clear-color-for-rename
|
||||
(fn [new-state]
|
||||
(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"}]
|
||||
(do-watch-update
|
||||
state
|
||||
(dwl/add-recent-color color)
|
||||
(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]))
|
||||
(done)))))))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue