Maintenance: Ported Manage > Channels > Email test to capybara.

This commit is contained in:
Martin Gruner 2021-10-08 08:41:05 +02:00
parent 445700d0aa
commit da22f4b1bd
4 changed files with 110 additions and 190 deletions

View file

@ -7,6 +7,8 @@ class Channel::Driver::Imap < Channel::EmailParser
FETCH_METADATA_TIMEOUT = 2.minutes FETCH_METADATA_TIMEOUT = 2.minutes
FETCH_MSG_TIMEOUT = 4.minutes FETCH_MSG_TIMEOUT = 4.minutes
EXPUNGE_TIMEOUT = 16.minutes EXPUNGE_TIMEOUT = 16.minutes
DEFAULT_TIMEOUT = 45.seconds
CHECK_ONLY_TIMEOUT = 6.seconds
def fetchable?(_channel) def fetchable?(_channel)
true true
@ -110,10 +112,7 @@ example
Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl},starttls=#{starttls},folder=#{folder},keep_on_server=#{keep_on_server},auth_type=#{options.fetch(:auth_type, 'LOGIN')})" Rails.logger.info "fetching imap (#{options[:host]}/#{options[:user]} port=#{port},ssl=#{ssl},starttls=#{starttls},folder=#{folder},keep_on_server=#{keep_on_server},auth_type=#{options.fetch(:auth_type, 'LOGIN')})"
# on check, reduce open_timeout to have faster probing # on check, reduce open_timeout to have faster probing
check_type_timeout = 45 check_type_timeout = check_type == 'check' ? CHECK_ONLY_TIMEOUT : DEFAULT_TIMEOUT
if check_type == 'check'
check_type_timeout = 6
end
timeout(check_type_timeout) do timeout(check_type_timeout) do
@imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false) @imap = ::Net::IMAP.new(options[:host], port, ssl, nil, false)

View file

@ -11,7 +11,6 @@ if [ "$LEVEL" == '1' ]; then
cp contrib/auto_wizard_test.json auto_wizard.json cp contrib/auto_wizard_test.json auto_wizard.json
cp test/integration/aaa_auto_wizard_base_setup_test.rb test/browser/aaa_auto_wizard_base_setup_test.rb cp test/integration/aaa_auto_wizard_base_setup_test.rb test/browser/aaa_auto_wizard_base_setup_test.rb
rm test/browser/abb_one_group_test.rb rm test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
rm test/browser/admin_drag_drop_to_new_group_test.rb rm test/browser/admin_drag_drop_to_new_group_test.rb
rm test/browser/admin_overview_test.rb rm test/browser/admin_overview_test.rb
rm test/browser/admin_permissions_granular_vs_full_test.rb rm test/browser/admin_permissions_granular_vs_full_test.rb
@ -68,7 +67,6 @@ elif [ "$LEVEL" == '2' ]; then
# only ticket action 2/3 # only ticket action 2/3
# test/browser/aaa_getting_started_test.rb # test/browser/aaa_getting_started_test.rb
# test/browser/abb_one_group_test.rb # test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
rm test/browser/admin_drag_drop_to_new_group_test.rb rm test/browser/admin_drag_drop_to_new_group_test.rb
rm test/browser/admin_overview_test.rb rm test/browser/admin_overview_test.rb
rm test/browser/admin_permissions_granular_vs_full_test.rb rm test/browser/admin_permissions_granular_vs_full_test.rb
@ -125,7 +123,6 @@ elif [ "$LEVEL" == '3' ]; then
# only ticket action 2/3 # only ticket action 2/3
# test/browser/aaa_getting_started_test.rb # test/browser/aaa_getting_started_test.rb
# test/browser/abb_one_group_test.rb # test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
rm test/browser/admin_drag_drop_to_new_group_test.rb rm test/browser/admin_drag_drop_to_new_group_test.rb
rm test/browser/admin_overview_test.rb rm test/browser/admin_overview_test.rb
rm test/browser/admin_permissions_granular_vs_full_test.rb rm test/browser/admin_permissions_granular_vs_full_test.rb
@ -182,7 +179,6 @@ elif [ "$LEVEL" == '4' ]; then
# only ticket action 3/3 # only ticket action 3/3
# test/browser/aaa_getting_started_test.rb # test/browser/aaa_getting_started_test.rb
# test/browser/abb_one_group_test.rb # test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
rm test/browser/admin_drag_drop_to_new_group_test.rb rm test/browser/admin_drag_drop_to_new_group_test.rb
rm test/browser/admin_overview_test.rb rm test/browser/admin_overview_test.rb
rm test/browser/admin_permissions_granular_vs_full_test.rb rm test/browser/admin_permissions_granular_vs_full_test.rb
@ -238,7 +234,6 @@ elif [ "$LEVEL" == '5' ]; then
# only profile action & admin # only profile action & admin
# test/browser/abb_one_group_test.rb # test/browser/abb_one_group_test.rb
# test/browser/admin_channel_email_test.rb
# rm test/browser/admin_drag_drop_to_new_group_test.rb # rm test/browser/admin_drag_drop_to_new_group_test.rb
# test/browser/admin_overview_test.rb # test/browser/admin_overview_test.rb
# rm test/browser/admin_permissions_granular_vs_full_test.rb # rm test/browser/admin_permissions_granular_vs_full_test.rb
@ -297,7 +292,6 @@ elif [ "$LEVEL" == '6' ]; then
cp contrib/auto_wizard_test.json auto_wizard.json cp contrib/auto_wizard_test.json auto_wizard.json
cp test/integration/aaa_auto_wizard_base_setup_test.rb test/browser/aaa_auto_wizard_base_setup_test.rb cp test/integration/aaa_auto_wizard_base_setup_test.rb test/browser/aaa_auto_wizard_base_setup_test.rb
rm test/browser/abb_one_group_test.rb rm test/browser/abb_one_group_test.rb
rm test/browser/admin_channel_email_test.rb
rm test/browser/admin_drag_drop_to_new_group_test.rb rm test/browser/admin_drag_drop_to_new_group_test.rb
rm test/browser/admin_overview_test.rb rm test/browser/admin_overview_test.rb
rm test/browser/admin_permissions_granular_vs_full_test.rb rm test/browser/admin_permissions_granular_vs_full_test.rb

