Refactoring: Applied factory best practices (only required attributes and values, proc based attribute assignment, sequence attribute).
This commit is contained in:
parent
d36c88d441
commit
ace7cea315
3 changed files with 124 additions and 21 deletions
|
@ -807,6 +807,9 @@ class App.TicketZoom extends App.Controller
|
||||||
# stop autosave
|
# stop autosave
|
||||||
@autosaveStop()
|
@autosaveStop()
|
||||||
|
|
||||||
|
# no form validation if macro is performed
|
||||||
|
if !macro.perform
|
||||||
|
|
||||||
# validate ticket form using HTML5 validity check
|
# validate ticket form using HTML5 validity check
|
||||||
element = @$('.edit').parent().get(0)
|
element = @$('.edit').parent().get(0)
|
||||||
if element && element.reportValidity && !element.reportValidity()
|
if element && element.reportValidity && !element.reportValidity()
|
||||||
|
|
13
spec/factories/macro.rb
Normal file
13
spec/factories/macro.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
FactoryBot.define do
|
||||||
|
factory :macro do
|
||||||
|
sequence(:name) { |n| "Macro #{n}" }
|
||||||
|
perform do
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
ux_flow_next_up { 'next_task' }
|
||||||
|
note { '' }
|
||||||
|
active { true }
|
||||||
|
created_by_id { 1 }
|
||||||
|
updated_by_id { 1 }
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,17 +9,98 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
scenario 'frontend checks reject the update', db_strategy: :reset do
|
scenario 'frontend checks reject the update', db_strategy: :reset do
|
||||||
# setup and migrate a required select attribute
|
# setup and migrate a required select attribute
|
||||||
attribute = create_attribute :object_manager_attribute_select,
|
attribute = create_attribute :object_manager_attribute_select,
|
||||||
screens: attributes_for(:required_screen)
|
screens: attributes_for(:required_screen),
|
||||||
|
data_option: {
|
||||||
|
options: {
|
||||||
|
'name 1': 'name 1',
|
||||||
|
'name 2': 'name 2',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
null: false,
|
||||||
|
relation: '',
|
||||||
|
maxlength: 255,
|
||||||
|
nulloption: true,
|
||||||
|
}
|
||||||
|
|
||||||
# create a new ticket and attempt to update its state without the required select attribute
|
# create a new ticket and attempt to update its state without the required select attribute
|
||||||
ticket = create :ticket, group: group
|
ticket = create :ticket, group: group
|
||||||
visit "#ticket/zoom/#{ticket.id}"
|
visit "#ticket/zoom/#{ticket.id}"
|
||||||
|
within(:active_content) do
|
||||||
|
expect(page).to have_css('.js-objectNumber', wait: 2)
|
||||||
|
|
||||||
select 'closed', from: 'state_id'
|
select 'closed', from: 'state_id'
|
||||||
click('.content.active .js-attributeBar .js-submit')
|
click('.js-attributeBar .js-submit')
|
||||||
expect(page).to have_css('.content.active')
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
|
end
|
||||||
|
|
||||||
# the update should have failed and thus the ticket is still in the new state
|
# the update should have failed and thus the ticket is still in the new state
|
||||||
expect(ticket.reload.state.name).to eq('new')
|
expect(ticket.reload.state.name).to eq('new')
|
||||||
|
|
||||||
|
within(:active_content) do
|
||||||
|
# update should work now
|
||||||
|
find('.edit [name=internal_name1]').select('name 2')
|
||||||
|
click('.js-attributeBar .js-submit')
|
||||||
|
expect(page).to have_no_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
ticket.reload
|
||||||
|
expect(ticket[attribute.name]).to eq('name 2')
|
||||||
|
expect(ticket.state.name).to eq('closed')
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'with macro and required tree_select field', db_strategy: :reset do
|
||||||
|
# setup and migrate a required select attribute
|
||||||
|
attribute = create_attribute :object_manager_attribute_tree_select,
|
||||||
|
screens: attributes_for(:required_screen),
|
||||||
|
data_option: {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'name 1',
|
||||||
|
value: 'name 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'name 2',
|
||||||
|
value: 'name 2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: '',
|
||||||
|
null: false,
|
||||||
|
relation: '',
|
||||||
|
maxlength: 255,
|
||||||
|
nulloption: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
attribute_value = 'name 2'
|
||||||
|
state = Ticket::State.by_category(:closed).first
|
||||||
|
macro = create(:macro,
|
||||||
|
perform: {
|
||||||
|
'ticket.state_id' => {
|
||||||
|
value: state.id,
|
||||||
|
},
|
||||||
|
"ticket.#{attribute.name}" => {
|
||||||
|
value: attribute_value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
# refresh browser to get macro accessable
|
||||||
|
page.driver.browser.navigate.refresh
|
||||||
|
|
||||||
|
# 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}"
|
||||||
|
|
||||||
|
within(:active_content) do
|
||||||
|
expect(page).to have_css('.js-objectNumber', wait: 2)
|
||||||
|
|
||||||
|
click('.js-openDropdownMacro')
|
||||||
|
click(".js-dropdownActionMacro[data-id=\"#{macro.id}\"]")
|
||||||
|
expect(page).not_to have_css('.js-submitDropdown .js-submit[disabled]', wait: 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
# the update should not have failed and thus the ticket is in closed state
|
||||||
|
ticket.reload
|
||||||
|
expect(ticket[attribute.name]).to eq(attribute_value)
|
||||||
|
expect(ticket.state.name).to eq(state.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -32,20 +113,26 @@ RSpec.describe 'Ticket Update', type: :system do
|
||||||
origin_ticket.merge_to(ticket_id: target_ticket.id, user_id: user.id)
|
origin_ticket.merge_to(ticket_id: target_ticket.id, user_id: user.id)
|
||||||
|
|
||||||
visit "#ticket/zoom/#{origin_ticket.id}"
|
visit "#ticket/zoom/#{origin_ticket.id}"
|
||||||
click '.content.active .js-actions .dropdown-toggle'
|
within(:active_content) do
|
||||||
click '.content.active .js-actions .dropdown-menu [data-type="ticket-history"]'
|
expect(page).to have_css('.js-actions .dropdown-toggle', wait: 3)
|
||||||
|
click '.js-actions .dropdown-toggle'
|
||||||
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
||||||
|
|
||||||
modal = find('.content.active .modal')
|
expect(page).to have_css('.modal', wait: 3)
|
||||||
|
modal = find('.modal')
|
||||||
expect(modal).to have_content "This ticket was merged into ticket ##{target_ticket.number}"
|
expect(modal).to have_content "This ticket was merged into ticket ##{target_ticket.number}"
|
||||||
expect(modal).to have_link "##{target_ticket.number}", href: "#ticket/zoom/#{target_ticket.id}"
|
expect(modal).to have_link "##{target_ticket.number}", href: "#ticket/zoom/#{target_ticket.id}"
|
||||||
|
|
||||||
visit "#ticket/zoom/#{target_ticket.id}"
|
visit "#ticket/zoom/#{target_ticket.id}"
|
||||||
click '.content.active .js-actions .dropdown-toggle'
|
expect(page).to have_css('.js-actions .dropdown-toggle', wait: 3)
|
||||||
click '.content.active .js-actions .dropdown-menu [data-type="ticket-history"]'
|
click '.js-actions .dropdown-toggle'
|
||||||
|
click '.js-actions .dropdown-menu [data-type="ticket-history"]'
|
||||||
|
|
||||||
modal = find('.content.active .modal')
|
expect(page).to have_css('.modal', wait: 3)
|
||||||
|
modal = find('.modal')
|
||||||
expect(modal).to have_content("Ticket ##{origin_ticket.number} was merged into this ticket")
|
expect(modal).to have_content("Ticket ##{origin_ticket.number} was merged into this ticket")
|
||||||
expect(modal).to have_link "##{origin_ticket.number}", href: "#ticket/zoom/#{origin_ticket.id}"
|
expect(modal).to have_link "##{origin_ticket.number}", href: "#ticket/zoom/#{origin_ticket.id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue