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.

inline_autocomplete_test.rb 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
  25. :boards, :messages
  26. def test_inline_autocomplete_for_issues
  27. log_user('jsmith', 'jsmith')
  28. visit 'issues/new'
  29. fill_in 'Description', :with => '#'
  30. within('.tribute-container') do
  31. assert page.has_text? 'Bug #12: Closed issue on a locked version'
  32. assert page.has_text? 'Bug #1: Cannot print recipes'
  33. first('li').click
  34. end
  35. assert_equal '#12 ', find('#issue_description').value
  36. end
  37. def test_inline_autocomplete_for_issues_with_double_hash_keep_syntax
  38. log_user('admin', 'admin')
  39. visit 'projects/ecookbook/issues/new'
  40. fill_in 'Description', :with => '##Closed'
  41. within('.tribute-container') do
  42. assert page.has_text? 'Bug #12: Closed issue on a locked version'
  43. assert page.has_text? 'Bug #11: Closed issue on a closed version'
  44. assert page.has_text? 'Bug #8: Closed issue'
  45. first('li').click
  46. end
  47. assert_equal '##12 ', find('#issue_description').value
  48. end
  49. def test_inline_autocomplete_filters_autocomplete_items
  50. log_user('jsmith', 'jsmith')
  51. visit 'issues/new'
  52. fill_in 'Description', :with => '#Closed'
  53. within('.tribute-container') do
  54. assert page.has_text? 'Bug #12: Closed issue on a locked version'
  55. assert page.has_text? 'Bug #11: Closed issue on a closed version'
  56. assert_not page.has_text? 'Bug #1: Cannot print recipes'
  57. end
  58. end
  59. def test_inline_autocomplete_on_issue_edit_description_should_show_autocomplete
  60. log_user('jsmith', 'jsmith')
  61. visit 'issues/1/edit'
  62. within('#issue-form') do
  63. click_link('Edit', match: :first)
  64. fill_in 'Description', :with => '#'
  65. end
  66. page.has_css?('.tribute-container li', minimum: 1)
  67. end
  68. def test_inline_autocomplete_on_issue_edit_notes_should_show_autocomplete
  69. log_user('jsmith', 'jsmith')
  70. visit 'issues/1/edit'
  71. # Prevent random fails because the element is not yet enabled
  72. find('#issue_notes').click
  73. fill_in 'issue[notes]', :with => '#'
  74. page.has_css?('.tribute-container li', minimum: 1)
  75. end
  76. def test_inline_autocomplete_on_issue_custom_field_with_full_text_formatting_should_show_autocomplete
  77. IssueCustomField.create!(
  78. :name => 'Full width field',
  79. :field_format => 'text', :full_width_layout => '1',
  80. :tracker_ids => [1], :is_for_all => true, :text_formatting => 'full'
  81. )
  82. log_user('jsmith', 'jsmith')
  83. visit 'issues/new'
  84. fill_in 'Full width field', :with => '#'
  85. page.has_css?('.tribute-container li', minimum: 1)
  86. end
  87. def test_inline_autocomplete_on_wiki_should_show_autocomplete
  88. log_user('jsmith', 'jsmith')
  89. visit 'projects/ecookbook/wiki/CookBook_documentation/edit'
  90. # Prevent random fails because the element is not yet enabled
  91. find('.wiki-edit').click
  92. fill_in 'content[text]', :with => '#'
  93. page.has_css?('.tribute-container li', minimum: 1)
  94. end
  95. def test_inline_autocomplete_on_news_description_should_show_autocomplete
  96. log_user('jsmith', 'jsmith')
  97. visit 'projects/ecookbook/news'
  98. click_link 'Add news'
  99. # Prevent random fails because the element is not yet enabled
  100. find('.wiki-edit').click
  101. fill_in 'Description', :with => '#'
  102. page.has_css?('.tribute-container li', minimum: 1)
  103. end
  104. def test_inline_autocomplete_on_new_message_description_should_show_autocomplete
  105. log_user('jsmith', 'jsmith')
  106. visit 'projects/ecookbook/boards/1'
  107. click_link 'New message'
  108. # Prevent random fails because the element is not yet enabled
  109. find('.wiki-edit').click
  110. fill_in 'message[content]', :with => '#'
  111. page.has_css?('.tribute-container li', minimum: 1)
  112. end
  113. def test_inline_autocompletion_of_wiki_page_links
  114. log_user('jsmith', 'jsmith')
  115. visit 'issues/new'
  116. fill_in 'Description', :with => '[['
  117. within('.tribute-container') do
  118. assert page.has_text? 'Child_1_1'
  119. assert page.has_text? 'Page_with_sections'
  120. end
  121. fill_in 'Description', :with => '[[page'
  122. within('.tribute-container') do
  123. assert page.has_text? 'Page_with_sections'
  124. assert page.has_text? 'Another_page'
  125. assert_not page.has_text? 'Child_1_1'
  126. first('li').click
  127. end
  128. assert_equal '[[Page_with_sections]] ', find('#issue_description').value
  129. end
  130. def test_inline_autocomplete_for_issues_should_escape_html_elements
  131. issue = Issue.generate!(subject: 'This issue has a <select> element', project_id: 1, tracker_id: 1)
  132. log_user('jsmith', 'jsmith')
  133. visit 'projects/1/issues/new'
  134. fill_in 'Description', :with => '#This'
  135. within('.tribute-container') do
  136. assert page.has_text? "Bug ##{issue.id}: This issue has a <select> element"
  137. end
  138. end
  139. def test_inline_autocomplete_for_users_should_work_after_status_change
  140. log_user('jsmith', 'jsmith')
  141. visit '/issues/1/edit'
  142. find('#issue_notes').click
  143. fill_in 'issue[notes]', :with => '@lopper'
  144. within('.tribute-container') do
  145. assert page.has_text? "Dave Lopper"
  146. end
  147. page.find('#issue_status_id').select('Feedback')
  148. find('#issue_notes').click
  149. fill_in 'issue[notes]', :with => '@lopper'
  150. within('.tribute-container') do
  151. assert page.has_text? "Dave Lopper"
  152. end
  153. end
  154. def test_inline_autocomplete_for_users_on_issues_bulk_edit_show_autocomplete
  155. log_user('jsmith', 'jsmith')
  156. visit '/issues/bulk_edit?ids[]=1&ids[]=2'
  157. find('#notes').click
  158. fill_in 'notes', :with => '@lopper'
  159. within('.tribute-container') do
  160. assert page.has_text? 'Dave Lopper'
  161. first('li').click
  162. end
  163. assert_equal '@dlopper ', find('#notes').value
  164. end
  165. def test_inline_autocomplete_for_users_on_issues_without_edit_issue_permission
  166. role_developer = Role.find(2)
  167. role_developer.remove_permission!(:edit_issues)
  168. role_developer.add_permission!(:add_issue_watchers)
  169. log_user('jsmith', 'jsmith')
  170. visit '/issues/4/edit'
  171. find('#issue_notes').click
  172. fill_in 'issue[notes]', :with => '@'
  173. within('.tribute-container') do
  174. assert page.has_text? 'John Smith'
  175. first('li').click
  176. end
  177. assert_equal '@jsmith ', find('#issue_notes').value
  178. end
  179. end