View file

@ -4,6 +4,113 @@ require 'rails_helper'
RSpec.describe 'Manage > Channels > Email', type: :system do RSpec.describe 'Manage > Channels > Email', type: :system do
context 'when managing email channels', required_envs: %w[MAILBOX_INIT] do
before do
visit '/#channels/email'
end
context 'when looking at the default screen' do
it 'has correct default settings' do
within :active_content do
# check if postmaster filters are shown
click 'a[href="#c-filter"]'
expect(find('#c-filter .overview')).to have_text 'NO ENTRIES'
# check if signatures are shown
click 'a[href="#c-signature"]'
expect(find('#c-signature .overview')).to have_text 'default'
end
end
end
context 'when creating new channels' do
let(:mailbox_user) { ENV['MAILBOX_INIT'].split(':')[0] }
let(:mailbox_password) { ENV['MAILBOX_INIT'].split(':')[1] }
before do
# Make sure the channel is loaded
'Channel::Driver::Imap'.constantize
# The normal timeout may be too low in slow CI environments.
stub_const 'Channel::Driver::Imap::CHECK_ONLY_TIMEOUT', 1.minute
end
it 'refuses wrong credentials' do
click 'a[href="#c-account"]'
click '.js-channelNew'
modal_ready
within '.modal' do
fill_in 'realname', with: 'My System'
fill_in 'email', with: "unknown_user.#{mailbox_user}"
fill_in 'password', with: mailbox_password
select 'Users', from: 'group_id'
click '.js-submit'
expect(page).to have_text('Unable to detect your server settings. Manual configuration needed.')
end
end
it 'accepts correct credentials' do
click 'a[href="#c-account"]'
click '.js-channelNew'
modal_ready
within '.modal' do
fill_in 'realname', with: 'My System'
fill_in 'email', with: mailbox_user
fill_in 'password', with: mailbox_password
select 'Users', from: 'group_id'
click '.js-submit'
end
modal_disappear timeout: 2.minutes
within :active_content do
expect(page).to have_text(mailbox_user)
all('.js-editInbound').last.click
fill_in 'options::folder', with: 'nonexisting_folder'
click '.js-submit'
expect(page).to have_text("Mailbox doesn\'t exist")
end
end
end
context 'when managing filters' do
let(:filter_name) { "Test Filter #{SecureRandom.uuid}" }
it 'works as expected' do
click 'a[href="#c-filter"]'
click '.content.active a[data-type="new"]'
modal_ready
within '.modal' do
fill_in 'name', with: filter_name
fill_in 'match::from::value', with: 'target'
click '.js-submit'
end
modal_disappear
expect(page).to have_text(filter_name)
click '.content.active .table .dropdown .btn--table'
click '.content.active .table .dropdown .js-clone'
modal_ready
click '.modal .js-submit'
modal_disappear
expect(page).to have_text("Clone: #{filter_name}")
end
end
end
context 'non editable' do context 'non editable' do
it 'hides "Edit" links' do it 'hides "Edit" links' do

