- Refactoring: Ticket create capybara system test is not idiomatic.
- DX: Extract Ticket create view template selection into dedicated common action capybara helper.
This commit is contained in:
parent
215cfb7990
commit
7ebd7a731d
3 changed files with 49 additions and 22 deletions
|
@ -4,5 +4,27 @@ FactoryBot.define do
|
|||
options { {} }
|
||||
updated_by_id { 1 }
|
||||
created_by_id { 1 }
|
||||
|
||||
transient do
|
||||
title { 'Title dummy.' }
|
||||
body { 'Content dummy.' }
|
||||
sender_type { 'email-out' }
|
||||
customer { create(:customer_user) }
|
||||
group { Group.first }
|
||||
owner { create(:agent_user) }
|
||||
end
|
||||
|
||||
trait :dummy_data do
|
||||
options do
|
||||
{
|
||||
'formSenderType' => sender_type,
|
||||
'title' => title,
|
||||
'body' => body,
|
||||
'customer_id' => customer.id,
|
||||
'group_id' => group.id,
|
||||
'owner_id' => owner.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -183,6 +183,26 @@ module CommonActions
|
|||
click '.js-openDropdownMacro'
|
||||
end
|
||||
|
||||
def use_template(template)
|
||||
wait(4).until do
|
||||
field = find('#form-template select[name="id"]')
|
||||
option = field.find(:option, template.name)
|
||||
option.select_option
|
||||
click '.sidebar-content .js-apply'
|
||||
|
||||
# this is a workaround for a race condition where
|
||||
# the template selection get's re-rendered after
|
||||
# a selection was made. The selection is lost and
|
||||
# the apply click has no effect.
|
||||
template.options.any? do |attribute, value|
|
||||
selector = %([name="#{attribute}"])
|
||||
next if !page.has_css?(selector, wait: 0)
|
||||
|
||||
find(selector, wait: 0, visible: false).value == value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Checks if modal is ready
|
||||
#
|
||||
# @param timeout [Integer] seconds to wait
|
||||
|
|
|
@ -4,31 +4,16 @@ require 'system/examples/text_modules_examples'
|
|||
|
||||
RSpec.describe 'Ticket Create', type: :system do
|
||||
context 'when applying ticket templates' do
|
||||
let(:agent) { create(:agent_user, groups: [permitted_group]) }
|
||||
let(:permitted_group) { create(:group) }
|
||||
let(:unpermitted_group) { create(:group) }
|
||||
let!(:template) { create(:template, :dummy_data, group: unpermitted_group, owner: agent) }
|
||||
|
||||
# Regression test for issue #2424 - Unavailable ticket template attributes get applied
|
||||
it 'unavailable attributes do not get applied', authenticated: false do
|
||||
user = create(:agent_user, password: 'test')
|
||||
permitted_group = create(:group)
|
||||
unpermitted_group = create(:group)
|
||||
|
||||
user.group_names_access_map = {
|
||||
permitted_group.name => 'full',
|
||||
}
|
||||
|
||||
template = create :template, options: {
|
||||
'title' => 'Template Title',
|
||||
'group_id' => unpermitted_group.id,
|
||||
'owner_id' => '2',
|
||||
}
|
||||
|
||||
login(
|
||||
username: user.email,
|
||||
password: 'test',
|
||||
)
|
||||
it 'unavailable attributes do not get applied', authenticated: -> { agent } do
|
||||
visit 'ticket/create'
|
||||
|
||||
# apply the ticket template and confirm that the group_id dropdown does not appear
|
||||
find('#form-template select[name="id"]').find(:option, template.name).select_option
|
||||
click '.sidebar-content .js-apply'
|
||||
use_template(template)
|
||||
expect(page).not_to have_selector 'select[name="group_id"]'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue