mirror of
https://github.com/penpot/penpot.git
synced 2025-07-25 23:37:20 +02:00
✨ Add color checks and test of event creation for fills
This commit is contained in:
parent
8c54cb764f
commit
6719902647
3 changed files with 88 additions and 40 deletions
|
@ -12,7 +12,7 @@
|
|||
[app.common.files.helpers :as cfh]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.text :as txt]
|
||||
[app.common.types.color :as ctc]
|
||||
[app.common.types.color :as types.color]
|
||||
[app.common.types.fill :as types.fill]
|
||||
[app.common.types.shape :as shp]
|
||||
[app.common.types.shape.shadow :refer [check-shadow]]
|
||||
|
@ -181,6 +181,10 @@
|
|||
([ids color position]
|
||||
(change-fill ids color position nil))
|
||||
([ids color position options]
|
||||
(assert (every? uuid? ids) "expect a coll of uuids for `ids`")
|
||||
(assert (number? position) "expect a number for position")
|
||||
|
||||
(let [color (types.color/check-color color)]
|
||||
(ptk/reify ::change-fill
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -189,7 +193,7 @@
|
|||
(rx/concat
|
||||
(rx/of (dwu/start-undo-transaction undo-id))
|
||||
(transform-fill state ids color change-fn options)
|
||||
(rx/of (dwu/commit-undo-transaction undo-id))))))))
|
||||
(rx/of (dwu/commit-undo-transaction undo-id)))))))))
|
||||
|
||||
(defn change-fill-and-clear
|
||||
([ids color] (change-fill-and-clear ids color nil))
|
||||
|
@ -208,14 +212,8 @@
|
|||
([ids color] (add-fill ids color nil))
|
||||
([ids color options]
|
||||
|
||||
(assert
|
||||
(ctc/check-color color)
|
||||
"expected a valid color struct")
|
||||
|
||||
(assert
|
||||
(every? uuid? ids)
|
||||
"expected a valid coll of uuid's")
|
||||
|
||||
(assert (every? uuid? ids) "expected a valid coll of uuid's")
|
||||
(let [color (types.color/check-color color)]
|
||||
(ptk/reify ::add-fill
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -228,13 +226,13 @@
|
|||
(rx/concat
|
||||
(rx/of (dwu/start-undo-transaction undo-id))
|
||||
(transform-fill state ids color change-fn options)
|
||||
(rx/of (dwu/commit-undo-transaction undo-id))))))))
|
||||
(rx/of (dwu/commit-undo-transaction undo-id)))))))))
|
||||
|
||||
(defn remove-fill
|
||||
([ids color position] (remove-fill ids color position nil))
|
||||
([ids color position options]
|
||||
|
||||
(assert (ctc/check-color color)
|
||||
(assert (types.color/check-color color)
|
||||
"expected a valid color struct")
|
||||
(assert (every? uuid? ids)
|
||||
"expected a valid coll of uuid's")
|
||||
|
@ -263,7 +261,7 @@
|
|||
([ids color] (remove-all-fills ids color nil))
|
||||
([ids color options]
|
||||
|
||||
(assert (ctc/check-color color) "expected a valid color struct")
|
||||
(assert (types.color/check-color color) "expected a valid color struct")
|
||||
(assert (every? uuid? ids) "expected a valid coll of uuid's")
|
||||
|
||||
|
||||
|
@ -573,11 +571,11 @@
|
|||
"expected valid color operations")
|
||||
|
||||
(assert
|
||||
(ctc/check-color new-color)
|
||||
(types.color/check-color new-color)
|
||||
"expected valid color structure")
|
||||
|
||||
(assert
|
||||
(ctc/check-color old-color)
|
||||
(types.color/check-color old-color)
|
||||
"expected valid color structure")
|
||||
|
||||
(ptk/reify ::change-color-in-selected
|
||||
|
@ -599,7 +597,7 @@
|
|||
|
||||
(defn apply-color-from-palette
|
||||
[color stroke?]
|
||||
(let [color (ctc/check-color color)]
|
||||
(let [color (types.color/check-color color)]
|
||||
(ptk/reify ::apply-color-from-palette
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
|
@ -634,7 +632,7 @@
|
|||
|
||||
(defn apply-color-from-colorpicker
|
||||
[color]
|
||||
(let [color (ctc/check-color color)]
|
||||
(let [color (types.color/check-color color)]
|
||||
(ptk/reify ::apply-color-from-colorpicker
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -675,7 +673,7 @@
|
|||
|
||||
(defn add-recent-color
|
||||
[color]
|
||||
(let [color (ctc/check-color color)]
|
||||
(let [color (types.color/check-color color)]
|
||||
(ptk/reify ::add-recent-color
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
|
@ -695,11 +693,11 @@
|
|||
|
||||
(defn apply-color-from-assets
|
||||
[file-id color stroke?]
|
||||
(let [color (ctc/check-library-color color)]
|
||||
(let [color (types.color/check-library-color color)]
|
||||
(ptk/reify ::apply-color-from-asserts
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ _]
|
||||
(let [color (ctc/library-color->color color file-id)]
|
||||
(let [color (types.color/library-color->color color file-id)]
|
||||
(rx/of (apply-color-from-palette color stroke?)
|
||||
(add-recent-color color)))))))
|
||||
|
||||
|
|
48
frontend/test/frontend_tests/data/workspace_colors_test.cljs
Normal file
48
frontend/test/frontend_tests/data/workspace_colors_test.cljs
Normal file
|
@ -0,0 +1,48 @@
|
|||
;; 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.data.workspace-colors-test
|
||||
(:require
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.colors :as dwc]
|
||||
[clojure.test :as t]
|
||||
[potok.v2.core :as ptk]))
|
||||
|
||||
(t/deftest build-change-fill-event
|
||||
(let [color1 {:color "#fabada"
|
||||
:opacity 1}
|
||||
color2 {:color "#fabada"
|
||||
:opacity 1
|
||||
:ref-id uuid/zero
|
||||
:ref-file uuid/zero}
|
||||
color3 {:color "#fabada"
|
||||
:opacity -1}
|
||||
color4 {:opacity 1
|
||||
:color "ffffff"}]
|
||||
(t/is (ptk/event? (dwc/change-fill #{uuid/zero} color1 1)))
|
||||
(t/is (ptk/event? (dwc/change-fill #{uuid/zero} color2 1)))
|
||||
(t/is (thrown? js/Error
|
||||
(ptk/event? (dwc/change-fill #{uuid/zero} color3 1))))
|
||||
(t/is (thrown? js/Error
|
||||
(ptk/event? (dwc/change-fill #{uuid/zero} color4 1))))))
|
||||
|
||||
(t/deftest build-add-fill-event
|
||||
(let [color1 {:color "#fabada"
|
||||
:opacity 1}
|
||||
color2 {:color "#fabada"
|
||||
:opacity 1
|
||||
:ref-id uuid/zero
|
||||
:ref-file uuid/zero}
|
||||
color3 {:color "#fabada"
|
||||
:opacity -1}
|
||||
color4 {:opacity 1
|
||||
:color "ffffff"}]
|
||||
(t/is (ptk/event? (dwc/add-fill #{uuid/zero} color1 1)))
|
||||
(t/is (ptk/event? (dwc/add-fill #{uuid/zero} color2 1)))
|
||||
(t/is (thrown? js/Error
|
||||
(ptk/event? (dwc/add-fill #{uuid/zero} color3 1))))
|
||||
(t/is (thrown? js/Error
|
||||
(ptk/event? (dwc/add-fill #{uuid/zero} color4 1))))))
|
|
@ -2,6 +2,7 @@
|
|||
(:require
|
||||
[cljs.test :as t]
|
||||
[frontend-tests.basic-shapes-test]
|
||||
[frontend-tests.data.workspace-colors-test]
|
||||
[frontend-tests.helpers-shapes-test]
|
||||
[frontend-tests.logic.comp-remove-swap-slots-test]
|
||||
[frontend-tests.logic.components-and-tokens]
|
||||
|
@ -39,6 +40,7 @@
|
|||
'frontend-tests.util-snap-data-test
|
||||
'frontend-tests.util-simple-math-test
|
||||
'frontend-tests.basic-shapes-test
|
||||
'frontend-tests.data.workspace-colors-test
|
||||
'frontend-tests.tokens.logic.token-actions-test
|
||||
'frontend-tests.tokens.logic.token-data-test
|
||||
'frontend-tests.tokens.import-export-test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue