2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-09-02 13:28:39 +00:00
|
|
|
RSpec.shared_examples 'text modules' do |path:|
|
2021-07-02 06:25:39 +00:00
|
|
|
let!(:agent_fixed_name) { create :agent, firstname: 'FFFF1', lastname: 'GGGG1', groups: [Group.find_by(name: 'Users')] }
|
2019-07-03 16:14:28 +00:00
|
|
|
let!(:group1) { create :group }
|
|
|
|
let!(:group2) { create :group }
|
|
|
|
let!(:text_module_without_group) { create :text_module }
|
|
|
|
let!(:text_module_group1) { create :text_module, groups: [group1] }
|
|
|
|
let!(:text_module_group2) { create :text_module, groups: [group2] }
|
|
|
|
|
2019-09-02 13:28:39 +00:00
|
|
|
it 'shows when send ::' do
|
2020-02-20 13:34:03 +00:00
|
|
|
refresh # workaround to get new created objects from db
|
2019-09-02 13:28:39 +00:00
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find('select[name="group_id"]').select(1)
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
expect(page).to have_selector(:text_module, text_module_without_group.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-23 21:44:18 +00:00
|
|
|
it 'does not break after usage of Ctrl/Command+Backspace' do
|
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
find(:richtext).send_keys('bur')
|
|
|
|
|
|
|
|
# The click is needed to get the focus back to the field for chrome.
|
|
|
|
find(:richtext).click
|
|
|
|
if OS.mac?
|
|
|
|
find(:richtext).send_keys(%i[command backspace])
|
|
|
|
else
|
|
|
|
find(:richtext).send_keys(%i[control backspace])
|
|
|
|
end
|
|
|
|
|
|
|
|
find(:richtext).send_keys('Some other text')
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
expect(find(:richtext)).to have_text 'Some other text'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-02 13:28:39 +00:00
|
|
|
it 'does not show when send :enter:' do
|
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find('select[name="group_id"]').select(1)
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
find(:richtext).send_keys(':')
|
|
|
|
expect(page).to have_no_selector(:text_module, text_module_without_group.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-29 14:19:09 +00:00
|
|
|
it 'does not break search on backspace' do
|
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find('select[name="group_id"]').select(1)
|
|
|
|
find(:richtext).send_keys('@@agen')
|
|
|
|
find(:richtext).send_keys(:backspace)
|
|
|
|
expect(page).to have_no_text('No results found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-02 06:25:39 +00:00
|
|
|
it 'does delete empty mentions (issue #3636 / FF only)' do
|
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find('select[name="group_id"]').select('Users')
|
|
|
|
find(:richtext).send_keys('@@FFFF1')
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
(agent_fixed_name.firstname.length + agent_fixed_name.lastname.length + 2).times do
|
|
|
|
find(:richtext).send_keys(:backspace)
|
|
|
|
end
|
|
|
|
expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does delete empty mentions (issue #3636 / simulation)' do
|
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
|
|
|
find('select[name="group_id"]').select('Users')
|
|
|
|
find(:richtext).send_keys('@@FFFF1')
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
find(:richtext).send_keys(:enter)
|
|
|
|
find(:richtext).send_keys('test')
|
|
|
|
page.execute_script("$('a[data-mention-user-id]').first().html('<br>')")
|
|
|
|
find(:richtext).send_keys(:backspace)
|
|
|
|
expect(find(:richtext).all('a[data-mention-user-id]', visible: :all).count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-03 16:14:28 +00:00
|
|
|
it 'supports group-dependent text modules' do
|
|
|
|
|
|
|
|
# give user access to all groups including those created
|
|
|
|
# by using FactoryBot outside of the example
|
2021-06-23 11:35:27 +00:00
|
|
|
group_names_access_map = Group.all.pluck(:name).index_with do |_group_name|
|
|
|
|
'full'.freeze
|
2019-07-03 16:14:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
current_user do |user|
|
|
|
|
user.group_names_access_map = group_names_access_map
|
|
|
|
user.save!
|
|
|
|
end
|
|
|
|
|
2020-02-20 13:34:03 +00:00
|
|
|
refresh # workaround to get changed settings from db
|
2019-07-03 16:14:28 +00:00
|
|
|
visit path
|
|
|
|
within(:active_content) do
|
2019-08-07 12:55:54 +00:00
|
|
|
find('select[name="group_id"]').select(group1.name)
|
2019-07-03 16:14:28 +00:00
|
|
|
find(:richtext).send_keys('::')
|
|
|
|
|
2019-08-07 12:55:54 +00:00
|
|
|
expect(page).to have_selector(:text_module, text_module_without_group.id)
|
|
|
|
expect(page).to have_selector(:text_module, text_module_group1.id)
|
|
|
|
expect(page).to have_no_selector(:text_module, text_module_group2.id)
|
2019-07-03 16:14:28 +00:00
|
|
|
|
2019-08-07 12:55:54 +00:00
|
|
|
find('select[name="group_id"]').select(group2.name)
|
2019-07-03 16:14:28 +00:00
|
|
|
find(:richtext).send_keys('::')
|
|
|
|
|
2019-08-07 12:55:54 +00:00
|
|
|
expect(page).to have_selector(:text_module, text_module_without_group.id)
|
|
|
|
expect(page).to have_no_selector(:text_module, text_module_group1.id)
|
|
|
|
expect(page).to have_selector(:text_module, text_module_group2.id)
|
2019-07-03 16:14:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|