email_reply_body_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Zoom > Email Reply Body', authenticated_as: :authenticate, time_zone: 'Europe/London', type: :system do
  4. let(:agent) { create(:agent, groups: [Group.first]) }
  5. let(:customer) { create(:customer) }
  6. let(:ticket) { create(:ticket, customer: customer, group: Group.first) }
  7. def authenticate
  8. Setting.set 'ui_ticket_zoom_article_email_full_quote', full_quote_setting_enabled
  9. Setting.set 'ui_ticket_zoom_article_email_full_quote_header', full_quote_header_setting_enabled
  10. agent
  11. end
  12. # Create a ticket article with a specific timestamp and customer origin.
  13. # This will allow us to later compare citation header with expected format.
  14. before do
  15. timestamp = DateTime.parse('2022-10-06 12:40:00 UTC')
  16. create(:ticket_article, :inbound_email, ticket: ticket, origin_by: customer, created_at: timestamp)
  17. end
  18. context 'when replying to a message' do
  19. before do
  20. visit ticket_zoom_path
  21. end
  22. context 'without full quote' do
  23. let(:full_quote_setting_enabled) { false }
  24. let(:full_quote_header_setting_enabled) { false }
  25. it 'body keeps existing content' do
  26. fill_in_body 'keep me'
  27. click_reply
  28. find_reset
  29. expect(body).to have_text 'keep me'
  30. # repeat
  31. fill_in_body 'and me! '
  32. click_reply
  33. find_reset
  34. expect(body).to have_text('keep me').and have_text('and me!')
  35. end
  36. end
  37. context 'with full quote' do
  38. let(:full_quote_setting_enabled) { true }
  39. context 'with header' do
  40. let(:full_quote_header_setting_enabled) { true }
  41. it 'body contains citation header' do
  42. click_reply
  43. expect(body).to contain_citation_header("On Thursday, October 6, 2022 at 1:40:00 PM, #{customer.fullname} wrote:")
  44. end
  45. end
  46. context 'without header' do
  47. let(:full_quote_header_setting_enabled) { false }
  48. it 'body does not contain citation header' do
  49. click_reply
  50. expect(body).not_to contain_citation_header("On Thursday, October 6, 2022 at 1:40:00 PM, #{customer.fullname} wrote:")
  51. end
  52. end
  53. # Regression test for issue #2344 - Missing translation for Full-Quote-Text "on xy wrote"
  54. context 'with header in German locale' do
  55. let(:agent) { create(:agent, preferences: { locale: 'de-de' }, groups: [Group.first]) }
  56. let(:full_quote_header_setting_enabled) { true }
  57. it 'body contains localized citation header' do
  58. click_reply
  59. expect(body).to contain_citation_header("Am Donnerstag, 6. Oktober 2022 um 13:40:00, schrieb #{customer.fullname}:")
  60. end
  61. end
  62. end
  63. end
  64. def ticket_zoom_path
  65. "#ticket/zoom/#{ticket.id}"
  66. end
  67. def body
  68. find(:richtext)
  69. end
  70. def fill_in_body(text)
  71. body.send_keys text
  72. end
  73. def find_reset
  74. find('.js-reset')
  75. end
  76. def click_reply
  77. click '.js-ArticleAction[data-type=emailReply]'
  78. end
  79. define :contain_citation_header do
  80. match do
  81. contain_citation_header
  82. end
  83. match_when_negated do
  84. contain_no_citation_header
  85. end
  86. failure_message do
  87. return <<~MESSAGE
  88. expected that citation:
  89. #{citation_block}
  90. would contain header:
  91. #{expected_block}
  92. MESSAGE
  93. end
  94. failure_message_when_negated do
  95. return <<~MESSAGE
  96. expected that citation:
  97. #{citation_block}
  98. would NOT contain header:
  99. #{expected_block}
  100. MESSAGE
  101. end
  102. def contain_citation_header
  103. citation.text.match? expected_regexp
  104. end
  105. def contain_no_citation_header
  106. !citation.text.match? expected_regexp
  107. end
  108. def citation
  109. actual.first('blockquote[type=cite]')
  110. end
  111. def citation_block
  112. citation.text.gsub(%r{^}, '> ')
  113. end
  114. def expected_block
  115. "> #{expected}"
  116. end
  117. def expected_regexp
  118. Regexp.new expected.gsub(' ', '([[:space:]]{1})')
  119. end
  120. end
  121. end