From a6c69c8530355a134f86810340713de6a413f0a9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 9 Mar 2022 11:16:19 +0100 Subject: [PATCH 1/4] Ensure that form element are well disabled to not submit them As they're not handled by the backend --- .../ensure_calculator_preferences_match_type.js.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/enterprise_fees/directives/ensure_calculator_preferences_match_type.js.coffee b/app/assets/javascripts/admin/enterprise_fees/directives/ensure_calculator_preferences_match_type.js.coffee index 4376ce59ef..2f4d97c46e 100644 --- a/app/assets/javascripts/admin/enterprise_fees/directives/ensure_calculator_preferences_match_type.js.coffee +++ b/app/assets/javascripts/admin/enterprise_fees/directives/ensure_calculator_preferences_match_type.js.coffee @@ -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 From 6f5dd5ab0c65bf08212403de08d80624c6a9fef1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 10 Mar 2022 09:53:16 +0100 Subject: [PATCH 2/4] Prepare to receive another test in the same context --- spec/system/admin/enterprise_fees_spec.rb | 64 ++++++++++++----------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/spec/system/admin/enterprise_fees_spec.rb b/spec/system/admin/enterprise_fees_spec.rb index 680ff8eb50..90c88c7b2a 100644 --- a/spec/system/admin/enterprise_fees_spec.rb +++ b/spec/system/admin/enterprise_fees_spec.rb @@ -58,42 +58,46 @@ 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") + + # Sets tax_category and inherits_tax_category + expect(fee.tax_category).to eq(nil) + expect(fee.inherits_tax_category).to eq(true) + end - 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 it "deleting an enterprise fee" do From 4b629eae1185894b36ad6b073ec96366e8798126 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 10 Mar 2022 09:54:16 +0100 Subject: [PATCH 3/4] Test that fee can be updated from weight to Flat Rate + Missing some spree i18n keys --- config/locales/en.yml | 2 ++ spec/system/admin/enterprise_fees_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 139b2b8315..e4f53174d5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/spec/system/admin/enterprise_fees_spec.rb b/spec/system/admin/enterprise_fees_spec.rb index 90c88c7b2a..dbd9a4e2ad 100644 --- a/spec/system/admin/enterprise_fees_spec.rb +++ b/spec/system/admin/enterprise_fees_spec.rb @@ -97,7 +97,15 @@ describe ' expect(fee.inherits_tax_category).to eq(true) end + 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 From e607d5c161944d827028d162472617fec2b7f702 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 19 Apr 2022 15:16:07 +0200 Subject: [PATCH 4/4] Shipping method: disabled form element to not submit them As they're not handled by the backend --- app/assets/javascripts/admin/spree/calculator.js | 4 ++-- spec/system/admin/shipping_methods_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/spree/calculator.js b/app/assets/javascripts/admin/spree/calculator.js index c5dbe0aed0..2dcd074af4 100644 --- a/app/assets/javascripts/admin/spree/calculator.js +++ b/app/assets/javascripts/admin/spree/calculator.js @@ -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); } }); }) diff --git a/spec/system/admin/shipping_methods_spec.rb b/spec/system/admin/shipping_methods_spec.rb index 3afb2dc875..b8c7eb2e86 100644 --- a/spec/system/admin/shipping_methods_spec.rb +++ b/spec/system/admin/shipping_methods_spec.rb @@ -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