0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 14:12:36 -05:00

Found error in handler logic, need rx streams

This commit is contained in:
Florian Schroedl 2024-07-02 16:06:41 +02:00
parent 3e5126251c
commit 50635ae879

View file

@ -2,7 +2,9 @@
(:require (:require
[app.common.test-helpers.compositions :as ctho] [app.common.test-helpers.compositions :as ctho]
[app.common.test-helpers.files :as cthf] [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]
[app.main.data.workspace.selection :as dws]
[app.main.ui.workspace.tokens.core :as wtc] [app.main.ui.workspace.tokens.core :as wtc]
[cljs.test :as t :include-macros true] [cljs.test :as t :include-macros true]
[frontend-tests.helpers.pages :as thp] [frontend-tests.helpers.pages :as thp]
@ -11,45 +13,55 @@
(t/use-fixtures :each (t/use-fixtures :each
{:before thp/reset-idmap!}) {:before thp/reset-idmap!})
(defn- setup-file (defn- setup-file
[] []
(-> (cthf/sample-file :file-1) (let [token-id (random-uuid)]
(ctho/add-rect :file-1 :rect-1 {}) (-> (cthf/sample-file :file-1 :page-label :page-1)
(ctho/add-rect :file-1 :rect-2 {}) (ctho/add-rect :rect-1 {})
(ctho/add-rect :file-1 :rect-3 {}))) (ctho/add-rect :rect-2 {})
(ctho/add-rect :rect-3 {})
(assoc-in [:data :tokens] {token-id {:id token-id
:value "12"
:name "sm"
:type :border-radius}}))))
(t/deftest test-update-shape (t/deftest test-update-shape
(t/async (t/async
done done
(let [;; ==== Setup (let [;; ==== Setup
file (setup-file) file (setup-file)
store (ths/setup-store file) store (ths/setup-store file)
rect-1 (cths/get-shape file :rect-1)
;; ==== Action ;; ==== Action
events [(wtc/on-add-token {:token-type-props {:attributes {:rx :ry} events [(dws/select-shape (:id rect-1))
:on-update-shape #(fn [& _])} (dch/update-shapes [(:id rect-1)] (fn [shape] (assoc shape :applied-tokens {:rx (random-uuid)})))
:token {:id (random-uuid)}})]] #_(wtc/on-add-token {:token-type-props {:attributes {:rx :ry}
:on-update-shape #(fn [& _])}
:shape-ids [(:id rect-1)]
:token {:id (random-uuid)}})]]
(ths/run-store (ths/run-store
store done events store done events
(fn [new-state] (fn [new-state]
(let [;; ==== Get (let [file' (ths/get-file-from-store new-state)
shape1' (get-in new-state [:workspace-data page' (cthf/current-page file')
:pages-index rect-1' (cths/get-shape file' :rect-1)
(cthi/id :page1) ;; ==== Get
:objects #_#_rect-1' (get-in new-state [:workspace-data
(cthi/id :shape1)]) :pages-index
fills' (:fills shape1') (cthi/id :page-1)
fill' (first fills')] :objects
(cthi/id :rect-1)])]
;; ==== Check
(t/is (some? (:applied-tokens rect-1')))))))))
;; ==== Check
(t/is (some? shape1'))
(t/is (= (count fills') 1))
(t/is (= (:fill-color fill') "#fabada"))
(t/is (= (:fill-opacity fill') 1))))))))
(comment (comment
(t/run-tests)
(defn make-printable (defn make-printable
"Convert records that are not printable by cider inspect into regular maps." "Convert records that are not printable by cider inspect into regular maps."
[coll] [coll]