mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 05:10:32 +00:00
* 🐛 Preserve effective center alignment on imported SVG strokes Imported strokes without explicit alignment render as centered in the sidebar, geometry and renderers, but stroke mutations materialized them as inner via build-stroke-style-attrs. Split the fallback: existing strokes keep center, genuinely new strokes keep the inner default. Restores the Taiga #7673 regression guard and locks both lifecycles with focused tests. Closes #11581 AI-assisted-by: muse-spark Signed-off-by: makesomethingshit <junsoo1172@gmail.com> * 🐛 Cover explicit inner stroke color updates Verify that changing an existing inner stroke color preserves its alignment, and clarify the missing-stroke default. AI-assisted-by: gpt-6 Signed-off-by: makesomethingshit <junsoo1172@gmail.com> --------- Signed-off-by: makesomethingshit <junsoo1172@gmail.com>
196 lines
9.0 KiB
Clojure
196 lines
9.0 KiB
Clojure
;; 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 SUBSIDIARY SL
|
|
|
|
(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.helpers :as dsh]
|
|
[app.main.data.workspace.colors :as dc]
|
|
[app.main.data.workspace.shapes :as dwsh]
|
|
[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
|
|
[(dwsh/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
|
|
objects (dsh/lookup-page-objects new-state)
|
|
shape1' (get objects (cthi/id :shape1))
|
|
fills' (:fills shape1')
|
|
fill' (first fills')]
|
|
|
|
;; ==== Check
|
|
(t/is (some? shape1'))
|
|
(t/is (= (count fills') 1))
|
|
(t/is (= (:fill-color fill') "#fabada"))
|
|
(t/is (= (:fill-opacity fill') 1))))))))
|
|
|
|
(t/deftest test-update-stroke-color
|
|
;; Old shapes without stroke-alignment are rendered as if it is centered
|
|
(t/async
|
|
done
|
|
(let [;; ==== Setup
|
|
store
|
|
(ths/setup-store
|
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
|
(cths/add-sample-shape :shape1 :strokes [{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2}])))
|
|
|
|
;; ==== Action
|
|
events
|
|
[(dc/change-stroke-color #{(cthi/id :shape1)} {:color "#FABADA"} 0)]]
|
|
|
|
(ths/run-store
|
|
store done events
|
|
(fn [new-state]
|
|
(let [;; ==== Get
|
|
objects (dsh/lookup-page-objects new-state)
|
|
shape1' (get objects (cthi/id :shape1))
|
|
stroke' (first (:strokes shape1'))]
|
|
|
|
;; ==== Check
|
|
(t/is (some? shape1'))
|
|
;; Old shapes without stroke-alignment are rendered as if it is
|
|
;; centered (Taiga #7673); an unrelated color change must not
|
|
;; switch the effective alignment to the new-stroke default.
|
|
(t/is (= (:stroke-alignment stroke') :center))
|
|
(t/is (= (:stroke-color stroke') "#FABADA"))
|
|
(t/is (= (:stroke-width stroke') 2))))))))
|
|
|
|
(t/deftest test-update-stroke-color-preserves-inner-alignment
|
|
(t/async
|
|
done
|
|
(let [store (ths/setup-store
|
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
|
(cths/add-sample-shape :shape1 :strokes [{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2
|
|
:stroke-alignment :inner}])))
|
|
events [(dc/change-stroke-color #{(cthi/id :shape1)} {:color "#FABADA"} 0)]]
|
|
(ths/run-store
|
|
store done events
|
|
(fn [new-state]
|
|
(let [objects (dsh/lookup-page-objects new-state)
|
|
stroke' (first (:strokes (get objects (cthi/id :shape1))))]
|
|
(t/is (= (:stroke-alignment stroke') :inner))
|
|
(t/is (= (:stroke-color stroke') "#FABADA"))))))))
|
|
|
|
(t/deftest test-update-stroke-attrs-preserves-missing-alignment
|
|
;; Existing strokes without :stroke-alignment keep effective :center
|
|
;; on the change-stroke-attrs path; explicit alignments are untouched.
|
|
(t/async
|
|
done
|
|
(let [store (ths/setup-store
|
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
|
(cths/add-sample-shape :shape1 :strokes [{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2}])
|
|
(cths/add-sample-shape :shape2 :strokes [{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2
|
|
:stroke-alignment :inner}])
|
|
(cths/add-sample-shape :shape3 :strokes [{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2
|
|
:stroke-alignment :outer}])))
|
|
events [(dc/change-stroke-attrs #{(cthi/id :shape1)} {:stroke-width 4} 0)
|
|
(dc/change-stroke-attrs #{(cthi/id :shape2)} {:stroke-width 4} 0)
|
|
(dc/change-stroke-attrs #{(cthi/id :shape3)} {:stroke-width 4} 0)]]
|
|
(ths/run-store
|
|
store done events
|
|
(fn [new-state]
|
|
(let [objects (dsh/lookup-page-objects new-state)
|
|
stroke1' (first (:strokes (get objects (cthi/id :shape1))))
|
|
stroke2' (first (:strokes (get objects (cthi/id :shape2))))
|
|
stroke3' (first (:strokes (get objects (cthi/id :shape3))))]
|
|
(t/is (= (:stroke-alignment stroke1') :center))
|
|
(t/is (= (:stroke-width stroke1') 4))
|
|
(t/is (= (:stroke-alignment stroke2') :inner))
|
|
(t/is (= (:stroke-alignment stroke3') :outer))))))))
|
|
|
|
(t/deftest test-new-stroke-keeps-inner-default
|
|
;; A shape with no strokes at all still gets the current new-stroke
|
|
;; default (:inner); the fix must not revert the new-stroke default
|
|
;; to :center.
|
|
(t/async
|
|
done
|
|
(let [store (ths/setup-store
|
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
|
(cths/add-sample-shape :shape1 :strokes [])))
|
|
events [(dc/change-stroke-color #{(cthi/id :shape1)} {:color "#FABADA"} 0)]]
|
|
(ths/run-store
|
|
store done events
|
|
(fn [new-state]
|
|
(let [objects (dsh/lookup-page-objects new-state)
|
|
shape1' (get objects (cthi/id :shape1))
|
|
stroke' (first (:strokes shape1'))]
|
|
(t/is (some? shape1'))
|
|
(t/is (= (:stroke-alignment stroke') :inner))
|
|
(t/is (= (:stroke-color stroke') "#FABADA"))))))))
|
|
(t/deftest test-update-stroke-color-preserves-dash-gap
|
|
;; Custom dash/gap on a dashed stroke describe stroke geometry, not color;
|
|
;; a stroke color change must preserve them (issue #11549).
|
|
(t/async
|
|
done
|
|
(let [store (ths/setup-store
|
|
(-> (cthf/sample-file :file1 :page-label :page1)
|
|
(cths/add-sample-shape :shape1 :strokes
|
|
[{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2
|
|
:stroke-style :dashed
|
|
:stroke-dash 4
|
|
:stroke-gap 20}])
|
|
(cths/add-sample-shape :shape2 :strokes
|
|
[{:stroke-color "#000000"
|
|
:stroke-opacity 1
|
|
:stroke-width 2
|
|
:stroke-style :dashed}])))
|
|
events [(dc/change-stroke-color #{(cthi/id :shape1)} {:color "#FABADA"} 0)
|
|
(dc/change-stroke-color #{(cthi/id :shape2)} {:color "#FABADA"} 0)]]
|
|
(ths/run-store
|
|
store done events
|
|
(fn [new-state]
|
|
(let [objects (dsh/lookup-page-objects new-state)
|
|
shape1' (get objects (cthi/id :shape1))
|
|
stroke1' (first (:strokes shape1'))
|
|
shape2' (get objects (cthi/id :shape2))
|
|
stroke2' (first (:strokes shape2'))]
|
|
|
|
;; dashed stroke with custom dash/gap keeps them after color change
|
|
(t/is (some? shape1'))
|
|
(t/is (= (:stroke-color stroke1') "#FABADA"))
|
|
(t/is (= (:stroke-style stroke1') :dashed))
|
|
(t/is (= (:stroke-width stroke1') 2))
|
|
(t/is (= (:stroke-dash stroke1') 4))
|
|
(t/is (= (:stroke-gap stroke1') 20))
|
|
|
|
;; dashed stroke without explicit dash/gap stays unset:
|
|
;; no implicit default is materialized into stored data
|
|
(t/is (some? shape2'))
|
|
(t/is (= (:stroke-color stroke2') "#FABADA"))
|
|
(t/is (= (:stroke-style stroke2') :dashed))
|
|
(t/is (nil? (:stroke-dash stroke2')))
|
|
(t/is (nil? (:stroke-gap stroke2'))))))))) |