mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 10:56:20 +00:00
Merge pull request #8963 from penpot/raguirref-fix/builder-bool-media-validation
🐛 Fix builder bool styles and media validation
This commit is contained in:
commit
b3645658fb
@ -356,7 +356,7 @@
|
|||||||
:code :empty-children
|
:code :empty-children
|
||||||
:hint "expected a group with at least one shape for creating a bool"))
|
:hint "expected a group with at least one shape for creating a bool"))
|
||||||
|
|
||||||
(let [head (if (= type :difference)
|
(let [head (if (= (:bool-type bool-shape) :difference)
|
||||||
(first children)
|
(first children)
|
||||||
(last children))
|
(last children))
|
||||||
fills (if (and (contains? head :svg-attrs) (empty? (:fills head)))
|
fills (if (and (contains? head :svg-attrs) (empty? (:fills head)))
|
||||||
@ -364,7 +364,7 @@
|
|||||||
(get head :fills))]
|
(get head :fills))]
|
||||||
(-> bool-shape
|
(-> bool-shape
|
||||||
(assoc :fills fills)
|
(assoc :fills fills)
|
||||||
(assoc :stroks (get head :strokes))))))
|
(assoc :strokes (get head :strokes))))))
|
||||||
|
|
||||||
(defn add-bool
|
(defn add-bool
|
||||||
[state params]
|
[state params]
|
||||||
@ -576,7 +576,7 @@
|
|||||||
{:keys [id width height name]}
|
{:keys [id width height name]}
|
||||||
(-> params
|
(-> params
|
||||||
(update :id default-uuid)
|
(update :id default-uuid)
|
||||||
(check-add-file-media params))]
|
(check-add-file-media))]
|
||||||
|
|
||||||
(-> state
|
(-> state
|
||||||
(update ::blobs assoc media-id blob)
|
(update ::blobs assoc media-id blob)
|
||||||
|
|||||||
72
common/test/common_tests/files_builder_test.cljc
Normal file
72
common/test/common_tests/files_builder_test.cljc
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
;; 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 common-tests.files-builder-test
|
||||||
|
(:require
|
||||||
|
[app.common.files.builder :as fb]
|
||||||
|
[app.common.uuid :as uuid]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
|
(defn- stroke
|
||||||
|
[color]
|
||||||
|
[{:stroke-style :solid
|
||||||
|
:stroke-alignment :inner
|
||||||
|
:stroke-width 1
|
||||||
|
:stroke-color color
|
||||||
|
:stroke-opacity 1}])
|
||||||
|
|
||||||
|
(t/deftest add-bool-uses-difference-head-style
|
||||||
|
(let [file-id (uuid/next)
|
||||||
|
page-id (uuid/next)
|
||||||
|
group-id (uuid/next)
|
||||||
|
child-a (uuid/next)
|
||||||
|
child-b (uuid/next)
|
||||||
|
state (-> (fb/create-state)
|
||||||
|
(fb/add-file {:id file-id :name "Test file"})
|
||||||
|
(fb/add-page {:id page-id :name "Page 1"})
|
||||||
|
(fb/add-group {:id group-id :name "Group A"})
|
||||||
|
(fb/add-shape {:id child-a
|
||||||
|
:type :rect
|
||||||
|
:name "A"
|
||||||
|
:x 0
|
||||||
|
:y 0
|
||||||
|
:width 10
|
||||||
|
:height 10
|
||||||
|
:strokes (stroke "#ff0000")})
|
||||||
|
(fb/add-shape {:id child-b
|
||||||
|
:type :rect
|
||||||
|
:name "B"
|
||||||
|
:x 20
|
||||||
|
:y 0
|
||||||
|
:width 10
|
||||||
|
:height 10
|
||||||
|
:strokes (stroke "#00ff00")})
|
||||||
|
(fb/close-group)
|
||||||
|
(fb/add-bool {:group-id group-id
|
||||||
|
:type :difference}))
|
||||||
|
bool (fb/get-shape state group-id)]
|
||||||
|
(t/is (= :bool (:type bool)))
|
||||||
|
(t/is (= (stroke "#ff0000") (:strokes bool)))))
|
||||||
|
|
||||||
|
(t/deftest add-file-media-validates-and-persists-media
|
||||||
|
(let [file-id (uuid/next)
|
||||||
|
page-id (uuid/next)
|
||||||
|
image-id (uuid/next)
|
||||||
|
state (-> (fb/create-state)
|
||||||
|
(fb/add-file {:id file-id :name "Test file"})
|
||||||
|
(fb/add-page {:id page-id :name "Page 1"})
|
||||||
|
(fb/add-file-media {:id image-id
|
||||||
|
:name "Image"
|
||||||
|
:width 128
|
||||||
|
:height 64}
|
||||||
|
(fb/map->BlobWrapper {:mtype "image/png"
|
||||||
|
:size 42
|
||||||
|
:blob nil})))
|
||||||
|
media (get-in state [::fb/file-media image-id])]
|
||||||
|
(t/is (= image-id (::fb/last-id state)))
|
||||||
|
(t/is (= "Image" (:name media)))
|
||||||
|
(t/is (= 128 (:width media)))
|
||||||
|
(t/is (= 64 (:height media)))))
|
||||||
@ -10,6 +10,7 @@
|
|||||||
[common-tests.buffer-test]
|
[common-tests.buffer-test]
|
||||||
[common-tests.colors-test]
|
[common-tests.colors-test]
|
||||||
[common-tests.data-test]
|
[common-tests.data-test]
|
||||||
|
[common-tests.files-builder-test]
|
||||||
[common-tests.files-changes-test]
|
[common-tests.files-changes-test]
|
||||||
[common-tests.files-migrations-test]
|
[common-tests.files-migrations-test]
|
||||||
[common-tests.geom-align-test]
|
[common-tests.geom-align-test]
|
||||||
@ -82,6 +83,7 @@
|
|||||||
'common-tests.colors-test
|
'common-tests.colors-test
|
||||||
'common-tests.data-test
|
'common-tests.data-test
|
||||||
'common-tests.files-changes-test
|
'common-tests.files-changes-test
|
||||||
|
'common-tests.files-builder-test
|
||||||
'common-tests.files-migrations-test
|
'common-tests.files-migrations-test
|
||||||
'common-tests.geom-align-test
|
'common-tests.geom-align-test
|
||||||
'common-tests.geom-bounds-map-test
|
'common-tests.geom-bounds-map-test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user