penpot/frontend/test/frontend_tests/ui/shortcuts_labels_test.cljs
Roshan Ramani 32d488e162
🐛 Fix swapped Move left and Move right shortcuts (#13068)
The `move-unit-left` shortcut was bound to the Right arrow and moved the
selection right, and `move-unit-right` the reverse, in both the workspace
and the path editor. Arrow keys behaved correctly, but the shortcuts panel
and the shortcut settings showed "Move left" next to the Right arrow, and
customizing "Move left" rebound the rightward move.

AI-assisted-by: claude-opus-5-5

Signed-off-by: Roshan Ramani <roshanramani.dev@gmail.com>
2026-11-17 09:45:02 +01:00

86 lines
3.4 KiB
Clojure

;; 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.ui.shortcuts-labels-test
(:require
[app.main.data.dashboard.shortcuts :as dsc]
[app.main.data.viewer.shortcuts :as vsc]
[app.main.data.workspace.grid-layout.shortcuts :as gsc]
[app.main.data.workspace.path.shortcuts :as psc]
[app.main.data.workspace.shortcuts :as wsc]
[app.main.ui.shortcuts :as ss]
[app.util.i18n :as i18n]
[cljs.test :as t :include-macros true]
[frontend-tests.helpers.mock :as mock]))
;; Every shortcut command definition carries a :label fn holding a static
;; (tr "literal") (see :penpot/tr-dynamic). This locks the wiring: all
;; definition ids resolve through translation-keyname, and unknown ids
;; (stale custom shortcuts, debug commands) fall back to the raw key.
;; Exempt: :preview-frame (debug-only, no PO key) and :delete-stop
;; (colorpicker-local, never translated); both keep today's raw fallback.
(def ^:private definition-maps
[wsc/shortcuts
psc/shortcuts
dsc/shortcuts
dsc/shortcuts-sidebar-navigation
dsc/shortcut-search
dsc/shortcut-create-new-project
vsc/shortcuts
gsc/shortcuts])
(def ^:private exempt-ids
#{:preview-frame})
(def ^:private section-ids
[:basics :workspace :dashboard :viewer])
(def ^:private subsection-ids
[:alignment :basics :edit :generic :main-menu :modify-layers
:navigation-dashboard :navigation-viewer :navigation-workspace
:panels :path-editor :shape :text-editor :tools :zoom-viewer
:zoom-workspace])
(t/deftest command-definitions-carry-static-labels
(with-redefs [i18n/tr (mock/stub (fn [k] (str "TR:" k)))]
(t/testing "every definition id resolves its literal key"
(doseq [shortcuts definition-maps
[id entry] shortcuts
:when (not (contains? exempt-ids id))]
(t/is (fn? (:label entry)) (str id " has a :label fn"))
(t/is (= (str "TR:shortcuts." (name id))
(ss/translation-keyname :sc id))
(str id " resolves"))))
(t/testing "sections resolve their literal keys"
(doseq [id section-ids]
(t/is (= (str "TR:shortcuts.section." (name id))
(ss/translation-keyname :sec id))
(str id " resolves"))))
(t/testing "subsections resolve, bare basics falls back to raw"
(doseq [id (remove #{:basics} subsection-ids)]
(t/is (= (str "TR:shortcuts.subsection." (name id))
(ss/translation-keyname :sub-sec id))
(str id " resolves")))
(t/is (= "shortcuts.subsection.basics"
(ss/translation-keyname :sub-sec :basics))))
(t/testing "unknown ids fall back to the raw key"
(t/is (= "shortcuts.stale-id"
(ss/translation-keyname :sc :stale-id)))
(t/is (= "shortcuts.preview-frame"
(ss/translation-keyname :sc :preview-frame))))))
(t/deftest unit-move-commands-match-their-direction
(doseq [shortcuts [wsc/shortcuts psc/shortcuts]
dir ["up" "down" "left" "right"]
:let [id (keyword (str "move-unit-" dir))
command (:command (get shortcuts id))
commands (if (string? command) [command] command)]]
(t/is (= dir (first commands)) (str id " is bound to the " dir " arrow"))))