View file

@ -1,180 +0,0 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'browser_test_helper'
class AdminChannelEmailTest < TestCase
def test_account_add
if !ENV['MAILBOX_INIT']
# raise "Need MAILBOX_INIT as ENV variable like export MAILBOX_INIT='unittest01@znuny.com:somepass'"
puts "NOTICE: Need MAILBOX_INIT as ENV variable like export MAILBOX_INIT='unittest01@znuny.com:somepass'"
return
end
mailbox_user = ENV['MAILBOX_INIT'].split(':')[0]
mailbox_password = ENV['MAILBOX_INIT'].split(':')[1]
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all
click(css: 'a[href="#manage"]')
click(css: '.content.active a[href="#channels/email"]')
# check if postmaster filter are shown
click(css: '.content.active a[href="#c-filter"]')
match(
css: '.content.active #c-filter .overview',
value: 'No Entries',
)
# check if signatures are shown
click(css: '.content.active a[href="#c-signature"]')
match(
css: '.content.active #c-signature .overview',
value: 'default',
)
click(css: '.content.active a[href="#c-account"]')
click(css: '.content.active .js-channelNew')
modal_ready
set(
css: '.modal input[name="realname"]',
value: 'My System',
)
set(
css: '.modal input[name="email"]',
value: mailbox_user,
)
set(
css: '.modal input[name="password"]',
value: mailbox_password,
)
select(
css: '.modal select[name="group_id"]',
value: 'Users',
)
click(css: '.modal button.js-submit')
sleep 4
watch_for(
css: '.modal',
value: '(already exists|unknown mailbox)',
)
click(css: '.modal .js-close')
# delete all channels
loop do
break if !@browser.find_elements(css: '.content.active .js-channelDelete')[0]
click(css: '.content.active .js-channelDelete')
sleep 2
# flanky
click(css: '.modal .js-submit')
sleep 2
end
# re-create
click(css: '.content.active .js-channelNew')
modal_ready
set(
css: '.modal input[name="realname"]',
value: 'My System',
)
set(
css: '.modal input[name="email"]',
value: mailbox_user,
)
set(
css: '.modal input[name="password"]',
value: mailbox_password,
)
select(
css: '.modal select[name="group_id"]',
value: 'Users',
)
click(css: '.modal button.js-submit')
modal_disappear(timeout: 20)
watch_for(
css: '.content.active',
value: mailbox_user,
)
# set invalid folder
click(css: '.content.active .js-editInbound')
modal_ready
set(
css: '.modal input[name="options::folder"]',
value: 'not_existing_folder',
)
click(css: '.modal .js-inbound button.js-submit')
watch_for(
css: '.modal',
value: 'Mailbox doesn\'t exist',
)
end
# test the creation and cloning of Postmaster filters
# confirm fix for issue #2170 - Cannot clone PostmasterFilter
def test_filter_clone
filter_name = "Test Filter #{SecureRandom.uuid}"
@browser = browser_instance
login(
username: 'admin@example.com',
password: 'test',
url: browser_url,
)
tasks_close_all
click(css: 'a[href="#manage"]')
click(css: '.content.active a[href="#channels/email"]')
click(css: '.content.active a[href="#c-filter"]')
# create a new email filter
click(css: '.content.active a[data-type="new"]')
modal_ready
set(
css: '.modal input[name="name"]',
value: filter_name,
)
set(
css: '.modal input[name="match::from::value"]',
value: 'target',
)
click(css: '.modal .js-submit')
modal_disappear
watch_for(
css: '.content.active .table',
value: filter_name,
)
# now clone filter that we just created
click(css: '.content.active .table .dropdown .btn--table')
click(css: '.content.active .table .dropdown .js-clone')
modal_ready
click(css: '.modal .js-submit')
modal_disappear
# confirm the clone exists in the table
watch_for(
css: '.content.active .table',
value: "Clone: #{filter_name}",
)
end
end