email_reply_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket > Update > Email Reply', current_user_id: -> { current_user.id }, time_zone: 'Europe/London', type: :system do
  4. let(:group) { Group.find_by(name: 'Users') }
  5. let(:ticket) { create(:ticket, group: group) }
  6. let(:ticket_article) { create(:ticket_article, ticket: ticket, from: 'Example Name <asdf1@example.com>') }
  7. let(:customer) { create(:customer) }
  8. let(:current_user) { customer }
  9. before do
  10. visit "ticket/zoom/#{ticket_article.ticket.id}"
  11. end
  12. context 'when TO field is being edited' do
  13. it 'shows error dialog when updated value is an invalid email' do
  14. within(:active_content) do
  15. click_email_reply
  16. find('.token').double_click
  17. find('.js-to', visible: false).sibling('.token-input').set('test')
  18. find('.js-textarea').set('welcome to the community')
  19. find('.js-submitDropdown button.js-submit').click
  20. expect(page).to have_text 'Please provide a recipient in "TO" or "CC".'
  21. end
  22. end
  23. it 'updates article when updated value is a valid email' do
  24. within(:active_content) do
  25. click_email_reply
  26. find('.token').double_click
  27. find('.js-to', visible: false).sibling('.token-input').set('user@test.com')
  28. find('.js-textarea').set('welcome to the community')
  29. find('.js-submitDropdown button.js-submit').click
  30. expect(page).to have_text 'welcome to the community'
  31. end
  32. end
  33. end
  34. context 'when a new recipient is added in email reply' do
  35. it 'shows both name and email in token' do
  36. click_email_reply
  37. find('.js-to', visible: false).sibling('.token-input').set(customer.email)
  38. find('ul.ui-autocomplete li:first-child', visible: false).click
  39. within all('.token-label')[1] do
  40. expect(page).to have_text("#{customer.firstname} #{customer.lastname} <#{customer.email}>")
  41. end
  42. end
  43. end
  44. def click_email_reply
  45. click '.js-ArticleAction[data-type=emailReply]'
  46. end
  47. end