Merge pull request #8979 from jibees/6300-dont-submit-form-element-that-are-not-handled-by-backend

shipping fees on admin: avoid backend error when updating calculator type
This commit is contained in:
Filipe
2022-04-20 12:23:32 +01:00
committed by GitHub
5 changed files with 60 additions and 34 deletions

View File

@@ -9,9 +9,9 @@ angular.module("admin.enterpriseFees").directive 'spreeEnsureCalculatorPreferenc
settings = element.parent().parent().find('div.calculator-settings')
if value == orig_calculator_type
settings.show()
settings.find('input').prop 'disabled', false
settings.find('input, select').prop 'disabled', false
else
settings.hide()
settings.find('input').prop 'disabled', true
settings.find('input, select').prop 'disabled', true
return
return

View File

@@ -7,11 +7,11 @@ $(function() {
if (calculator_select.val() === original_calc_type) {
$('div.calculator-settings').show();
$('.calculator-settings-warning').hide();
$('.calculator-settings').find('input,textarea').prop("disabled", false);
$('.calculator-settings').find('input,textarea,select').prop("disabled", false);
} else {
$('div.calculator-settings').hide();
$('.calculator-settings-warning').show();
$('.calculator-settings').find('input,textarea').prop("disabled", true);
$('.calculator-settings').find('input,textarea,select').prop("disabled", true);
}
});
})

View File

@@ -4212,6 +4212,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
spree/payment:
one: Payment
other: Payments
unit: unit
per_unit: per unit
datetime:
distance_in_words:
about_x_hours:

View File

@@ -58,42 +58,54 @@ describe '
expect(page).to have_selector "#sets_enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
end
it "editing an enterprise fee" do
context "editing an enterprise fee" do
# Given an enterprise fee
fee = create(:enterprise_fee)
enterprise = create(:enterprise, name: 'Foo')
let!(:fee) { create(:enterprise_fee) }
let!(:enterprise) { create(:enterprise, name: 'Foo') }
# When I go to the enterprise fees page
login_as_admin_and_visit admin_enterprise_fees_path
before do
# When I go to the enterprise fees page
login_as_admin_and_visit admin_enterprise_fees_path
# And I update the fields for the enterprise fee and click update
select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
select 'Inherit From Product', from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
end
# And I update the fields for the enterprise fee and click update
select 'Foo', from: 'sets_enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'sets_enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'sets_enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
select 'Inherit From Product',
from: 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id'
select 'Flat Percent', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
it "handle the default cases" do
# Then I should see the updated fields for my fee
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id",
selected: 'Foo'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type",
selected: 'Admin fee'
expect(page).to have_selector "input[value='Greetings!']"
expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id',
selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
# Then I should see the updated fields for my fee
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_enterprise_id",
selected: 'Foo'
expect(page).to have_select "sets_enterprise_fee_set_collection_attributes_0_fee_type",
selected: 'Admin fee'
expect(page).to have_selector "input[value='Greetings!']"
expect(page).to have_select 'sets_enterprise_fee_set_collection_attributes_0_tax_category_id',
selected: 'Inherit From Product'
expect(page).to have_selector "option[selected]", text: 'Flat Percent (per item)'
fee.reload
expect(fee.enterprise).to eq(enterprise)
expect(fee.name).to eq('Greetings!')
expect(fee.fee_type).to eq('admin')
expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem")
fee.reload
expect(fee.enterprise).to eq(enterprise)
expect(fee.name).to eq('Greetings!')
expect(fee.fee_type).to eq('admin')
expect(fee.calculator_type).to eq("Calculator::FlatPercentPerItem")
# Sets tax_category and inherits_tax_category
expect(fee.tax_category).to eq(nil)
expect(fee.inherits_tax_category).to eq(true)
end
# Sets tax_category and inherits_tax_category
expect(fee.tax_category).to eq(nil)
expect(fee.inherits_tax_category).to eq(true)
it "handle when updating calculator type for Weight to Flat Rate" do
select 'Weight (per kg or lb)', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
select 'Flat Rate (per item)', from: 'sets_enterprise_fee_set_collection_attributes_0_calculator_type'
click_button 'Update'
expect(fee.reload.calculator_type).to eq("Calculator::PerItem")
end
end
it "deleting an enterprise fee" do

View File

@@ -71,6 +71,18 @@ describe 'shipping methods' do
expect(page).to have_field "shipping_method_distributor_ids_#{distributor2.id}",
checked: false
end
it "handle when updating calculator type for Weight to Flat Rate" do
visit spree.edit_admin_shipping_method_path(@shipping_method)
select2_select 'Weight (per kg or lb)', from: 'calc_type'
click_button 'Update'
select2_select 'Flat Rate (per item)', from: 'calc_type'
click_button 'Update'
expect(@shipping_method.reload.calculator_type).to eq("Calculator::PerItem")
end
end
context "as an enterprise user", js: true do