🐛 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:
Eva Marco 2026-09-30 14:02:14 +02:00 committed by Andrés Moya
parent d4c01ae0b1
commit c034838a42
3 changed files with 47 additions and 1 deletions

View File

@ -764,7 +764,7 @@
component-id
variant-id
variant-properties
{})
[])
(dwva/remove-empty-properties variant-id)
(dwva/update-error component-id name)))))))

View 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')))))))))

View File

@ -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