From ff58d8c121add30179fab643e1a8097d30a34d62 Mon Sep 17 00:00:00 2001 From: Eva Marco Date: Tue, 29 Sep 2026 16:52:22 +0200 Subject: [PATCH] :wrench: Add tests for restoring variants and property chains Cover the callers of the variant generators that had no tests with the new validation: restoring a deleted variant into its container, restoring it after its container was deleted, and adding a property and then setting its value, as the workspace properties panel does. Each case runs with valid data and expects no validation error on JS. AI-assisted-by: claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 --- .../logic/variant_properties_test.cljc | 24 ++++++ .../common_tests/logic/variants_test.cljc | 80 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/common/test/common_tests/logic/variant_properties_test.cljc b/common/test/common_tests/logic/variant_properties_test.cljc index fed63093ec..cad6b8bdc7 100644 --- a/common/test/common_tests/logic/variant_properties_test.cljc +++ b/common/test/common_tests/logic/variant_properties_test.cljc @@ -744,6 +744,30 @@ (t/is (= (mapv :name (:variant-properties c01')) (mapv :name (:variant-properties c03')))))) +;; The chain that update-properties-names-and-values runs in the workspace +;; when the user adds a property with a value +(t/deftest test-add-new-property-then-set-its-value + (let [file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02)) + v-id (-> (ths/get-shape file :v01) :id) + page (thf/current-page file) + c01-id (:id (thc/get-component file :c01)) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id page)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (clvp/generate-add-new-property v-id :property-name "Color") + (clvp/generate-update-property-value c01-id 1 "Red")) + + file' (thf/apply-changes file changes) + + comp01' (thc/get-component file' :c01) + comp02' (thc/get-component file' :c02)] + + (t/is (= {:name "Color" :value "Red"} (-> comp01' :variant-properties second))) + (t/is (= {:name "Color" :value ""} (-> comp02' :variant-properties second))))) + ;; ============================================================================= ;; validate-shapes failure tests (only run on CLJS, where validation runs) ;; ============================================================================= diff --git a/common/test/common_tests/logic/variants_test.cljc b/common/test/common_tests/logic/variants_test.cljc index e3a0abef77..574d04aeab 100644 --- a/common/test/common_tests/logic/variants_test.cljc +++ b/common/test/common_tests/logic/variants_test.cljc @@ -271,3 +271,83 @@ (t/is (str/includes? (:hint error) "generate-relocate")) (t/is (contains? (error-codes error) :component-main-external))))) + +(defn- delete-shapes + [file labels] + (let [page (thf/current-page file) + changes (-> (pcb/empty-changes nil) + (pcb/with-page page) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page)) + (#(second (cls/generate-delete-shapes % (into #{} (map thi/id) labels) {}))))] + (thf/apply-changes file changes))) + +(defn- restore-changes + [file component-label] + (let [page (thf/current-page file)] + (cll/generate-restore-component (-> (pcb/empty-changes) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects page))) + (:data file) + (thi/id component-label) + (:id file) + page + (:objects page)))) + +(t/deftest test-restore-variant-into-its-container + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02) + (delete-shapes [:m01])) + + ;; ==== Action + changes (restore-changes file :c01) + file' (thf/apply-changes file changes) + + ;; ==== Get + m01' (ths/get-shape file' :m01) + c01' (thc/get-component file' :c01)] + + ;; ==== Check + (t/is (= (thi/id :v01) (:parent-id m01'))) + (t/is (= (thi/id :v01) (:variant-id m01'))) + (t/is (= (thi/id :v01) (:variant-id c01'))))) + +#?(:cljs + (t/deftest test-restore-variant-into-its-container-validates + (let [file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02) + (delete-shapes [:m01])) + changes (restore-changes file :c01)] + + (t/is (nil? (validation-error file changes)))))) + +(t/deftest test-restore-variant-after-deleting-its-container + (let [;; ==== Setup + file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02) + (delete-shapes [:m01 :m02])) + + ;; ==== Action + changes (restore-changes file :c01) + file' (thf/apply-changes file changes) + + ;; ==== Get + v01' (ths/get-shape file' :v01) + m01' (ths/get-shape file' :m01) + c01' (thc/get-component file' :c01)] + + ;; ==== Check + (t/is (nil? v01')) + (t/is (some? m01')) + (t/is (nil? (:variant-id m01'))) + (t/is (nil? (:variant-id c01'))))) + +#?(:cljs + (t/deftest test-restore-variant-after-deleting-its-container-validates + (let [file (-> (thf/sample-file :file1) + (thv/add-variant :v01 :c01 :m01 :c02 :m02) + (delete-shapes [:m01 :m02])) + changes (restore-changes file :c01)] + + (t/is (nil? (validation-error file changes))))))