From 92a1699afeb23d7313d97a3e9ec4f2796cc0fbcc Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 3 Nov 2024 23:05:04 +0000 Subject: Adds tests for @IconsHelper@ (#23980). git-svn-id: https://svn.redmine.org/redmine/trunk@23205 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/helpers/icons_helper_test.rb | 128 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 test/helpers/icons_helper_test.rb (limited to 'test/helpers') diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb new file mode 100644 index 000000000..e8ae94c9c --- /dev/null +++ b/test/helpers/icons_helper_test.rb @@ -0,0 +1,128 @@ +# 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 IconsHelperTest < Redmine::HelperTest + include IconsHelper + + def test_sprite_icon_should_return_svg_with_defaults + expected = %r{$} + icon = sprite_icon('edit') + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_label + expected = %r{Edit} + icon = sprite_icon('edit', 'Edit') + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_hidden_label_when_icon_only_is_true + expected = %r{} + icon = sprite_icon('edit', 'Edit', icon_only: true) + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_custom_size + expected = %r{$} + icon = sprite_icon('edit', size: '24') + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_custom_css_class + expected = %r{$} + icon = sprite_icon('edit', css_class: 'custom-class') + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_custom_sprite + expected = %r{$} + icon = sprite_icon('edit', sprite: 'custom') + + assert_match expected, icon + end + + def test_sprite_icon_should_return_svg_with_plugin_sprite + expected = %r{$} + icon = sprite_icon('edit', plugin: 'my_plugin') + + assert_match expected, icon + end + + def test_file_icon_should_return_folder_icon_for_directory + entry = stub(:is_dir? => true) + expected = %r{folder_name} + icon = file_icon(entry, "folder_name") + + assert_match expected, icon + end + + def test_file_icon_should_return_folder_icon_for_files + entry = stub(:is_dir? => false) + expected = %r{file_name} + icon = file_icon(entry, "file_name") + + assert_match expected, icon + end + + def test_file_icon_should_return_file_type_icon_for_files + entry = stub(:is_dir? => false) + expected = %r{text.txt} + icon = file_icon(entry, "text.txt") + + assert_match expected, icon + end + + def test_principal_icon_should_return_group_icon_for_group_classes + expected = %r{} + + %w(groupanonymous groupnonmember group).each do |principal_class| + assert_match expected, principal_icon(principal_class) + end + end + + def test_principal_icon_should_return_nil_for_non_group_classes + assert_nil principal_icon('user') + end + + def test_activity_event_type_icon_should_return_correct_icon_for_reply_events + expected = %r{} + assert_match expected, activity_event_type_icon('reply') + end + + def test_activity_event_type_icon_should_return_correct_icon_for_time_entry_events + expected = %r{} + assert_match expected, activity_event_type_icon('time-entry') + end + + def test_icon_for_mime_type_should_return_specific_icon_for_known_mime_types + assert_equal 'text-plain', icon_for_mime_type('text-plain') + assert_equal 'application-pdf', icon_for_mime_type('application-pdf') + end + + def test_icon_for_mime_type_should_return_generic_file_icon_for_unknown_mime_types + assert_equal 'file', icon_for_mime_type('unknown-type') + end +end \ No newline at end of file -- cgit v1.2.3