Skip to content

Commit

Permalink
Merge pull request #8979 from jibees/6300-dont-submit-form-element-th…
Browse files Browse the repository at this point in the history
…at-are-not-handled-by-backend

shipping fees on admin: avoid backend error when updating calculator type
  • Loading branch information
filipefurtad0 authored Apr 20, 2022
2 parents 06dbb3b + e607d5c commit 1f6b5ef
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/assets/javascripts/admin/spree/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
})
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
76 changes: 44 additions & 32 deletions spec/system/admin/enterprise_fees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,54 @@
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') }

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

# When I go to the enterprise fees page
login_as_admin_and_visit admin_enterprise_fees_path
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)'

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

# 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 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'

# 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")

# Sets tax_category and inherits_tax_category
expect(fee.tax_category).to eq(nil)
expect(fee.inherits_tax_category).to eq(true)
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
Expand Down
12 changes: 12 additions & 0 deletions spec/system/admin/shipping_methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
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
Expand Down

0 comments on commit 1f6b5ef

Please sign in to comment.