Fixed #2242, required attribute not being enforeced, for the frontend only.
This commit is contained in:
parent
8e52cb52a8
commit
f7a59c6bbd
4 changed files with 109 additions and 1 deletions
|
@ -807,7 +807,13 @@ class App.TicketZoom extends App.Controller
|
||||||
# stop autosave
|
# stop autosave
|
||||||
@autosaveStop()
|
@autosaveStop()
|
||||||
|
|
||||||
# validate ticket
|
# validate ticket form using HTML5 validity check
|
||||||
|
if !@$('.edit').parent().get(0).reportValidity()
|
||||||
|
@submitEnable(e)
|
||||||
|
@autosaveStart()
|
||||||
|
return
|
||||||
|
|
||||||
|
# validate ticket by model
|
||||||
errors = ticket.validate(
|
errors = ticket.validate(
|
||||||
screen: 'edit'
|
screen: 'edit'
|
||||||
)
|
)
|
||||||
|
|
|
@ -220,4 +220,52 @@ FactoryBot.define do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :required_screen, class: Hash do
|
||||||
|
create_middle do
|
||||||
|
{
|
||||||
|
'ticket.customer' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
item_class: 'column'
|
||||||
|
},
|
||||||
|
'ticket.agent' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
item_class: 'column'
|
||||||
|
},
|
||||||
|
'admin.organization' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
'admin.group' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
item_class: 'column'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
edit do
|
||||||
|
{
|
||||||
|
'ticket.customer' => {
|
||||||
|
shown: true,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
'ticket.agent' => {
|
||||||
|
shown: true,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
'admin.organization' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
'admin.group' => {
|
||||||
|
shown: true,
|
||||||
|
required: true,
|
||||||
|
item_class: 'column'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -125,6 +125,35 @@ module CommonActions
|
||||||
def expect_current_route(route, **options)
|
def expect_current_route(route, **options)
|
||||||
expect(page).to have_current_route(route, **options)
|
expect(page).to have_current_route(route, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Create and migrate an object manager attribute and verify that it exists. Returns the newly attribute.
|
||||||
|
#
|
||||||
|
# Create a select attribute:
|
||||||
|
# @example
|
||||||
|
# attribute = setup_attribute :object_manager_attribute_select
|
||||||
|
#
|
||||||
|
# Create a required text attribute:
|
||||||
|
# @example
|
||||||
|
# attribute = setup_attribute :object_manager_attribute_text,
|
||||||
|
# screens: attributes_for(:required_screen)
|
||||||
|
#
|
||||||
|
# Create a date attribute with custom parameters:
|
||||||
|
# @example
|
||||||
|
# attribute = setup_attribute :object_manager_attribute_date,
|
||||||
|
# data_option: {
|
||||||
|
# 'future' => true,
|
||||||
|
# 'past' => false,
|
||||||
|
# 'diff' => 24,
|
||||||
|
# 'null' => true,
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# return [attribute]
|
||||||
|
def create_attribute(attribute_name, attribute_parameters = {})
|
||||||
|
attribute = create(attribute_name, attribute_parameters)
|
||||||
|
ObjectManager::Attribute.migration_execute
|
||||||
|
page.driver.browser.navigate.refresh
|
||||||
|
attribute
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|
25
spec/system/ticket/update_spec.rb
Normal file
25
spec/system/ticket/update_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Ticket Create', type: :system do
|
||||||
|
|
||||||
|
let(:group) { Group.find_by(name: 'Users') }
|
||||||
|
|
||||||
|
# Regression test for issue #2242 - mandatory fields can be empty (or "-") on ticket update
|
||||||
|
context 'when updating a ticket without its required select attributes' do
|
||||||
|
scenario 'frontend checks reject the update', db_strategy: :reset do
|
||||||
|
# setup and migrate a required select attribute
|
||||||
|
attribute = create_attribute :object_manager_attribute_select,
|
||||||
|
screens: attributes_for(:required_screen)
|
||||||
|
|
||||||
|
# create a new ticket and attempt to update its state without the required select attribute
|
||||||
|
ticket = create :ticket, group: group
|
||||||
|
visit "#ticket/zoom/#{ticket.id}"
|
||||||
|
select 'closed', from: 'state_id'
|
||||||
|
click('.content.active .js-attributeBar .js-submit')
|
||||||
|
expect(page).to have_css('.content.active')
|
||||||
|
|
||||||
|
# the update should have failed and thus the ticket is still in the new state
|
||||||
|
expect(ticket.reload.state.name).to eq('new')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue