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.

journals_helper_test.rb 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 JournalsHelperTest < Redmine::HelperTest
  20. include JournalsHelper
  21. fixtures :projects, :trackers, :issue_statuses, :issues, :journals,
  22. :enumerations, :issue_categories,
  23. :projects_trackers,
  24. :users, :roles, :member_roles, :members,
  25. :enabled_modules,
  26. :custom_fields,
  27. :attachments,
  28. :versions
  29. def test_journal_thumbnail_attachments_should_return_thumbnailable_attachments
  30. skip unless convert_installed?
  31. set_tmp_attachments_directory
  32. issue = Issue.generate!
  33. journal = new_record(Journal) do
  34. issue.init_journal(User.find(1))
  35. issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'image.png'), :author => User.find(1))
  36. issue.attachments << Attachment.new(:file => mock_file_with_options(:original_filename => 'foo'), :author => User.find(1))
  37. issue.save
  38. end
  39. assert_equal 2, journal.details.count
  40. thumbnails = journal_thumbnail_attachments(journal)
  41. assert_equal 1, thumbnails.count
  42. assert_kind_of Attachment, thumbnails.first
  43. assert_equal 'image.png', thumbnails.first.filename
  44. end
  45. def test_render_journal_actions_should_return_edit_link_and_actions_dropdown
  46. User.current = User.find(1)
  47. issue = Issue.find(1)
  48. journals = issue.visible_journals_with_index # add indice
  49. journal_actions = render_journal_actions(issue, journals.first, {reply_links: true})
  50. assert_select_in journal_actions, 'a[title=?][class="icon-only icon-comment"]', 'Quote'
  51. assert_select_in journal_actions, 'a[title=?][class="icon-only icon-edit"]', 'Edit'
  52. assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-del"]'
  53. assert_select_in journal_actions, 'div[class="drdn-items"] a[class="icon icon-copy-link"]'
  54. end
  55. def test_journal_thumbnail_attachments_should_be_in_the_same_order_as_the_journal_details
  56. skip unless convert_installed?
  57. set_tmp_attachments_directory
  58. issue = Issue.generate!
  59. # Thumbnails should be displayed in the same order as Journal.detail, not in attachment id order.
  60. attachment1 = Attachment.generate!(:file => mock_file_with_options(:original_filename => 'image1.png'), :author => User.find(1))
  61. attachment2 = Attachment.generate!(:file => mock_file_with_options(:original_filename => 'image2.png'), :author => User.find(1))
  62. journal = Journal.create!(:journalized => issue, :user_id => 1)
  63. JournalDetail.create!(
  64. :journal => journal, :property => 'attachment',
  65. :prop_key => attachment2.id.to_s,
  66. :value => 'image2.png'
  67. )
  68. JournalDetail.create!(
  69. :journal => journal, :property => 'attachment',
  70. :prop_key => attachment1.id.to_s,
  71. :value => 'image1.png'
  72. )
  73. journal.reload
  74. thumbnails = journal_thumbnail_attachments(journal)
  75. assert_equal 2, thumbnails.count
  76. assert_equal 2, journal.details.count
  77. assert_equal journal.details.map(&:value), thumbnails.map(&:filename)
  78. end
  79. end