From fb8d2827d2c56cd0f125b46f79132991b5348388 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 23 Sep 2022 12:03:18 +0100 Subject: [PATCH 1/3] Adds number localization preferences test --- .../admin/configuration/general_settings_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/system/admin/configuration/general_settings_spec.rb b/spec/system/admin/configuration/general_settings_spec.rb index 8c9060cb1b..fbc952f243 100644 --- a/spec/system/admin/configuration/general_settings_spec.rb +++ b/spec/system/admin/configuration/general_settings_spec.rb @@ -39,7 +39,6 @@ describe "General Settings" do within('.currency') do find("[for='currency_symbol_position_after']").click end - click_button 'Update' expect(page).to have_content(Spree.t(:successfully_updated, @@ -47,4 +46,14 @@ describe "General Settings" do expect(page).to have_checked_field('10.00 $') end end + + context "editing number localization preferences" do + it "enables international thousand/decimal separator logic" do + find("#enable_localized_number_").set "true" + click_button 'Update' + expect(page).to have_content(Spree.t(:successfully_updated, + resource: Spree.t(:general_settings))) + expect(Spree::Config.preferred_enable_localized_number?).to eq(true) + end + end end From 6e3c0858c19091a801115aa5bd7a63beb0aa95d1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 23 Sep 2022 12:47:18 +0100 Subject: [PATCH 2/3] Adds decimal and thousands separator test --- .../configuration/general_settings_spec.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spec/system/admin/configuration/general_settings_spec.rb b/spec/system/admin/configuration/general_settings_spec.rb index fbc952f243..c6b4a6f978 100644 --- a/spec/system/admin/configuration/general_settings_spec.rb +++ b/spec/system/admin/configuration/general_settings_spec.rb @@ -45,6 +45,24 @@ describe "General Settings" do resource: Spree.t(:general_settings))) expect(page).to have_checked_field('10.00 $') end + + it "changes the currency decimal separator" do + expect(Spree::Config.preferred_currency_decimal_mark).to eq('.') + fill_in "currency_decimal_mark", with: ',' + click_button 'Update' + expect(page).to have_content(Spree.t(:successfully_updated, + resource: Spree.t(:general_settings))) + expect(Spree::Config.preferred_currency_decimal_mark).to eq(',') + end + + it "changes the currency thousands separator" do + expect(Spree::Config.preferred_currency_thousands_separator).to eq(',') + fill_in "currency_thousands_separator", with: '.' + click_button 'Update' + expect(page).to have_content(Spree.t(:successfully_updated, + resource: Spree.t(:general_settings))) + expect(Spree::Config.preferred_currency_thousands_separator).to eq('.') + end end context "editing number localization preferences" do From 7b33405530d01d44656cdedc2d650a2839f82fbc Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 23 Sep 2022 13:00:39 +0100 Subject: [PATCH 3/3] Replaces translation with actual string DRY: creates update_and_assert_message --- .../configuration/general_settings_spec.rb | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/spec/system/admin/configuration/general_settings_spec.rb b/spec/system/admin/configuration/general_settings_spec.rb index c6b4a6f978..f2125b4c27 100644 --- a/spec/system/admin/configuration/general_settings_spec.rb +++ b/spec/system/admin/configuration/general_settings_spec.rb @@ -22,12 +22,7 @@ describe "General Settings" do context "editing general settings (admin)" do it "should be able to update the site name" do fill_in "site_name", with: "OFN Demo Site99" - click_button "Update" - - within("[class='flash success']") do - expect(page).to have_content(Spree.t(:successfully_updated, - resource: Spree.t(:general_settings))) - end + update_and_assert_message expect(find("#site_name").value).to eq("OFN Demo Site99") end end @@ -39,28 +34,21 @@ describe "General Settings" do within('.currency') do find("[for='currency_symbol_position_after']").click end - click_button 'Update' - - expect(page).to have_content(Spree.t(:successfully_updated, - resource: Spree.t(:general_settings))) + update_and_assert_message expect(page).to have_checked_field('10.00 $') end it "changes the currency decimal separator" do expect(Spree::Config.preferred_currency_decimal_mark).to eq('.') fill_in "currency_decimal_mark", with: ',' - click_button 'Update' - expect(page).to have_content(Spree.t(:successfully_updated, - resource: Spree.t(:general_settings))) + update_and_assert_message expect(Spree::Config.preferred_currency_decimal_mark).to eq(',') end it "changes the currency thousands separator" do expect(Spree::Config.preferred_currency_thousands_separator).to eq(',') fill_in "currency_thousands_separator", with: '.' - click_button 'Update' - expect(page).to have_content(Spree.t(:successfully_updated, - resource: Spree.t(:general_settings))) + update_and_assert_message expect(Spree::Config.preferred_currency_thousands_separator).to eq('.') end end @@ -68,10 +56,17 @@ describe "General Settings" do context "editing number localization preferences" do it "enables international thousand/decimal separator logic" do find("#enable_localized_number_").set "true" - click_button 'Update' - expect(page).to have_content(Spree.t(:successfully_updated, - resource: Spree.t(:general_settings))) + update_and_assert_message expect(Spree::Config.preferred_enable_localized_number?).to eq(true) end end end + +private + +def update_and_assert_message + click_button 'Update' + within("[class='flash success']") do + expect(page).to have_content("General Settings has been successfully updated!") + end +end