From f0a5c76b45eb49bf0065c125f21da03702c4bb96 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Tue, 1 Apr 2025 17:23:19 +0200 Subject: [PATCH] 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