diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index 81dc28399d..3e950a81b8 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -61,15 +61,18 @@ [changes component-id pos value] (if-let [value (ctv/prepare-property-value value)] (let [data (pcb/get-library-data changes) + objects (pcb/get-objects changes) component (ctcl/get-component data component-id true) - main-id (:main-instance-id component) - name (-> (:variant-properties component) - (update pos assoc :value value) - ctv/properties-to-name)] - (-> changes - (pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value) - {:apply-changes-local-library? true}) - (pcb/update-shapes [main-id] #(assoc % :variant-name name)))) + main-id (:main-instance-id component)] + (if (contains? objects main-id) + (let [name (-> (:variant-properties component) + (update pos assoc :value value) + ctv/properties-to-name)] + (-> changes + (pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value) + {:apply-changes-local-library? true}) + (pcb/update-shapes [main-id] #(assoc % :variant-name name)))) + changes)) changes)) diff --git a/common/test/common_tests/logic/variants_test.cljc b/common/test/common_tests/logic/variants_test.cljc index d4a4696336..d164c0e066 100644 --- a/common/test/common_tests/logic/variants_test.cljc +++ b/common/test/common_tests/logic/variants_test.cljc @@ -511,3 +511,55 @@ (thf/validate-file! file') (t/is (some? new-shape')) (t/is (not= (:parent-id new-shape') (:id container))))) + +(defn- two-property-file-with-other-page + [] + (-> (thf/sample-file :file1 :page-label :page1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02) + (thf/add-sample-page :page2))) + +(t/deftest test-update-property-value-skips-when-main-not-in-objects + (let [file (two-property-file-with-other-page) + other (thf/current-page file) + comp01 (thc/get-component file :c01) + main (ths/get-shape file :m01 :page-label :page1) + before (:variant-properties comp01) + label (:variant-name main) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id other)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects other)) + (clvp/generate-update-property-value (:id comp01) 1 "crítica")) + + file' (thf/apply-changes file changes) + comp01' (thc/get-component file' :c01) + main' (ths/get-shape file' :m01 :page-label :page1)] + + (thf/validate-file! file') + (t/is (empty? (:redo-changes changes))) + (t/is (= before (:variant-properties comp01'))) + (t/is (= label (:variant-name main'))))) + +(t/deftest test-update-property-value-writes-main-page-and-chains + (let [file (two-property-file-with-other-page) + mains (thf/get-page file :page1) + comp01 (thc/get-component file :c01) + + changes (-> (pcb/empty-changes nil) + (pcb/with-page-id (:id mains)) + (pcb/with-library-data (:data file)) + (pcb/with-objects (:objects mains)) + (clvp/generate-update-property-value (:id comp01) 0 "active") + (clvp/generate-update-property-value (:id comp01) 1 "crítica")) + + file' (thf/apply-changes file changes) + comp01' (thc/get-component file' :c01) + main' (ths/get-shape file' :m01 :page-label :page1) + props' (:variant-properties comp01')] + + (thf/validate-file! file') + (t/is (= "active" (-> props' first :value))) + (t/is (= "crítica" (-> props' second :value))) + (t/is (= (ctv/properties-to-name props') (:variant-name main'))) + (t/is (= "active, crítica" (:variant-name main'))))) diff --git a/frontend/src/app/main/data/workspace/variants.cljs b/frontend/src/app/main/data/workspace/variants.cljs index 09f6003a9d..149a5edeff 100644 --- a/frontend/src/app/main/data/workspace/variants.cljs +++ b/frontend/src/app/main/data/workspace/variants.cljs @@ -38,6 +38,34 @@ [beicon.v2.core :as rx] [potok.v2.core :as ptk])) +(defn- get-variant-mains-page + "Return the page that holds the variant mains. + + Pass `:component-id` or `:variant-id`. Finds nothing when that id has + no main page in the file." + [data {:keys [component-id variant-id]}] + (let [page-id (cond + (some? component-id) + (:main-instance-page (ctkl/get-component data component-id)) + + (some? variant-id) + (-> (cfv/find-variant-components data variant-id) + first + :main-instance-page)) + objects (when page-id + (dm/get-in data [:pages-index page-id :objects]))] + (when (and page-id objects) + {:page-id page-id + :objects objects}))) + +(defn- with-main-page + "Run `f` with the page id and objects that hold the component/variant mains. + Returns an empty stream when the file cannot resolve them." + [data opts f] + (if-let [{:keys [page-id objects]} (get-variant-mains-page data opts)] + (f page-id objects) + (rx/empty))) + (defn update-properties-names-and-values "Compares the previous properties with the updated ones and executes the correspondent action for each one depending on if it needs to be removed, updated or added" @@ -49,53 +77,51 @@ ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:component-id component-id} + (fn [page-id objects] + (let [updated-properties (ctv/update-number-in-repeated-prop-names updated-properties) - updated-properties (ctv/update-number-in-repeated-prop-names updated-properties) + properties-to-remove (ctv/find-properties-to-remove previous-properties updated-properties) + properties-to-add (ctv/find-properties-to-add previous-properties updated-properties) + properties-to-update (ctv/find-properties-to-update previous-properties updated-properties) - properties-to-remove (ctv/find-properties-to-remove previous-properties updated-properties) - properties-to-add (ctv/find-properties-to-add previous-properties updated-properties) - properties-to-update (ctv/find-properties-to-update previous-properties updated-properties) + changes (-> (pcb/empty-changes it page-id) + (pcb/with-objects objects) + (pcb/with-library-data data)) - changes (-> (pcb/empty-changes it page-id) - (pcb/with-objects objects) - (pcb/with-library-data data)) + changes (reduce + (fn [changes {:keys [name]}] + (-> changes + (clvp/generate-update-property-value component-id (ctv/find-index-for-property-name previous-properties name) ""))) + changes + properties-to-remove) - changes (reduce - (fn [changes {:keys [name]}] - (-> changes - (clvp/generate-update-property-value component-id (ctv/find-index-for-property-name previous-properties name) ""))) - changes - properties-to-remove) + changes (reduce + (fn [changes {:keys [name value]}] + (-> changes + (clvp/generate-update-property-value component-id (ctv/find-index-for-property-name previous-properties name) value))) + changes + properties-to-update) - changes (reduce - (fn [changes {:keys [name value]}] - (-> changes - (clvp/generate-update-property-value component-id (ctv/find-index-for-property-name previous-properties name) value))) - changes - properties-to-update) + changes (reduce + (fn [changes [idx {:keys [name value]}]] + (-> changes + (clvp/generate-add-new-property variant-id {:property-name name}) + (clvp/generate-update-property-value component-id (+ idx (count previous-properties)) value))) + changes + (map-indexed vector properties-to-add)) - changes (reduce - (fn [changes [idx {:keys [name value]}]] - (-> changes - (clvp/generate-add-new-property variant-id {:property-name name}) - (clvp/generate-update-property-value component-id (+ idx (count previous-properties)) value))) - changes - (map-indexed vector properties-to-add)) + undo-id (js/Symbol)] - undo-id (js/Symbol)] - - (rx/of - (when (or (seq properties-to-remove) (seq properties-to-update)) - (ev/event {::ev/name "variant-edit-property-value" ::ev/origin "workspace:rename-in-layers"})) - (when (seq properties-to-add) - (ev/event {::ev/name "variant-add-property" ::ev/origin "workspace:rename-in-layers"})) - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + (rx/of + (when (or (seq properties-to-remove) (seq properties-to-update)) + (ev/event {::ev/name "variant-edit-property-value" ::ev/origin "workspace:rename-in-layers"})) + (when (seq properties-to-add) + (ev/event {::ev/name "variant-add-property" ::ev/origin "workspace:rename-in-layers"})) + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))))) (defn update-property-name "Update the variant property name on the position pos @@ -105,44 +131,39 @@ ptk/UpdateEvent (update [_ state] (let [file-id (:current-file-id state) - data (dsh/lookup-file-data state) - objects (dsh/lookup-page-objects state) - - related-components (cfv/find-variant-components data objects variant-id)] - - (reduce - (fn [s related-component] - (update-in s - [:files file-id :data :components (:id related-component) :variant-properties] - (fn [props] (mapv #(with-meta % nil) props)))) - state - related-components))) + data (dsh/lookup-file-data state)] + (if-let [{:keys [objects]} (get-variant-mains-page data {:variant-id variant-id})] + (let [related-components (cfv/find-variant-components data objects variant-id)] + (reduce + (fn [s related-component] + (update-in s + [:files file-id :data :components (:id related-component) :variant-properties] + (fn [props] (mapv #(with-meta % nil) props)))) + state + related-components)) + state))) ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - related-components (cfv/find-variant-components data objects variant-id) - - props (-> related-components last :variant-properties) - valid-pos? (> (count props) pos) - prop-name (when valid-pos? (-> props (nth pos) :name)) - - changes (when valid-pos? - (-> (pcb/empty-changes it page-id) - (pcb/with-objects objects) - (pcb/with-library-data data) - (clvp/generate-update-property-name variant-id pos new-name))) - undo-id (js/Symbol)] - (when (and valid-pos? (not= prop-name new-name)) - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id) - (ev/event {::ev/name "variant-edit-property-name" ::ev/origin trigger}))))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [related-components (cfv/find-variant-components data objects variant-id) + props (-> related-components last :variant-properties) + valid-pos? (> (count props) pos) + prop-name (when valid-pos? (-> props (nth pos) :name)) + changes (when valid-pos? + (-> (pcb/empty-changes it page-id) + (pcb/with-objects objects) + (pcb/with-library-data data) + (clvp/generate-update-property-name variant-id pos new-name))) + undo-id (js/Symbol)] + (when (and valid-pos? (not= prop-name new-name)) + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id) + (ev/event {::ev/name "variant-edit-property-name" ::ev/origin trigger})))))))))) (defn update-property-value "Updates the variant property value on the position pos in a component" @@ -150,20 +171,18 @@ (ptk/reify ::update-property-value ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-update-property-value component-id pos value)) - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:component-id component-id} + (fn [page-id objects] + (let [changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-update-property-value component-id pos value)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))))) (defn update-error "Sets or unsets an error for a component" @@ -173,20 +192,18 @@ (ptk/reify ::update-error ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-set-variant-error component-id value)) - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id))))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:component-id component-id} + (fn [page-id objects] + (let [changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-set-variant-error component-id value)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id)))))))))) (defn remove-property "Remove the variant property on the position pos @@ -195,21 +212,18 @@ (ptk/reify ::remove-property ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-remove-property variant-id pos)) - - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-remove-property variant-id pos)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))))) (defn remove-empty-properties "Remove every empty property for all components when their respective values are empty @@ -218,45 +232,39 @@ (ptk/reify ::remove-empty-properties ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [variant-components (cfv/find-variant-components data objects variant-id) + properties-empty-pos (->> variant-components + (mapcat :variant-properties) + (group-by :name) + (map-indexed + (fn [i [_ v]] + [i (->> v + (map :value) + (remove empty?) + empty?)])) + (reverse)) + changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects)) + changes (reduce + (fn [changes [pos property-empty?]] + (if property-empty? + (-> changes + (clvp/generate-remove-property variant-id pos)) + changes)) + changes + properties-empty-pos) + undo-id (js/Symbol)] - variant-components (cfv/find-variant-components data objects variant-id) - - properties-empty-pos (->> variant-components - (mapcat :variant-properties) - (group-by :name) - (map-indexed - (fn [i [_ v]] - [i (->> v - (map :value) - (remove empty?) - empty?)])) - (reverse)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects)) - - changes (reduce - (fn [changes [pos property-empty?]] - (if property-empty? - (-> changes - (clvp/generate-remove-property variant-id pos)) - changes)) - changes - properties-empty-pos) - - undo-id (js/Symbol)] - - (when (seq (:redo-changes changes)) - (rx/of - (ev/event {::ev/name "variant-remove-property" ::ev/origin "workspace:rename-in-layers"}) - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id))))))) + (when (seq (:redo-changes changes)) + (rx/of + (ev/event {::ev/name "variant-remove-property" ::ev/origin "workspace:rename-in-layers"}) + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id)))))))))) (defn add-new-property "Add a new variant property to all the components with this variant-id" @@ -264,21 +272,18 @@ (ptk/reify ::add-new-property ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-add-new-property variant-id options)) - - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-add-new-property variant-id options)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))))) (defn reorder-variant-poperties "Reorder properties by moving a property from some position to some space between positions" @@ -286,21 +291,18 @@ (ptk/reify ::reorder-variant-properties ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-reorder-variant-poperties variant-id from-pos to-space-between-pos)) - - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-reorder-variant-poperties variant-id from-pos to-space-between-pos)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))))) (defn- set-variant-id "Sets the variant-id on a component" @@ -566,21 +568,19 @@ ptk/WatchEvent (watch [_ state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) - variant-components (cfv/find-variant-components data objects variant-id) - clean-name (cpn/clean-path name) - undo-id (js/Symbol)] - - (rx/concat - (rx/of (dwu/start-undo-transaction undo-id) - (dwsh/update-shapes [variant-id] #(assoc % :name clean-name))) - (rx/from (map - #(dwl/rename-component-and-main-instance (:id %) clean-name) - variant-components)) - (rx/of (dwu/commit-undo-transaction undo-id))))))) + (let [data (dsh/lookup-file-data state)] + (with-main-page data {:variant-id variant-id} + (fn [page-id objects] + (let [variant-components (cfv/find-variant-components data objects variant-id) + clean-name (cpn/clean-path name) + undo-id (js/Symbol)] + (rx/concat + (rx/of (dwu/start-undo-transaction undo-id) + (dwsh/update-shapes [variant-id] #(assoc % :name clean-name) {:page-id page-id})) + (rx/from (map + #(dwl/rename-component-and-main-instance (:id %) clean-name) + variant-components)) + (rx/of (dwu/commit-undo-transaction undo-id)))))))))) (defn rename-comp-or-variant-and-main "If the component is in a variant, rename the variant. diff --git a/frontend/test/frontend_tests/data/workspace_variants_test.cljs b/frontend/test/frontend_tests/data/workspace_variants_test.cljs new file mode 100644 index 0000000000..d96a7823b8 --- /dev/null +++ b/frontend/test/frontend_tests/data/workspace_variants_test.cljs @@ -0,0 +1,154 @@ +;; 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.data.workspace-variants-test + (:require + [app.common.path-names :as cpn] + [app.common.test-helpers.components :as cthc] + [app.common.test-helpers.files :as cthf] + [app.common.test-helpers.ids-map :as cthi] + [app.common.test-helpers.shapes :as cths] + [app.common.test-helpers.variants :as thv] + [app.common.types.variant :as ctv] + [app.main.data.workspace.variants :as dwv] + [cljs.test :as t :include-macros true] + [frontend-tests.helpers.state :as ths])) + +(t/use-fixtures :each + {:before cthi/reset-idmap!}) + +(defn- two-property-file-on-other-page + [] + (-> (cthf/sample-file :file1 :page-label :page1) + (thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02) + (cthf/add-sample-page :page2))) + +(defn- run + [file events done assert-fn] + (ths/run-store + (ths/setup-store file) + done + events + (fn [state] + (cthf/validate-file! (ths/get-file-from-state state)) + (assert-fn state)))) + +(defn- variant-name + [file label] + (:variant-name (cths/get-shape file label :page-label :page1))) + +(t/deftest update-property-value-from-another-page + (t/async + done + (let [file (two-property-file-on-other-page) + component-id (:id (cthc/get-component file :c01)) + other-id (cthi/id :page2)] + (run file + [(dwv/update-property-value component-id 0 "active") + (dwv/update-property-value component-id 1 "crítica")] + done + (fn [state] + (let [file (ths/get-file-from-state state) + props (:variant-properties (cthc/get-component file :c01))] + (t/is (= other-id (:current-page-id state))) + (t/is (= "crítica" (-> props second :value))) + (t/is (= "active, crítica" (variant-name file :m01))) + (t/is (= (ctv/properties-to-name props) (variant-name file :m01))))))))) + +(t/deftest update-property-value-on-main-page + (t/async + done + (let [file (-> (two-property-file-on-other-page) + (cthf/switch-to-page :page1)) + component-id (:id (cthc/get-component file :c01))] + (run file + [(dwv/update-property-value component-id 1 "crítica")] + done + (fn [state] + (let [file (ths/get-file-from-state state) + props (:variant-properties (cthc/get-component file :c01))] + (t/is (= (cthi/id :page1) (:current-page-id state))) + (t/is (= "crítica" (-> props second :value))) + (t/is (= (ctv/properties-to-name props) (variant-name file :m01))))))))) + +(t/deftest add-remove-reorder-from-another-page + (t/async + done + (let [file (two-property-file-on-other-page) + variant-id (cthi/id :v01)] + (run file + [(dwv/add-new-property variant-id {:fill-values? true}) + (dwv/reorder-variant-poperties variant-id 0 3) + (dwv/remove-property variant-id 0)] + done + (fn [state] + (let [file (ths/get-file-from-state state) + comp1 (cthc/get-component file :c01) + comp2 (cthc/get-component file :c02) + names1 (mapv :name (:variant-properties comp1)) + names2 (mapv :name (:variant-properties comp2))] + (t/is (= names1 names2)) + (t/is (= (ctv/properties-to-name (:variant-properties comp1)) + (variant-name file :m01))) + (t/is (= (ctv/properties-to-name (:variant-properties comp2)) + (variant-name file :m02))))))))) + +(t/deftest formula-rename-from-another-page + (t/async + done + (let [file (two-property-file-on-other-page) + comp (cthc/get-component file :c01) + previous (:variant-properties comp) + updated [{:name "Property 1" :value "active"} + {:name "Property 2" :value "crítica"}]] + (run file + [(dwv/update-properties-names-and-values (:id comp) (:variant-id comp) previous updated) + (dwv/remove-empty-properties (:variant-id comp))] + done + (fn [state] + (let [file (ths/get-file-from-state state) + props (:variant-properties (cthc/get-component file :c01))] + (t/is (= "active" (-> props first :value))) + (t/is (= "crítica" (-> props second :value))) + (t/is (= (ctv/properties-to-name props) (variant-name file :m01))))))))) + +(t/deftest update-property-name-from-another-page + (t/async + done + (let [file (two-property-file-on-other-page) + variant-id (cthi/id :v01)] + (run file + [(dwv/update-property-name variant-id 0 "Status" {:trigger "test"})] + done + (fn [state] + (let [file (ths/get-file-from-state state) + names (mapv :name (:variant-properties (cthc/get-component file :c01)))] + (t/is (= names (mapv :name (:variant-properties (cthc/get-component file :c02))))) + (t/is (= "Status" (first names))))))))) + +(t/deftest rename-variant-from-another-page + (t/async + done + (let [file (two-property-file-on-other-page) + variant-id (cthi/id :v01) + other-id (cthi/id :page2) + clean-name (cpn/clean-path "Renamed set")] + (run file + [(dwv/rename-variant variant-id "Renamed set")] + done + (fn [state] + (let [file (ths/get-file-from-state state) + container (cths/get-shape file :v01 :page-label :page1) + main1 (cths/get-shape file :m01 :page-label :page1) + main2 (cths/get-shape file :m02 :page-label :page1) + comp1 (cthc/get-component file :c01) + comp2 (cthc/get-component file :c02)] + (t/is (= other-id (:current-page-id state))) + (t/is (= clean-name (:name container))) + (t/is (= clean-name (:name main1))) + (t/is (= clean-name (:name main2))) + (t/is (= clean-name (cpn/merge-path-item (:path comp1) (:name comp1)))) + (t/is (= clean-name (cpn/merge-path-item (:path comp2) (:name comp2)))))))))) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index c96f1e4983..94188ea2b4 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -38,6 +38,7 @@ [frontend-tests.data.workspace-texts-test] [frontend-tests.data.workspace-thumbnails-test] [frontend-tests.data.workspace-variant-rename-test] + [frontend-tests.data.workspace-variants-test] [frontend-tests.data.workspace-versions-test] [frontend-tests.debug-logging-test] [frontend-tests.errors-governor-test] @@ -189,6 +190,7 @@ 'frontend-tests.data.workspace-texts-test 'frontend-tests.data.workspace-thumbnails-test 'frontend-tests.data.workspace-variant-rename-test + 'frontend-tests.data.workspace-variants-test 'frontend-tests.data.workspace-versions-test 'frontend-tests.debug-logging-test 'frontend-tests.errors-governor-test