From 9b459556cd55947eebe5b0b9e5b4899a523014d1 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Tue, 28 Apr 2020 00:53:06 +0300 Subject: [PATCH] =?UTF-8?q?Fixes=20#3014=20-=20Fullquote=20Header=20for=20?= =?UTF-8?q?forwarded=20mails.=20Thanks=20to=20@drbw=20=E2=9D=A4=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../article_action/email_reply.coffee | 20 ++-- .../ticket/update/full_quote_header_spec.rb | 111 ++++++++++++++++++ 2 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 spec/system/ticket/update/full_quote_header_spec.rb diff --git a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee index 1e13ac968..6144e0254 100644 --- a/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee +++ b/app/assets/javascripts/app/controllers/ticket_zoom/article_action/email_reply.coffee @@ -148,12 +148,7 @@ class EmailReply extends App.Controller selected = App.Utils.text2html(selected) if selected - quote_header = '' - if App.Config.get('ui_ticket_zoom_article_email_full_quote_header') - date = @date_format(article.created_at) - name = article.updated_by.displayName() - email = article.updated_by.email - quote_header = App.i18n.translateInline('On %s, %s wrote:', date, name) + '

' + quote_header = @fullQuoteHeader(article) selected = "


#{quote_header}#{selected}

" @@ -201,7 +196,9 @@ class EmailReply extends App.Controller body = App.Utils.textCleanup(article.body) body = App.Utils.text2html(body) - body = "
---Begin forwarded message:---

#{body}

" + quote_header = @fullQuoteHeader(article) + + body = "
---Begin forwarded message:---

#{quote_header}#{body}

" articleNew = {} articleNew.body = body @@ -342,4 +339,13 @@ class EmailReply extends App.Controller true + @fullQuoteHeader: (article) -> + if !App.Config.get('ui_ticket_zoom_article_email_full_quote_header') + return '' + + date = @date_format(article.created_at) + name = article.updated_by.displayName() + + App.i18n.translateInline('On %s, %s wrote:', date, name) + '

' + App.Config.set('200-EmailReply', EmailReply, 'TicketZoomArticleAction') diff --git a/spec/system/ticket/update/full_quote_header_spec.rb b/spec/system/ticket/update/full_quote_header_spec.rb new file mode 100644 index 000000000..75519e83c --- /dev/null +++ b/spec/system/ticket/update/full_quote_header_spec.rb @@ -0,0 +1,111 @@ +require 'rails_helper' + +RSpec.describe 'Ticket > Update > Full Quote Header', type: :system, time_zone: 'Europe/London' do + let(:group) { Group.find_by(name: 'Users') } + let(:ticket) { create(:ticket, group: group) } + let(:ticket_article) { create(:ticket_article, ticket: ticket, from: 'Example Name ') } + let(:customer) { create(:customer) } + + prepend_before do + Setting.set 'ui_ticket_zoom_article_email_full_quote_header', full_quote_header_setting + end + + before do + UserInfo.current_user_id = customer.id + visit "ticket/zoom/#{ticket_article.ticket.id}" + end + + context 'when "ui_ticket_zoom_article_email_full_quote_header" is enabled' do + let(:full_quote_header_setting) { true } + + it 'includes OP when forwarding' do + within(:active_content) do + click_forward + + within(:richtext) do + expect(page).to contain_full_quote(ticket_article) + end + end + end + + it 'includes OP when replying' do + within(:active_content) do + highlight_and_click_reply + + within(:richtext) do + expect(page).to contain_full_quote(ticket_article) + end + end + end + end + + context 'when "ui_ticket_zoom_article_email_full_quote_header" is disabled' do + let(:full_quote_header_setting) { false } + + it 'does not include OP when forwarding' do + within(:active_content) do + click_forward + + within(:richtext) do + expect(page).not_to contain_full_quote(ticket_article) + end + end + end + + it 'does not include OP when replying' do + within(:active_content) do + highlight_and_click_reply + + within(:richtext) do + expect(page).not_to contain_full_quote(ticket_article) + end + end + end + end + + def click_forward + click '.js-ArticleAction[data-type=emailForward]' + end + + def highlight_and_click_reply + find('.ticket-article-item .textBubble') + .execute_script <<~JAVASCRIPT + window.getSelection().removeAllRanges() + var range = window.document.createRange() + range.setStart(this, 0) + range.setEnd(this.nextSibling, 0) + window.getSelection().addRange(range) + JAVASCRIPT + + click '.js-ArticleAction[data-type=emailReply]' + end + + define :contain_full_quote do + match do + citation.has_text?(name) && citation.has_no_text?(email) && citation.has_text?(timestamp) + end + + match_when_negated do + citation.has_no_text?(name) && citation.has_no_text?(email) && citation.has_no_text?(timestamp) + end + + def citation + actual.first('blockquote[type=cite]') + end + + def name + expected.created_by.fullname + end + + def email + expected.created_by.email + end + + def timestamp + expected + .created_at + .in_time_zone('Europe/London') + .strftime('%A, %B %1d, %Y, %1I:%M:%S %p') + end + end +end