email_spec.rb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Channels > Email', type: :system do
  4. context 'when managing email channels', required_envs: %w[MAILBOX_INIT] do
  5. before do
  6. visit '/#channels/email'
  7. end
  8. context 'when looking at the default screen' do
  9. it 'has correct default settings' do
  10. within :active_content do
  11. # check if postmaster filters are shown
  12. click 'a[href="#c-filter"]'
  13. expect(find('#c-filter .overview')).to have_text 'NO ENTRIES'
  14. # check if signatures are shown
  15. click 'a[href="#c-signature"]'
  16. expect(find('#c-signature .overview')).to have_text 'default'
  17. end
  18. end
  19. end
  20. context 'when creating new channels' do
  21. let(:mailbox_user) { ENV['MAILBOX_INIT'].split(':')[0] }
  22. let(:mailbox_password) { ENV['MAILBOX_INIT'].split(':')[1] }
  23. before do
  24. # Make sure the channel is loaded
  25. 'Channel::Driver::Imap'.constantize
  26. # The normal timeout may be too low in slow CI environments.
  27. stub_const 'Channel::Driver::Imap::CHECK_ONLY_TIMEOUT', 1.minute
  28. end
  29. it 'refuses wrong credentials' do
  30. click 'a[href="#c-account"]'
  31. click '.js-channelNew'
  32. in_modal do
  33. fill_in 'realname', with: 'My System'
  34. fill_in 'email', with: "unknown_user.#{mailbox_user}"
  35. fill_in 'password', with: mailbox_password
  36. select 'Users', from: 'group_id'
  37. click '.js-submit'
  38. expect(page).to have_text('The server settings could not be automatically detected. Please configure them manually.')
  39. end
  40. end
  41. it 'accepts correct credentials' do
  42. click 'a[href="#c-account"]'
  43. click '.js-channelNew'
  44. in_modal timeout: 2.minutes do
  45. fill_in 'realname', with: 'My System'
  46. fill_in 'email', with: mailbox_user
  47. fill_in 'password', with: mailbox_password
  48. select 'Users', from: 'group_id'
  49. click '.js-submit'
  50. end
  51. within :active_content do
  52. expect(page).to have_text(mailbox_user)
  53. all('.js-editInbound').last.click
  54. fill_in 'options::folder', with: 'nonexisting_folder'
  55. click '.js-submit'
  56. expect(page).to have_text("Mailbox doesn\'t exist")
  57. end
  58. end
  59. end
  60. context 'when managing filters' do
  61. let(:filter_name) { "Test Filter #{SecureRandom.uuid}" }
  62. it 'works as expected' do
  63. click 'a[href="#c-filter"]'
  64. click '.content.active a[data-type="new"]'
  65. in_modal do
  66. fill_in 'name', with: filter_name
  67. fill_in 'match::from::value', with: 'target'
  68. click '.js-submit'
  69. end
  70. expect(page).to have_text(filter_name)
  71. click '.content.active .table .dropdown .btn--table'
  72. click '.content.active .table .dropdown .js-clone'
  73. in_modal do
  74. click '.js-submit'
  75. end
  76. expect(page).to have_text("Clone: #{filter_name}")
  77. end
  78. end
  79. end
  80. context 'non editable' do
  81. it 'hides "Edit" links' do
  82. # ensure that the only existing email channel
  83. # has preferences == { editable: false }
  84. Channel.destroy_all
  85. create(:email_channel, preferences: { editable: false })
  86. visit '/#channels/email'
  87. # verify page has loaded
  88. expect(page).to have_css('#c-account h3', text: 'Inbound')
  89. expect(page).to have_css('#c-account h3', text: 'Outbound')
  90. expect(page).to have_no_css('.js-editInbound, .js-editOutbound', text: 'Edit')
  91. end
  92. end
  93. context 'when adding an email' do
  94. before do
  95. visit '#channels/email'
  96. end
  97. it 'one can switch between default and expert forms' do
  98. click '.js-channelNew'
  99. in_modal do
  100. click '.js-expert'
  101. expect(page).to have_text 'ORGANIZATION & DEPARTMENT NAME'
  102. expect(page).to have_text 'SSL/STARTTLS'
  103. expect(page).to have_text 'PORT'
  104. click '.js-close'
  105. end
  106. end
  107. it 'in the expert form, the port for SSL/NoSSL is set automatically only when it is default' do
  108. click '.js-channelNew'
  109. in_modal do
  110. click '.js-expert'
  111. expect(find('input[name="options::port"]').value).to eq('993')
  112. field = find('select[name="options::ssl"]')
  113. option_yes = field.find(:option, 'SSL')
  114. option_no = field.find(:option, 'No SSL')
  115. option_no.select_option
  116. expect(find('input[name="options::port"]').value).to eq('143')
  117. option_yes.select_option
  118. expect(find('input[name="options::port"]').value).to eq('993')
  119. option_no.select_option
  120. expect(find('input[name="options::port"]').value).to eq('143')
  121. port = '4242'
  122. fill_in 'options::port', with: port
  123. field.click
  124. expect(find('input[name="options::port"]').value).to eq(port)
  125. fill_in 'options::folder', with: 'testabc'
  126. expect(find('input[name="options::port"]').value).to eq(port)
  127. click '.js-close'
  128. end
  129. end
  130. it 'entered values on the default form are copied to the expert form' do
  131. click '.js-channelNew'
  132. in_modal do
  133. name = 'Area53'
  134. email = 'dont@ask.com'
  135. password = 'f34therRa!nSplash'
  136. fill_in 'realname', with: name
  137. fill_in 'email', with: email
  138. fill_in 'password', with: password
  139. click '.js-expert'
  140. expect(find('input[name="options::realname"]').value).to eq(name)
  141. expect(find('input[name="options::email"]').value).to eq(email)
  142. expect(find('input[name="options::user"]').value).to eq(email)
  143. expect(find('input[name="options::password"]').value).to eq(password)
  144. click '.js-close'
  145. end
  146. end
  147. end
  148. context 'when editing inbound email settings' do
  149. it 'the expert form fields are not shown' do
  150. visit '#channels/email'
  151. click '.js-channelEnable'
  152. click '.js-editInbound'
  153. in_modal do
  154. expect(page).to have_no_text 'ORGANIZATION & DEPARTMENT NAME'
  155. expect(page).to have_no_text 'ORGANIZATION SUPPORT'
  156. expect(page).to have_no_text 'EMAIL'
  157. end
  158. end
  159. end
  160. end