2020-04-27 21:53:06 +00:00
|
|
|
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 <asdf1@example.com>') }
|
|
|
|
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
|
2020-07-14 10:39:17 +00:00
|
|
|
expect(page).to contain_full_quote(ticket_article).formatted_for(:forward)
|
2020-04-27 21:53:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes OP when replying' do
|
|
|
|
within(:active_content) do
|
|
|
|
highlight_and_click_reply
|
|
|
|
|
|
|
|
within(:richtext) do
|
2020-07-14 10:39:17 +00:00
|
|
|
expect(page).to contain_full_quote(ticket_article).formatted_for(:reply)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when customer is agent' do
|
|
|
|
let(:customer) { create(:agent) }
|
|
|
|
|
|
|
|
it 'includes OP without email when forwarding' do
|
|
|
|
within(:active_content) do
|
|
|
|
click_forward
|
|
|
|
|
|
|
|
within(:richtext) do
|
|
|
|
expect(page).to contain_full_quote(ticket_article).formatted_for(:forward).ensuring_privacy(true)
|
|
|
|
end
|
2020-04-27 21:53:06 +00:00
|
|
|
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
|
2020-07-14 10:39:17 +00:00
|
|
|
expect(page).not_to contain_full_quote(ticket_article).formatted_for(:forward)
|
2020-04-27 21:53:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not include OP when replying' do
|
|
|
|
within(:active_content) do
|
|
|
|
highlight_and_click_reply
|
|
|
|
|
|
|
|
within(:richtext) do
|
2020-07-14 10:39:17 +00:00
|
|
|
expect(page).not_to contain_full_quote(ticket_article).formatted_for(:reply)
|
2020-04-27 21:53:06 +00:00
|
|
|
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
|
2020-07-14 10:39:17 +00:00
|
|
|
confirm_content && confirm_style
|
2020-04-27 21:53:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
match_when_negated do
|
2020-07-14 10:39:17 +00:00
|
|
|
confirm_no_content
|
|
|
|
end
|
|
|
|
|
|
|
|
# sets expected quote format
|
|
|
|
# @param [Symbol] :forward or :reply, defaults to :reply if not set
|
|
|
|
chain :formatted_for do |style|
|
|
|
|
@style = style
|
|
|
|
end
|
|
|
|
|
|
|
|
def style
|
|
|
|
@style || :reply # rubocop:disable RSpec/InstanceVariable
|
|
|
|
end
|
|
|
|
|
|
|
|
# sets expected privacy level
|
|
|
|
# @param [Boolean] defaults to false if not set
|
|
|
|
chain :ensuring_privacy do |flag|
|
|
|
|
@ensuring_privacy = flag
|
|
|
|
end
|
|
|
|
|
|
|
|
def ensure_privacy?
|
|
|
|
@ensuring_privacy || false # rubocop:disable RSpec/InstanceVariable
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_content
|
|
|
|
case style
|
|
|
|
when :reply
|
|
|
|
confirm_content_reply
|
|
|
|
when :forward
|
|
|
|
confirm_content_forward
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_content_reply
|
|
|
|
citation.has_text?(name) && citation.has_no_text?(email) && citation.has_text?(timestamp_reply)
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_content_forward
|
|
|
|
if ensure_privacy?
|
|
|
|
citation.has_text?(name) && citation.has_no_text?(email) && citation.has_text?(timestamp_forward)
|
|
|
|
else
|
|
|
|
citation.has_text?(name) && citation.has_text?(email) && citation.has_text?(timestamp_forward)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_no_content
|
|
|
|
citation.has_no_text?(name) && citation.has_no_text?(email) && citation.has_no_text?(timestamp_reply) && citation.has_no_text?(timestamp_forward)
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirm_style
|
|
|
|
case style
|
|
|
|
when :forward
|
|
|
|
citation.text.match?(/Subject(.+)\nDate(.+)/)
|
|
|
|
when :reply
|
|
|
|
citation.text.match?(/^On(.+)wrote:$/)
|
|
|
|
end
|
2020-04-27 21:53:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def citation
|
|
|
|
actual.first('blockquote[type=cite]')
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
expected.created_by.fullname
|
|
|
|
end
|
|
|
|
|
|
|
|
def email
|
|
|
|
expected.created_by.email
|
|
|
|
end
|
|
|
|
|
2020-07-14 10:39:17 +00:00
|
|
|
def timestamp_reply
|
2020-04-27 21:53:06 +00:00
|
|
|
expected
|
|
|
|
.created_at
|
|
|
|
.in_time_zone('Europe/London')
|
|
|
|
.strftime('%A, %B %1d, %Y, %1I:%M:%S %p')
|
|
|
|
end
|
2020-07-14 10:39:17 +00:00
|
|
|
|
|
|
|
def timestamp_forward
|
|
|
|
expected
|
|
|
|
.created_at
|
|
|
|
.in_time_zone('Europe/London')
|
|
|
|
.strftime('%m/%d/%Y %H:%M')
|
|
|
|
end
|
2020-04-27 21:53:06 +00:00
|
|
|
end
|
|
|
|
end
|