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 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 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 File.expand_path('../../application_system_test_case', __FILE__)
  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_filters_autocomplete_items
  38. log_user('jsmith', 'jsmith')
  39. visit '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_not page.has_text? 'Bug #1: Cannot print recipes'
  45. end
  46. end
  47. def test_inline_autocomplete_on_issue_edit_description_should_show_autocomplete
  48. log_user('jsmith', 'jsmith')
  49. visit 'issues/1/edit'
  50. within('#issue-form') do
  51. click_link('Edit', match: :first)
  52. fill_in 'Description', :with => '#'
  53. end
  54. page.has_css?('.tribute-container li', minimum: 1)
  55. end
  56. def test_inline_autocomplete_on_issue_edit_notes_should_show_autocomplete
  57. log_user('jsmith', 'jsmith')
  58. visit 'issues/1/edit'
  59. # Prevent random fails because the element is not yet enabled
  60. find('#issue_notes').click
  61. fill_in 'issue[notes]', :with => '#'
  62. page.has_css?('.tribute-container li', minimum: 1)
  63. end
  64. def test_inline_autocomplete_on_issue_custom_field_with_full_text_formatting_should_show_autocomplete
  65. IssueCustomField.create!(
  66. :name => 'Full width field',
  67. :field_format => 'text', :full_width_layout => '1',
  68. :tracker_ids => [1], :is_for_all => true, :text_formatting => 'full'
  69. )
  70. log_user('jsmith', 'jsmith')
  71. visit 'issues/new'
  72. fill_in 'Full width field', :with => '#'
  73. page.has_css?('.tribute-container li', minimum: 1)
  74. end
  75. def test_inline_autocomplete_on_wiki_should_show_autocomplete
  76. log_user('jsmith', 'jsmith')
  77. visit 'projects/ecookbook/wiki/CookBook_documentation/edit'
  78. # Prevent random fails because the element is not yet enabled
  79. find('.wiki-edit').click
  80. fill_in 'content[text]', :with => '#'
  81. page.has_css?('.tribute-container li', minimum: 1)
  82. end
  83. def test_inline_autocomplete_on_news_description_should_show_autocomplete
  84. log_user('jsmith', 'jsmith')
  85. visit 'projects/ecookbook/news'
  86. click_link 'Add news'
  87. # Prevent random fails because the element is not yet enabled
  88. find('.wiki-edit').click
  89. fill_in 'Description', :with => '#'
  90. page.has_css?('.tribute-container li', minimum: 1)
  91. end
  92. def test_inline_autocomplete_on_new_message_description_should_show_autocomplete
  93. log_user('jsmith', 'jsmith')
  94. visit 'projects/ecookbook/boards/1'
  95. click_link 'New message'
  96. # Prevent random fails because the element is not yet enabled
  97. find('.wiki-edit').click
  98. fill_in 'message[content]', :with => '#'
  99. page.has_css?('.tribute-container li', minimum: 1)
  100. end
  101. def test_inline_autocompletion_of_wiki_page_links
  102. log_user('jsmith', 'jsmith')
  103. visit 'issues/new'
  104. fill_in 'Description', :with => '[['
  105. within('.tribute-container') do
  106. assert page.has_text? 'Child_1_1'
  107. assert page.has_text? 'Page_with_sections'
  108. end
  109. fill_in 'Description', :with => '[[page'
  110. within('.tribute-container') do
  111. assert page.has_text? 'Page_with_sections'
  112. assert page.has_text? 'Another_page'
  113. assert_not page.has_text? 'Child_1_1'
  114. first('li').click
  115. end
  116. assert_equal '[[Page_with_sections]] ', find('#issue_description').value
  117. end
  118. def test_inline_autocomplete_for_issues_should_escape_html_elements
  119. issue = Issue.generate!(subject: 'This issue has a <select> element', project_id: 1, tracker_id: 1)
  120. log_user('jsmith', 'jsmith')
  121. visit 'projects/1/issues/new'
  122. fill_in 'Description', :with => '#This'
  123. within('.tribute-container') do
  124. assert page.has_text? "Bug ##{issue.id}: This issue has a <select> element"
  125. end
  126. end
  127. def test_inline_autocomplete_for_users_should_work_after_status_change
  128. log_user('jsmith', 'jsmith')
  129. visit '/issues/1/edit'
  130. find('#issue_notes').click
  131. fill_in 'issue[notes]', :with => '@lopper'
  132. within('.tribute-container') do
  133. assert page.has_text? "Dave Lopper"
  134. end
  135. page.find('#issue_status_id').select('Feedback')
  136. find('#issue_notes').click
  137. fill_in 'issue[notes]', :with => '@lopper'
  138. within('.tribute-container') do
  139. assert page.has_text? "Dave Lopper"
  140. end
  141. end
  142. end