diff --git a/frontend/src/app/main/data/workspace/groups.cljs b/frontend/src/app/main/data/workspace/groups.cljs index 384eed100..04beaa553 100644 --- a/frontend/src/app/main/data/workspace/groups.cljs +++ b/frontend/src/app/main/data/workspace/groups.cljs @@ -198,7 +198,8 @@ (dws/select-shapes (d/ordered-set (:id group)))) (ptk/data-event :layout/update {:ids parents})))))))) -(def group-selected +(defn group-selected + [] (ptk/reify ::group-selected ptk/WatchEvent (watch [_ state _] @@ -258,7 +259,8 @@ (when change-selection? (dws/select-shapes child-ids)))))))) -(def ungroup-selected +(defn ungroup-selected + [] (ptk/reify ::ungroup-selected ptk/WatchEvent (watch [_ state _] diff --git a/frontend/src/app/main/data/workspace/shortcuts.cljs b/frontend/src/app/main/data/workspace/shortcuts.cljs index 2d808a9bd..45a763cca 100644 --- a/frontend/src/app/main/data/workspace/shortcuts.cljs +++ b/frontend/src/app/main/data/workspace/shortcuts.cljs @@ -119,12 +119,12 @@ :group {:tooltip (ds/meta "G") :command (ds/c-mod "g") :subsections [:modify-layers] - :fn #(emit-when-no-readonly dw/group-selected)} + :fn #(emit-when-no-readonly (dw/group-selected))} :ungroup {:tooltip (ds/shift "G") :command "shift+g" :subsections [:modify-layers] - :fn #(emit-when-no-readonly dw/ungroup-selected)} + :fn #(emit-when-no-readonly (dw/ungroup-selected))} :mask {:tooltip (ds/meta "M") :command (ds/c-mod "m") diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 4dd499d18..c25d5cdfe 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -243,8 +243,8 @@ is-group? (and single? has-group?) is-bool? (and single? has-bool?) - do-create-group #(st/emit! dw/group-selected) - do-remove-group #(st/emit! dw/ungroup-selected) + do-create-group #(st/emit! (dw/group-selected)) + do-remove-group #(st/emit! (dw/ungroup-selected)) do-mask-group #(st/emit! (dw/mask-group)) do-unmask-group #(st/emit! (dw/unmask-group)) do-create-artboard-from-selection diff --git a/frontend/test/frontend_tests/logic/groups_test.cljs b/frontend/test/frontend_tests/logic/groups_test.cljs new file mode 100644 index 000000000..a535a586f --- /dev/null +++ b/frontend/test/frontend_tests/logic/groups_test.cljs @@ -0,0 +1,51 @@ +;; 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 INC +(ns frontend-tests.logic.groups-test + (:require + [app.common.data :as d] + [app.common.test-helpers.compositions :as ctho] + [app.common.test-helpers.files :as cthf] + [app.common.test-helpers.shapes :as cths] + [app.common.uuid :as uuid] + [app.main.data.workspace :as dw] + [app.main.data.workspace.groups :as dwgr] + [app.main.data.workspace.selection :as dws] + [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 test-create-group + (t/async + done + (let [;; ==== Setup + file (-> (cthf/sample-file :file1) + (cths/add-sample-shape :test-shape)) + store (ths/setup-store file) + test-shape (cths/get-shape file :test-shape) + + ;; ==== Action + events + [(dws/select-shapes (d/ordered-set (:id test-shape))) + (dwgr/group-selected)]] + + (ths/run-store + store done events + (fn [new-state] + (let [;; ==== Get + file' (ths/get-file-from-store new-state) + page' (cthf/current-page file') + group-id (->> (:objects page') + vals + (filter #(= :group (:type %))) + first + :id)] + ;; ==== Check + ;; Group has been created and is selected + (t/is (= (get-in new-state [:workspace-local :selected]) #{group-id}))))))))