diff --git a/lib/reporting/report_headers_builder.rb b/lib/reporting/report_headers_builder.rb index cc5b537fa5..824394536c 100644 --- a/lib/reporting/report_headers_builder.rb +++ b/lib/reporting/report_headers_builder.rb @@ -12,9 +12,9 @@ module Reporting def table_headers filter = if OpenFoodNetwork::FeatureToggle.enabled?(:report_inverse_columns_logic, @current_user) - proc { |key| key.in?(fields_to_show) } + proc { |key| key.to_sym.in?(fields_to_show) } else - proc { |key| !key.in?(fields_to_hide) } + proc { |key| !key.to_sym.in?(fields_to_hide) } end report.columns.keys.filter { |key| filter.call(key) }.map do |key| translate_header(key) diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 68e1fa6aa0..a8a7efd7c0 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -124,7 +124,7 @@ describe ' expect(page).to have_content 'PAYMENT STATE' end - describe "sales tax report" do + shared_examples "sales tax report" do |inverse_columns_logic| let(:distributor1) { create(:distributor_enterprise, with_payment_and_shipping: true, charges_sales_tax: true) } @@ -168,6 +168,9 @@ describe ' } before do + allow(OpenFoodNetwork::FeatureToggle).to receive(:enabled?).with( + :report_inverse_columns_logic, anything + ).and_return(inverse_columns_logic) order1.reload break unless order1.next! until order1.delivery? @@ -180,11 +183,15 @@ describe ' break unless order1.next! until order1.complete? login_as_admin_and_visit admin_reports_path - click_link "Sales Tax" - select("Tax Types", from: "report_subtype") end - it "reports" do + it "generate Tax Types reports" do + if inverse_columns_logic + click_link "Tax Types" + else + click_link "Sales Tax" + select("Tax Types", from: "report_subtype") + end # Then it should give me access only to managed enterprises expect(page).to have_select 'q_distributor_id_eq', with_options: [user1.enterprises.first.name] @@ -211,8 +218,27 @@ describe ' # And the total tax should be correct expect(page).to have_content "286.84" # total tax end + + it "generate Tax Rates report" do + if inverse_columns_logic + click_link "Tax Rates" + else + click_link "Sales Tax" + select("Tax Rates", from: "report_subtype") + end + + click_button 'Go' + expect(page).to have_css(".report__table thead th", text: "20.0% ($)") + expect(page).to have_css(".report__table thead th", text: "0.0% ($)") + + expect(page).to have_table_row [order1.number, "1446.7", "16.76", "0", "270.08", "286.84", + "1733.54"] + end end + it_behaves_like "sales tax report", false + it_behaves_like "sales tax report", true + describe "orders & fulfilment reports" do it "loads the report page" do login_as_admin_and_visit admin_reports_path