summaryrefslogtreecommitdiffstats
path: root/test/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'test/helpers')
-rw-r--r--test/helpers/application_helper_test.rb48
-rw-r--r--test/helpers/avatars_helper_test.rb12
-rw-r--r--test/helpers/icons_helper_test.rb7
-rw-r--r--test/helpers/journals_helper_test.rb19
-rw-r--r--test/helpers/reactions_helper_test.rb216
5 files changed, 301 insertions, 1 deletions
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index f959744e2..2e2e8b933 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -1732,6 +1732,46 @@ class ApplicationHelperTest < Redmine::HelperTest
end
end
+ def test_section_edit_links_with_multiline_heading
+ raw = <<~RAW
+ # Wiki
+
+ ## `Foo` Bar
+
+ The heading above generates multiline HTML.
+ Don't assume heading tags are always single-line.
+
+ ```
+ <h2>
+ <code>Foo</code> Bar</h2>
+ ```
+ RAW
+ @project = Project.find(1)
+ set_language_if_valid 'en'
+ with_settings :text_formatting => 'common_mark' do
+ result =
+ textilizable(
+ raw,
+ :edit_section_links =>
+ {:controller => 'wiki', :action => 'edit',
+ :project_id => '1', :id => 'Test'}
+ ).delete("\n")
+
+ assert_match(
+ Regexp.new(
+ '<div class="contextual heading-2" title="Edit this section" id="section-2">' \
+ '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\?section=2">' \
+ '<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-.*\.svg#icon--edit"></use></svg>' \
+ '<span class="icon-label">Edit this section</span>' \
+ '</a></div>' \
+ '<a name="Foo-Bar"></a>' \
+ '<h2 ><code>Foo</code> Bar<a href="#Foo-Bar" class="wiki-anchor">&para;</a></h2>'
+ ),
+ result
+ )
+ end
+ end
+
def test_default_formatter
with_settings :text_formatting => 'unknown' do
text = 'a *link*: http://www.example.net/'
@@ -2363,6 +2403,14 @@ class ApplicationHelperTest < Redmine::HelperTest
assert_equal expected, format_activity_description(text)
end
+ def test_render_flash_messages_should_ignore_non_string_values
+ flash[:array_value] = ['1', '2']
+ flash[:hash_value] = { foo: 'bar' }
+
+ result = render_flash_messages
+ assert_equal '', result
+ end
+
private
def wiki_links_with_special_characters
diff --git a/test/helpers/avatars_helper_test.rb b/test/helpers/avatars_helper_test.rb
index f407ae09e..baa64a653 100644
--- a/test/helpers/avatars_helper_test.rb
+++ b/test/helpers/avatars_helper_test.rb
@@ -68,6 +68,18 @@ class AvatarsHelperTest < Redmine::HelperTest
assert_include 'class="gravatar picture"', avatar('jsmith <jsmith@somenet.foo>', :class => 'picture')
end
+ def test_avatar_with_initials
+ with_settings :gravatar_default => 'initials' do
+ assert_include 'initials="RA"', avatar(User.find(1))
+ end
+ end
+
+ def test_avatar_should_reject_initials_if_default_is_not_initials
+ with_settings :gravatar_default => 'identicon' do
+ assert_not_include 'initials="RA"', avatar(User.find(1))
+ end
+ end
+
def test_avatar_disabled
with_settings :gravatar_enabled => '0' do
assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb
index ab0b58db4..7ef071f86 100644
--- a/test/helpers/icons_helper_test.rb
+++ b/test/helpers/icons_helper_test.rb
@@ -71,6 +71,13 @@ class IconsHelperTest < Redmine::HelperTest
assert_match expected, icon
end
+ def test_sprite_icon_should_return_svg_with_filled_class_when_style_is_filled
+ expected = %r{<svg class="s18 icon-svg icon-svg-filled" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--edit"></use></svg>$}
+ icon = sprite_icon('edit', style: :filled)
+
+ assert_match expected, icon
+ end
+
def test_file_icon_should_return_folder_icon_for_directory
entry = stub(:is_dir? => true)
expected = %r{<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-\w+.svg#icon--folder"></use></svg><span class="icon-label">folder_name</span>}
diff --git a/test/helpers/journals_helper_test.rb b/test/helpers/journals_helper_test.rb
index 355d5ec6f..5c78761ef 100644
--- a/test/helpers/journals_helper_test.rb
+++ b/test/helpers/journals_helper_test.rb
@@ -47,10 +47,27 @@ class JournalsHelperTest < Redmine::HelperTest
journals = issue.visible_journals_with_index # add indice
journal_actions = render_journal_actions(issue, journals.first, {reply_links: true})
- assert_select_in journal_actions, 'a[title=?][class="icon icon-comment"]', 'Quote'
+ assert_select_in journal_actions, 'a[title=?][class="icon-only icon-quote"]', 'Quote'
assert_select_in journal_actions, 'a[title=?][class="icon-only icon-edit"]', 'Edit'
assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-del"]'
assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-copy-link"]'
+ assert_select_in journal_actions, 'span.reaction-button-wrapper'
+ end
+
+ def test_render_journal_actions_with_journal_without_notes
+ User.current = User.find(1)
+ issue = Issue.find(1)
+ issue.journals.first.update!(notes: '')
+
+ journals = issue.visible_journals_with_index
+
+ journal_actions = render_journal_actions(issue, journals.first, reply_links: true)
+
+ assert_select_in journal_actions, 'span.reaction-button-wrapper'
+ assert_select_in journal_actions, 'span.drdn'
+
+ assert_select_in journal_actions, 'a[class="icon-only icon-quote"]', false
+ assert_select_in journal_actions, 'a[class="icon-only icon-edit"]', false
end
def test_journal_thumbnail_attachments_should_be_in_the_same_order_as_the_journal_details
diff --git a/test/helpers/reactions_helper_test.rb b/test/helpers/reactions_helper_test.rb
new file mode 100644
index 000000000..1c5c82418
--- /dev/null
+++ b/test/helpers/reactions_helper_test.rb
@@ -0,0 +1,216 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006- Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+require_relative '../test_helper'
+
+class ReactionsHelperTest < ActionView::TestCase
+ include ReactionsHelper
+
+ setup do
+ User.current = users(:users_002)
+ Setting.reactions_enabled = '1'
+ end
+
+ teardown do
+ Setting.clear_cache
+ end
+
+ test 'reaction_id_for generates a DOM id' do
+ assert_equal "reaction_issue_1", reaction_id_for(issues(:issues_001))
+ end
+
+ test 'reaction_button returns nil when feature is disabled' do
+ Setting.reactions_enabled = '0'
+
+ assert_nil reaction_button(issues(:issues_004))
+ end
+
+ test 'reaction_button returns nil when object not visible' do
+ User.current = users(:users_003)
+
+ assert_nil reaction_button(issues(:issues_004))
+ end
+
+ test 'reaction_button for anonymous users shows readonly button' do
+ User.current = nil
+
+ result = reaction_button(journals(:journals_001))
+
+ assert_select_in result, 'span.reaction-button.readonly[title=?]', 'John Smith'
+ assert_select_in result, 'a.reaction-button', false
+ end
+
+ test 'reaction_button for inactive projects shows readonly button' do
+ issue6 = issues(:issues_006)
+ issue6.project.update!(status: Project::STATUS_CLOSED)
+
+ result = reaction_button(issue6)
+
+ assert_select_in result, 'span.reaction-button.readonly[title=?]', 'John Smith'
+ assert_select_in result, 'a.reaction-button', false
+ end
+
+ test 'reaction_button includes no tooltip when the object has no reactions' do
+ issue = issues(:issues_002) # Issue without reactions
+ result = reaction_button(issue)
+
+ assert_select_in result, 'a.reaction-button[title]', false
+ end
+
+ test 'reaction_button includes tooltip with all usernames when reactions are 10 or fewer' do
+ issue = issues(:issues_002)
+
+ reactions = build_reactions(10)
+ issue.reactions += reactions
+
+ result = with_locale 'en' do
+ reaction_button(issue)
+ end
+
+ # The tooltip should display usernames in order of newest reactions.
+ expected_tooltip = 'Bob9 Doe, Bob8 Doe, Bob7 Doe, Bob6 Doe, Bob5 Doe, ' \
+ 'Bob4 Doe, Bob3 Doe, Bob2 Doe, Bob1 Doe, and Bob0 Doe'
+
+ assert_select_in result, 'a.reaction-button[title=?]', expected_tooltip
+ end
+
+ test 'reaction_button includes tooltip with 10 usernames and others count when reactions exceed 10' do
+ issue = issues(:issues_002)
+
+ reactions = build_reactions(11)
+ issue.reactions += reactions
+
+ result = with_locale 'en' do
+ reaction_button(issue)
+ end
+
+ expected_tooltip = 'Bob10 Doe, Bob9 Doe, Bob8 Doe, Bob7 Doe, Bob6 Doe, ' \
+ 'Bob5 Doe, Bob4 Doe, Bob3 Doe, Bob2 Doe, Bob1 Doe, and 1 other'
+
+ assert_select_in result, 'a.reaction-button[title=?]', expected_tooltip
+ end
+
+ test 'reaction_button should be label less when no reactions' do
+ issue = issues(:issues_002)
+
+ result = with_locale('en') do
+ reaction_button(issue)
+ end
+ assert_select_in result, 'a.reaction-button' do
+ assert_select 'span.icon-label', false
+ end
+
+ # readonly
+ User.current = nil
+ result = with_locale('en') do
+ reaction_button(issue)
+ end
+ assert_select_in result, 'span.reaction-button.readonly' do
+ assert_select 'span.icon-label', false
+ end
+ end
+
+ test 'reaction_button should not count and display non-visible users' do
+ issue2 = issues(:issues_002)
+
+ issue2.reaction_detail = Reaction::Detail.new(
+ visible_users: users(:users_002, :users_003)
+ )
+
+ result = with_locale('en') do
+ reaction_button(issue2)
+ end
+
+ assert_select_in result, 'a.reaction-button[title=?]', 'John Smith and Dave Lopper'
+
+ # When all users are non-visible users
+ issue2.reaction_detail = Reaction::Detail.new(
+ visible_users: []
+ )
+
+ result = with_locale('en') do
+ reaction_button(issue2)
+ end
+
+ assert_select_in result, 'a.reaction-button[title]', false
+ assert_select_in result, 'a.reaction-button' do
+ assert_select 'span.icon-label', false
+ end
+ end
+
+ test 'reaction_button formats the tooltip content based on the support.array settings of each locale' do
+ result = with_locale('ja') do
+ reaction_button(issues(:issues_001))
+ end
+
+ assert_select_in result, 'a.reaction-button[title=?]', 'Dave Lopper、John Smith、Redmine Admin'
+ end
+
+ test 'reaction_button for reacted object' do
+ User.current = users(:users_002)
+
+ issue = issues(:issues_001)
+
+ result = with_locale('en') do
+ reaction_button(issue)
+ end
+ tooltip = 'Dave Lopper, John Smith, and Redmine Admin'
+
+ assert_select_in result, 'span.reaction-button-wrapper[data-reaction-button-id=?]', 'reaction_issue_1' do
+ href = reaction_path(issue.reaction_detail.user_reaction, object_type: 'Issue', object_id: 1)
+
+ assert_select 'a.icon.reaction-button.reacted[href=?]', href do
+ assert_select 'use[href*=?]', 'thumb-up-filled'
+ assert_select 'span.icon-label', '3'
+ end
+
+ assert_select 'span.reaction-button', false
+ end
+ end
+
+ test 'reaction_button for non-reacted object' do
+ User.current = users(:users_004)
+
+ issue = issues(:issues_001)
+
+ result = with_locale('en') do
+ reaction_button(issue)
+ end
+ tooltip = 'Dave Lopper, John Smith, and Redmine Admin'
+
+ assert_select_in result, 'span.reaction-button-wrapper[data-reaction-button-id=?]', 'reaction_issue_1' do
+ href = reactions_path(object_type: 'Issue', object_id: 1)
+
+ assert_select 'a.icon.reaction-button[href=?]', href do
+ assert_select 'use[href*=?]', 'thumb-up'
+ assert_select 'span.icon-label', '3'
+ end
+
+ assert_select 'span.reaction-button', false
+ end
+ end
+
+ private
+
+ def build_reactions(count)
+ Array.new(count) do |i|
+ Reaction.new(user: User.generate!(firstname: "Bob#{i}"))
+ end
+ end
+end