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.

queries_helper_test.rb 4.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2023 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 '../test_helper'
  19. class QueriesHelperTest < Redmine::HelperTest
  20. include QueriesHelper
  21. fixtures :projects, :enabled_modules, :users, :members,
  22. :member_roles, :roles, :trackers, :issue_statuses,
  23. :issue_categories, :enumerations, :issues,
  24. :watchers, :custom_fields, :custom_values, :versions,
  25. :queries,
  26. :projects_trackers,
  27. :custom_fields_trackers
  28. def test_filters_options_for_select_should_have_a_blank_option
  29. options = filters_options_for_select(IssueQuery.new)
  30. assert_select_in options, 'option[value=""]'
  31. end
  32. def test_filters_options_for_select_should_not_group_regular_filters
  33. with_locale 'en' do
  34. options = filters_options_for_select(IssueQuery.new)
  35. assert_select_in options, 'optgroup option[value=status_id]', 0
  36. assert_select_in options, 'option[value=status_id]', :text => 'Status'
  37. end
  38. end
  39. def test_filters_options_for_select_should_group_date_filters
  40. with_locale 'en' do
  41. options = filters_options_for_select(IssueQuery.new)
  42. assert_select_in options, 'optgroup[label=?]', 'Date', 1
  43. assert_select_in options, 'optgroup > option[value=due_date]', :text => 'Due date'
  44. end
  45. end
  46. def test_filters_options_for_select_should_not_group_only_one_date_filter
  47. with_locale 'en' do
  48. options = filters_options_for_select(TimeEntryQuery.new)
  49. assert_select_in options, 'option[value=spent_on]'
  50. assert_select_in options, 'optgroup[label=?]', 'Date', 0
  51. assert_select_in options, 'optgroup option[value=spent_on]', 0
  52. end
  53. end
  54. def test_filters_options_for_select_should_group_relations_filters
  55. with_locale 'en' do
  56. options = filters_options_for_select(IssueQuery.new)
  57. assert_select_in options, 'optgroup[label=?]', 'Relations', 1
  58. assert_select_in options, 'optgroup[label=?] > option', 'Relations', 11
  59. assert_select_in options, 'optgroup > option[value=relates]', :text => 'Related to'
  60. end
  61. end
  62. def test_filters_options_for_select_should_group_associations_filters
  63. CustomField.delete_all
  64. cf1 = ProjectCustomField.create!(:name => 'Foo', :field_format => 'string', :is_filter => true)
  65. cf2 = ProjectCustomField.create!(:name => 'Bar', :field_format => 'string', :is_filter => true)
  66. with_locale 'en' do
  67. options = filters_options_for_select(IssueQuery.new)
  68. assert_select_in options, 'optgroup[label=?]', 'Project', 1
  69. assert_select_in options, 'optgroup[label=?] > option', 'Project', 3
  70. assert_select_in options, 'optgroup > option[value=?]', "project.cf_#{cf1.id}", :text => "Project's Foo"
  71. end
  72. end
  73. def test_query_to_csv_should_translate_boolean_custom_field_values
  74. f = IssueCustomField.generate!(:field_format => 'bool', :name => 'Boolean', :is_for_all => true, :trackers => Tracker.all)
  75. issues = [
  76. Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '0'}),
  77. Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {f.id.to_s => '1'})
  78. ]
  79. with_locale 'fr' do
  80. csv = query_to_csv(issues, IssueQuery.new(:column_names => ['id', "cf_#{f.id}"]))
  81. assert_include "Oui", csv
  82. assert_include "Non", csv
  83. end
  84. end
  85. end