You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keyboard_shortcuts_test.rb 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../application_system_test_case'
  19. class InlineAutocompleteSystemTest < ApplicationSystemTestCase
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  21. :trackers, :projects_trackers, :enabled_modules, :issue_statuses, :issues,
  22. :enumerations, :custom_fields, :custom_values, :custom_fields_trackers,
  23. :watchers, :journals, :journal_details, :versions,
  24. :workflows
  25. def test_keyboard_shortcuts_to_switch_edit_preview_tabs
  26. log_user('jsmith', 'jsmith')
  27. visit 'issues/new'
  28. fill_in 'Description', :with => 'new issue description'
  29. # Switch to preview using control + shift + p
  30. find('#issue_description').click.send_keys([:control, :shift, 'p'])
  31. find 'div.wiki-preview', :visible => true, :text => 'new issue description'
  32. # Switch to edit using control + shift + p
  33. page.find('body').send_keys([:control, :shift, 'p'])
  34. find 'div.wiki-preview', :visible => false
  35. find 'textarea.wiki-edit', :visible => true
  36. # Switch back to preview using command + shift + p
  37. find('#issue_description').click.send_keys([:command, :shift, 'p'])
  38. find 'div.wiki-preview', :visible => true, :text => 'new issue description'
  39. # Switch to edit using control + shift + p
  40. page.find('body').send_keys([:command, :shift, 'p'])
  41. find 'div.wiki-preview', :visible => false
  42. find 'textarea.wiki-edit', :visible => true
  43. end
  44. def test_keyboard_shortcuts_should_switch_to_edit_tab_the_last_previewed_tab
  45. log_user('jsmith', 'jsmith')
  46. visit 'issues/1/edit'
  47. page.first(:link, 'Edit').click
  48. # Preview issue description by clicking the Preview tab
  49. page.find('#issue_description_and_toolbar').click_link('Preview')
  50. find 'div#preview_issue_description', :visible => true
  51. # Preview issue notes by clicking the Preview tab
  52. page.find('fieldset:nth-child(3)').click_link('Preview')
  53. find 'div#preview_issue_notes', :visible => true
  54. page.find('body').send_keys([:command, :shift, 'p'])
  55. find 'textarea#issue_notes', :visible => true
  56. find 'div#preview_issue_notes', :visible => false
  57. end
  58. def test_keyboard_shortcuts_for_wiki_toolbar_buttons_using_textile
  59. with_settings :text_formatting => 'textile' do
  60. log_user('jsmith', 'jsmith')
  61. visit 'issues/new'
  62. find('#issue_description').click.send_keys([modifier_key, 'b'])
  63. assert_equal '**', find('#issue_description').value
  64. # Clear textarea value
  65. fill_in 'Description', :with => ''
  66. find('#issue_description').send_keys([modifier_key, 'u'])
  67. assert_equal '++', find('#issue_description').value
  68. # Clear textarea value
  69. fill_in 'Description', :with => ''
  70. find('#issue_description').send_keys([modifier_key, 'i'])
  71. assert_equal '__', find('#issue_description').value
  72. end
  73. end
  74. def test_keyboard_shortcuts_for_wiki_toolbar_buttons_using_markdown
  75. with_settings :text_formatting => 'markdown' do
  76. log_user('jsmith', 'jsmith')
  77. visit 'issues/new'
  78. find('#issue_description').click.send_keys([modifier_key, 'b'])
  79. assert_equal '****', find('#issue_description').value
  80. # Clear textarea value
  81. fill_in 'Description', :with => ''
  82. find('#issue_description').send_keys([modifier_key, 'u'])
  83. assert_equal '__', find('#issue_description').value
  84. # Clear textarea value
  85. fill_in 'Description', :with => ''
  86. find('#issue_description').send_keys([modifier_key, 'i'])
  87. assert_equal '**', find('#issue_description').value
  88. end
  89. end
  90. def test_keyboard_shortcuts_keys_should_be_shown_in_button_title
  91. log_user('jsmith', 'jsmith')
  92. visit 'issues/new'
  93. within('.jstBlock .jstElements') do
  94. assert_equal "Strong (#{modifier_key_title}B)", find('button.jstb_strong')['title']
  95. assert_equal "Italic (#{modifier_key_title}I)", find('button.jstb_em')['title']
  96. # assert button without shortcut
  97. assert_equal "Deleted", find('button.jstb_del')['title']
  98. end
  99. end
  100. private
  101. def modifier_key
  102. modifier = osx? ? "command" : "control"
  103. modifier.to_sym
  104. end
  105. def modifier_key_title
  106. osx? ? "⌘" : "Ctrl+"
  107. end
  108. end