From 28c4cc7cee75afc10ef9d3461de39ab888ea056b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 28 Aug 2025 11:44:51 -0400 Subject: [PATCH 1/2] test: backfill hotkeys helper tests and remove support for the unused use case of comma-delimited-strings --- app/helpers/hotkeys_helper.rb | 25 ++++++-------- test/helpers/hotkeys_helper_test.rb | 52 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 test/helpers/hotkeys_helper_test.rb diff --git a/app/helpers/hotkeys_helper.rb b/app/helpers/hotkeys_helper.rb index 7bd0424d1..48f3cc6f7 100644 --- a/app/helpers/hotkeys_helper.rb +++ b/app/helpers/hotkeys_helper.rb @@ -1,19 +1,14 @@ module HotkeysHelper + # Pass in an array of chorded keys, e.g. ["ctrl", "shift", "J"] def hotkey_label(hotkey) - hotkey.split(",").first if hotkey - case hotkey - when Array - hotkey.map { |key| - if key == "ctrl" && platform.mac? - "⌘" - elsif key == "enter" - platform.mac? ? "return" : "enter" - else - key - end - }.join() - else - hotkey.split(",").first if hotkey - end + hotkey.map do |key| + if key == "ctrl" && platform.mac? + "⌘" + elsif key == "enter" + platform.mac? ? "return" : "enter" + else + key + end + end.join() end end diff --git a/test/helpers/hotkeys_helper_test.rb b/test/helpers/hotkeys_helper_test.rb new file mode 100644 index 000000000..ebade4aa5 --- /dev/null +++ b/test/helpers/hotkeys_helper_test.rb @@ -0,0 +1,52 @@ +require "test_helper" + +class HotkeysHelperTest < ActionView::TestCase + include SetPlatform + + test "mac modifier key" do + emulate_mac + + assert_equal "⌘J", hotkey_label([ "⌘", "J" ]) + end + + test "linux modifier key" do + emulate_linux + + assert_equal "ctrlJ", hotkey_label([ "ctrl", "J" ]) + end + + test "mac enter" do + emulate_mac + + assert_equal "returnJ", hotkey_label([ "enter", "J" ]) + end + + test "linux enter" do + emulate_linux + + assert_equal "enterJ", hotkey_label([ "enter", "J" ]) + end + + test "mac hyper" do + emulate_mac + + assert_equal "hyperJ", hotkey_label([ "hyper", "J" ]) + end + + test "linux hyper" do + emulate_linux + + assert_equal "hyperJ", hotkey_label([ "hyper", "J" ]) + end + + private + def emulate_mac + stub_platform = ApplicationPlatform.new("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36") + self.stubs(:platform).returns(stub_platform) + end + + def emulate_linux + stub_platform = ApplicationPlatform.new("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36") + self.stubs(:platform).returns(stub_platform) + end +end From 5f4ee049c673d6c0122d36f5572f632c23023c2b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 28 Aug 2025 11:47:21 -0400 Subject: [PATCH 2/2] Fix up hotkeys ref: https://fizzy.37signals.com/5986089/collections/2/cards/1452 --- app/helpers/hotkeys_helper.rb | 4 ++-- test/helpers/hotkeys_helper_test.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/hotkeys_helper.rb b/app/helpers/hotkeys_helper.rb index 48f3cc6f7..062f6ca2d 100644 --- a/app/helpers/hotkeys_helper.rb +++ b/app/helpers/hotkeys_helper.rb @@ -8,7 +8,7 @@ module HotkeysHelper platform.mac? ? "return" : "enter" else key - end - end.join() + end.capitalize + end.join("+").gsub(/⌘\+/, "⌘") end end diff --git a/test/helpers/hotkeys_helper_test.rb b/test/helpers/hotkeys_helper_test.rb index ebade4aa5..ec96f6c9c 100644 --- a/test/helpers/hotkeys_helper_test.rb +++ b/test/helpers/hotkeys_helper_test.rb @@ -12,31 +12,31 @@ class HotkeysHelperTest < ActionView::TestCase test "linux modifier key" do emulate_linux - assert_equal "ctrlJ", hotkey_label([ "ctrl", "J" ]) + assert_equal "Ctrl+J", hotkey_label([ "ctrl", "J" ]) end test "mac enter" do emulate_mac - assert_equal "returnJ", hotkey_label([ "enter", "J" ]) + assert_equal "Return+J", hotkey_label([ "enter", "J" ]) end test "linux enter" do emulate_linux - assert_equal "enterJ", hotkey_label([ "enter", "J" ]) + assert_equal "Enter+J", hotkey_label([ "enter", "J" ]) end test "mac hyper" do emulate_mac - assert_equal "hyperJ", hotkey_label([ "hyper", "J" ]) + assert_equal "Hyper+J", hotkey_label([ "hyper", "J" ]) end test "linux hyper" do emulate_linux - assert_equal "hyperJ", hotkey_label([ "hyper", "J" ]) + assert_equal "Hyper+J", hotkey_label([ "hyper", "J" ]) end private