mirror of
https://github.com/penpot/penpot.git
synced 2026-10-31 23:10:31 +00:00
🐛 Fix assertion when renaming a variant to an invalid name
When a variant is renamed to a name that is not a valid properties formula, rename-shape-or-variant passed an empty map as the updated properties. The variant functions now assert that properties are a vector or nil, so the rename failed. Pass an empty vector instead, which means the same and keeps the order the properties have. Add a test that renames a variant to an invalid name through a test store and checks that it gets marked with :variant-error. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
d4c01ae0b1
commit
c034838a42
@ -764,7 +764,7 @@
|
||||
component-id
|
||||
variant-id
|
||||
variant-properties
|
||||
{})
|
||||
[])
|
||||
(dwva/remove-empty-properties variant-id)
|
||||
(dwva/update-error component-id name)))))))
|
||||
|
||||
|
||||
44
frontend/test/frontend_tests/logic/rename_variant_test.cljs
Normal file
44
frontend/test/frontend_tests/logic/rename_variant_test.cljs
Normal file
@ -0,0 +1,44 @@
|
||||
;; 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.rename-variant-test
|
||||
(:require
|
||||
[app.common.test-helpers.files :as cthf]
|
||||
[app.common.test-helpers.shapes :as cths]
|
||||
[app.common.test-helpers.variants :as cthv]
|
||||
[app.main.data.workspace :as dw]
|
||||
[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 rename-variant-with-invalid-name
|
||||
"Renaming a variant in the layers panel to a name that is not a valid
|
||||
properties formula marks it with :variant-error. 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)
|
||||
(cthv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02))
|
||||
store (ths/setup-store file)
|
||||
main (cths/get-shape file :m01)
|
||||
|
||||
;; ==== Action
|
||||
events [(dw/rename-shape-or-variant (:id main) "hola")]]
|
||||
|
||||
(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)]
|
||||
|
||||
;; ==== Check
|
||||
(t/is (= "hola" (:variant-error main')))))))))
|
||||
@ -62,6 +62,7 @@
|
||||
[frontend-tests.logic.path-helpers-test]
|
||||
[frontend-tests.logic.path-lifecycle-test]
|
||||
[frontend-tests.logic.path-tools-test]
|
||||
[frontend-tests.logic.rename-variant-test]
|
||||
[frontend-tests.logic.sidebar-transform-coalescing-test]
|
||||
[frontend-tests.logic.transform-in-variant-test]
|
||||
[frontend-tests.logic.update-position-test]
|
||||
@ -231,6 +232,7 @@
|
||||
'frontend-tests.logic.path-helpers-test
|
||||
'frontend-tests.logic.path-lifecycle-test
|
||||
'frontend-tests.logic.path-tools-test
|
||||
'frontend-tests.logic.rename-variant-test
|
||||
'frontend-tests.logic.pasting-in-containers-test
|
||||
'frontend-tests.logic.transform-in-variant-test
|
||||
'frontend-tests.main.refs-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user