From f0a5c76b45eb49bf0065c125f21da03702c4bb96 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Tue, 1 Apr 2025 17:23:19 +0200 Subject: [PATCH 1/3] Fixes button staying disabled after report fail - added a test --- app/jobs/report_job.rb | 12 ++++++++---- spec/support/reports_helper.rb | 13 +++++++++++++ spec/system/admin/reports_spec.rb | 8 ++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/jobs/report_job.rb b/app/jobs/report_job.rb index efa09420ba..c9ea5353fd 100644 --- a/app/jobs/report_job.rb +++ b/app/jobs/report_job.rb @@ -47,10 +47,14 @@ class ReportJob < ApplicationJob end def broadcast_error(channel) - cable_ready[channel].inner_html( - selector: "#report-table", - html: I18n.t("report_job.report_failed") - ).broadcast + cable_ready[channel] + .inner_html( + selector: "#report-go", + html: Spree::Admin::BaseController.helpers.button(I18n.t(:go), "report__submit-btn") + ).inner_html( + selector: "#report-table", + html: I18n.t("report_job.report_failed") + ).broadcast end def actioncable_content(format, blob) diff --git a/spec/support/reports_helper.rb b/spec/support/reports_helper.rb index fda57daca0..2de8a9ab17 100644 --- a/spec/support/reports_helper.rb +++ b/spec/support/reports_helper.rb @@ -13,6 +13,19 @@ module ReportsHelper expect(page).to have_button "Go", disabled: false end + def run_failed_report(report) + click_on "Go" + + allow(report).to receive(:new).and_raise(StandardError, 'Provoked error for testing') + perform_enqueued_jobs(only: ReportJob) + + expect(page).not_to have_selector ".loading" + expect(page).to have_button "Go", disabled: false + expect(page).to have_content 'This report failed. It may be too big to process. ' \ + 'We will look into it but please let us know ' \ + 'if the problem persists.' + end + def generate_report run_report click_on "Download Report" diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 2d689ff7a0..ff7923e1b3 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -347,6 +347,14 @@ RSpec.describe ' variant3.update!(sku: "") end + it "shows report error at the bottom of page" do + login_as_admin + visit admin_reports_path + + click_link 'All products' + run_failed_report(Reporting::Reports::ProductsAndInventory::AllProducts) + end + it "shows products and inventory report" do login_as_admin visit admin_reports_path From 6666896fa3ec2c78dceeb202865a6ce91e6154fe Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Wed, 2 Apr 2025 14:46:22 +0200 Subject: [PATCH 2/3] Requested changes --- spec/support/reports_helper.rb | 13 ------------- spec/system/admin/reports_spec.rb | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/spec/support/reports_helper.rb b/spec/support/reports_helper.rb index 2de8a9ab17..fda57daca0 100644 --- a/spec/support/reports_helper.rb +++ b/spec/support/reports_helper.rb @@ -13,19 +13,6 @@ module ReportsHelper expect(page).to have_button "Go", disabled: false end - def run_failed_report(report) - click_on "Go" - - allow(report).to receive(:new).and_raise(StandardError, 'Provoked error for testing') - perform_enqueued_jobs(only: ReportJob) - - expect(page).not_to have_selector ".loading" - expect(page).to have_button "Go", disabled: false - expect(page).to have_content 'This report failed. It may be too big to process. ' \ - 'We will look into it but please let us know ' \ - 'if the problem persists.' - end - def generate_report run_report click_on "Download Report" diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index ff7923e1b3..151a4f80de 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -352,7 +352,24 @@ RSpec.describe ' visit admin_reports_path click_link 'All products' - run_failed_report(Reporting::Reports::ProductsAndInventory::AllProducts) + report = Reporting::Reports::ProductsAndInventory::AllProducts + + click_on "Go" + + allow(report).to receive(:new).and_raise(StandardError, 'Provoked error for testing') + perform_enqueued_jobs(only: ReportJob) + + expect(page).not_to have_selector ".loading" + expect(page).to have_button "Go", disabled: false + expect(page).to have_content 'This report failed. It may be too big to process. ' \ + 'We will look into it but please let us know ' \ + 'if the problem persists.' + + # Admin shoulb be able to make some changes and retry + sleep(1) + allow(report).to receive(:new).and_call_original + + run_report end it "shows products and inventory report" do From 0ef3b06cdf34ae7937523c89750a7271b438b476 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 7 Apr 2025 13:12:51 +0200 Subject: [PATCH 3/3] Requested changes --- spec/system/admin/reports_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 151a4f80de..7a451de56e 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -366,10 +366,10 @@ RSpec.describe ' 'if the problem persists.' # Admin shoulb be able to make some changes and retry - sleep(1) allow(report).to receive(:new).and_call_original run_report + expect(page).to have_content "Supplier" end it "shows products and inventory report" do