mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 21:57:52 +00:00
🐛 Fix validation error when turning a component into a variant
transform-in-variant (Ctrl+K on a component) runs a chain of events, each one committing its own changes. It set the variant-id on the main instance before setting it on the component, so the shape validation of that step saw them out of sync and rejected the change. Set the variant-id on the component first, and give the main instance an empty variant-name, which is what the validator expects while the variant has no properties yet. Add a test that runs transform-in-variant through a test store. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
c38a1d5d59
commit
fbf1d81dcc
@ -0,0 +1,50 @@
|
||||
;; 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.logic.transform-in-variant-test
|
||||
(:require
|
||||
[app.common.test-helpers.components :as cthc]
|
||||
[app.common.test-helpers.compositions :as ctho]
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.types.component :as ctk]
|
||||
[app.main.data.workspace.variants :as dwv]
|
||||
[cljs.test :as t :include-macros true]
|
||||
[frontend-tests.helpers.pages :as thp]
|
||||
[frontend-tests.helpers.state :as ths]))
|
||||
|
||||
(t/use-fixtures :each
|
||||
{:before thp/reset-idmap!})
|
||||
|
||||
(t/deftest transform-component-in-variant
|
||||
"Ctrl+K on a component main turns it into a variant. Each step of the event
|
||||
chain is validated, so a validation error here fails the test through the
|
||||
store error handler."
|
||||
(t/async
|
||||
done
|
||||
(let [;; ==== Setup
|
||||
file (-> (cthf/sample-file :file1)
|
||||
(ctho/add-simple-component :c01 :m01 :r01))
|
||||
store (ths/setup-store file)
|
||||
main (cths/get-shape file :m01)
|
||||
|
||||
;; ==== Action
|
||||
events [(dwv/transform-in-variant (:id main))]]
|
||||
|
||||
(ths/run-store
|
||||
store done events
|
||||
(fn [new-state]
|
||||
(let [;; ==== Get
|
||||
file' (ths/get-file-from-state new-state)
|
||||
main' (cths/get-shape file' :m01)
|
||||
container' (cths/get-shape-by-id file' (:parent-id main'))
|
||||
comp' (cthc/get-component file' :c01)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (ctk/is-variant-container? container'))
|
||||
(t/is (= (:id container') (:variant-id main')))
|
||||
(t/is (= (:id container') (:variant-id comp')))
|
||||
(t/is (= 1 (count (:variant-properties comp'))))))))))
|
||||
@ -91,6 +91,7 @@
|
||||
[frontend-tests.logic.path-tools-test]
|
||||
[frontend-tests.logic.scale-selected-test]
|
||||
[frontend-tests.logic.sidebar-transform-coalescing-test]
|
||||
[frontend-tests.logic.transform-in-variant-test]
|
||||
[frontend-tests.logic.update-position-test]
|
||||
[frontend-tests.logic.wasm-modifiers-nil-id-test]
|
||||
[frontend-tests.logic.wasm-pixel-snap-test]
|
||||
@ -333,6 +334,7 @@
|
||||
'frontend-tests.logic.path-tools-test
|
||||
'frontend-tests.logic.pasting-in-containers-test
|
||||
'frontend-tests.logic.scale-selected-test
|
||||
'frontend-tests.logic.transform-in-variant-test
|
||||
'frontend-tests.main.refs-test
|
||||
'frontend-tests.main-errors-test
|
||||
'frontend-tests.logic.sidebar-transform-coalescing-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user