mirror of
https://github.com/penpot/penpot.git
synced 2025-04-01 01:21:21 -05:00
♻️ Refactor front end test to make use of common file helpers
This commit is contained in:
parent
c16ef39abf
commit
da939cc0a6
3 changed files with 106 additions and 1 deletions
49
frontend/test/frontend_tests/basic_shapes_test.cljs
Normal file
49
frontend/test/frontend_tests/basic_shapes_test.cljs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
(ns frontend-tests.basic-shapes-test
|
||||||
|
(:require
|
||||||
|
[app.common.test-helpers.files :as cthf]
|
||||||
|
[app.common.test-helpers.ids-map :as cthi]
|
||||||
|
[app.common.test-helpers.shapes :as cths]
|
||||||
|
[app.main.data.workspace.changes :as dch]
|
||||||
|
[cljs.test :as t :include-macros true]
|
||||||
|
[frontend-tests.helpers.state :as ths]))
|
||||||
|
|
||||||
|
(t/deftest test-update-shape
|
||||||
|
(t/async
|
||||||
|
done
|
||||||
|
(let [;; ==== Setup
|
||||||
|
store
|
||||||
|
(ths/setup-store
|
||||||
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
||||||
|
(cths/add-sample-shape :shape1)))
|
||||||
|
|
||||||
|
;; ==== Action
|
||||||
|
events
|
||||||
|
[(dch/update-shapes [(cthi/id :shape1)]
|
||||||
|
#(assoc % :fills
|
||||||
|
(cths/sample-fills-color :fill-color
|
||||||
|
"#fabada")))]]
|
||||||
|
|
||||||
|
(ths/run-store
|
||||||
|
store done events
|
||||||
|
(fn [new-state]
|
||||||
|
(let [;; ==== Get
|
||||||
|
shape1' (get-in new-state [:workspace-data
|
||||||
|
:pages-index
|
||||||
|
(cthi/id :page1)
|
||||||
|
:objects
|
||||||
|
(cthi/id :shape1)])
|
||||||
|
fills' (:fills shape1')
|
||||||
|
fill' (first fills')]
|
||||||
|
|
||||||
|
(cthf/dump-shape shape1')
|
||||||
|
|
||||||
|
;; ==== Check
|
||||||
|
(t/is (some? shape1'))
|
||||||
|
(t/is (= (count fills') 1))
|
||||||
|
(t/is (= (:fill-color fill') "#fabada"))
|
||||||
|
(t/is (= (:fill-opacity fill') 1))))))))
|
|
@ -97,7 +97,7 @@
|
||||||
(if (empty? shapes)
|
(if (empty? shapes)
|
||||||
state
|
state
|
||||||
(let [[group changes]
|
(let [[group changes]
|
||||||
(dwg/prepare-create-group nil (:objects page) (:id page) shapes prefix true)]
|
(dwg/prepare-create-group (pcb/empty-changes) nil (:objects page) (:id page) shapes prefix true)]
|
||||||
|
|
||||||
(swap! idmap assoc label (:id group))
|
(swap! idmap assoc label (:id group))
|
||||||
(update state :workspace-data
|
(update state :workspace-data
|
||||||
|
|
56
frontend/test/frontend_tests/helpers/state.cljs
Normal file
56
frontend/test/frontend_tests/helpers/state.cljs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) KALEIDOS INC
|
||||||
|
|
||||||
|
(ns frontend-tests.helpers.state
|
||||||
|
(:require
|
||||||
|
[app.common.pprint :refer [pprint]]
|
||||||
|
[app.common.schema :as sm]
|
||||||
|
[app.common.test-helpers.files :as cthf]
|
||||||
|
[app.main.data.workspace.layout :as layout]
|
||||||
|
[beicon.v2.core :as rx]
|
||||||
|
[potok.v2.core :as ptk]))
|
||||||
|
|
||||||
|
(def ^private initial-state
|
||||||
|
{:workspace-layout layout/default-layout
|
||||||
|
:workspace-global layout/default-global
|
||||||
|
:current-file-id nil
|
||||||
|
:current-page-id nil
|
||||||
|
:workspace-data nil
|
||||||
|
:workspace-libraries {}
|
||||||
|
:features/team #{"components/v2"}})
|
||||||
|
|
||||||
|
(defn- on-error
|
||||||
|
[cause]
|
||||||
|
(js/console.log "STORE ERROR" (.-stack cause))
|
||||||
|
(when-let [data (some-> cause ex-data ::sm/explain)]
|
||||||
|
(pprint (sm/humanize-explain data))))
|
||||||
|
|
||||||
|
(defn setup-store
|
||||||
|
[file]
|
||||||
|
(let [state (-> initial-state
|
||||||
|
(assoc :current-file-id (:id file)
|
||||||
|
:current-page-id (cthf/current-page-id file)
|
||||||
|
:workspace-file (dissoc file :data)
|
||||||
|
:workspace-data (:data file)))
|
||||||
|
store (ptk/store {:state state :on-error on-error})]
|
||||||
|
store))
|
||||||
|
|
||||||
|
(defn run-store
|
||||||
|
[store done events completed-cb]
|
||||||
|
(let [stream (ptk/input-stream store)]
|
||||||
|
(->> stream
|
||||||
|
(rx/take-until (rx/filter #(= :the/end %) stream))
|
||||||
|
(rx/last)
|
||||||
|
(rx/tap (fn []
|
||||||
|
(completed-cb @store)))
|
||||||
|
(rx/subs! (fn [_] (done))
|
||||||
|
(fn [cause]
|
||||||
|
(js/console.log "[error]:" cause))
|
||||||
|
(fn [_]
|
||||||
|
(js/console.log "[complete]"))))
|
||||||
|
(doall (for [event events]
|
||||||
|
(ptk/emit! store event)))
|
||||||
|
(ptk/emit! store :the/end)))
|
Loading…
Add table
Reference in a new issue