From c0e820e4470cc9d16b01894a98416e24df9cfde4 Mon Sep 17 00:00:00 2001 From: isidzukuri Date: Thu, 15 Feb 2024 09:14:52 +0200 Subject: [PATCH 1/3] Improve error message by not displaying the first part of the second sentence if no changes were counted --- app/views/admin/products_v3/_table.html.haml | 8 ++++-- .../system/admin/products_v3/products_spec.rb | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index 73b89847d4..d14f073714 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -27,8 +27,12 @@ .modified_summary{ 'data-bulk-form-target': "changedSummary", 'data-translation-key': 'admin.products_v3.table.changed_summary'} - if defined?(error_counts) .error_summary - -# X products were saved correctly, but Y products could not be saved correctly. Please review errors and try again - = t('.error_summary.saved', count: error_counts[:saved]) + t('.error_summary.invalid', count: error_counts[:invalid]) + - if error_counts[:saved] > 0 + -# X products were saved correctly, but Y products could not be saved correctly. Please review errors and try again + = t('.error_summary.saved', count: error_counts[:saved]) + t('.error_summary.invalid', count: error_counts[:invalid]) + - else + -# Y products could not be saved correctly. Please review errors and try again + = t('.error_summary.invalid', count: error_counts[:invalid]) .form-buttons = form.submit t('.reset'), type: :reset, class: "medium", 'data-reflex': 'click->products#fetch' = form.submit t('.save'), class: "medium" diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 2ab88a2f29..4dd1835ee2 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -330,6 +330,34 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do end end + context "when only one product edited with invalid data" do + let!(:product_b) { create(:simple_product, name: "Bananas") } + + before do + within row_containing_name("Apples") do + fill_in "Name", with: "" + fill_in "SKU", with: "A" * 256 + end + end + + it "shows errors for product" do + # Also update another product with valid data + within row_containing_name("Bananas") do + fill_in "Name", with: "Bananes" + end + + expect { + click_button "Save changes" + product_a.reload + }.to_not change { product_a.name } + + expect(page).not_to have_content("0 product was saved correctly") + expect(page).to have_content("1 product could not be saved") + expect(page).to have_content "Please review the errors and try again" + end + end + end + describe "edit image" do shared_examples "updating image" do it "saves product image" do From b9eea88f5c4a8b9ba72547d604ff693b52f12375 Mon Sep 17 00:00:00 2001 From: isidzukuri Date: Thu, 15 Feb 2024 09:20:32 +0200 Subject: [PATCH 2/3] more precise spec for error message wording --- spec/system/admin/products_v3/products_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 4dd1835ee2..8a1402aaaf 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -351,7 +351,7 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do product_a.reload }.to_not change { product_a.name } - expect(page).not_to have_content("0 product was saved correctly") + expect(page).not_to have_content("0 product was saved correctly, but") expect(page).to have_content("1 product could not be saved") expect(page).to have_content "Please review the errors and try again" end From 0c02b5d9bd71dbdf1543148c6dd7cb7f5fbb9273 Mon Sep 17 00:00:00 2001 From: isidzukuri Date: Thu, 15 Feb 2024 09:24:02 +0200 Subject: [PATCH 3/3] fix spec --- spec/system/admin/products_v3/products_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 8a1402aaaf..8c8d2e18de 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -328,9 +328,8 @@ describe 'As an admin, I can manage products', feature: :admin_style_v3 do expect(page).to have_content "Changes saved" end end - end - context "when only one product edited with invalid data" do + context "when only one product edited with invalid data" do let!(:product_b) { create(:simple_product, name: "Bananas") } before do