diff --git a/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv new file mode 100644 index 00000000000..14eb8c3a39e --- /dev/null +++ b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv @@ -0,0 +1,5 @@ +Distributor,Order Cycle,Order number,Tax Category,Tax Rate Name,Tax Rate,Total excl. tax ($),Tax,Total incl. tax ($),First Name,Last Name,Code,Email +Distributor,oc1,ORDER_NUMBER_1,tax_category,State,0.015,115.0,1.73,116.73,cfname,clname,ABC123,order1@example.com +Distributor,oc1,ORDER_NUMBER_1,tax_category,Country,0.025,115.0,2.88,117.88,cfname,clname,ABC123,order1@example.com +Distributor,oc1,ORDER_NUMBER_2,tax_category,State,0.015,215.0,3.23,218.23,c2fname,c2lname,DEF456,order2@example.com +Distributor,oc1,ORDER_NUMBER_2,tax_category,Country,0.025,215.0,5.38,220.38,c2fname,c2lname,DEF456,order2@example.com diff --git a/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx new file mode 100644 index 00000000000..ad2870fd259 Binary files /dev/null and b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx differ diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index eb9699c99b8..d06a1411148 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -105,7 +105,7 @@ it "generates the report" do login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" expect(page).to have_button("Go") click_on "Go" @@ -167,7 +167,7 @@ it "generates the report" do login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" expect(page).to have_button("Go") click_on "Go" @@ -335,7 +335,7 @@ login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" end it "should load all the orders" do @@ -423,5 +423,58 @@ expect(page.find("table.report__table tbody").text).to have_content(customer2_summary_row) expect(page).to have_selector(table_raw_selector, count: 6) end + + describe "downloading" do + context "csv files" do + let(:report_file_csv) do + CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") + end + + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "CSV", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.csv/) + expect(CSV.read(downloaded_filename)).to eq(report_file_csv) + end + end + + context "xlsx files" do + let(:report_file_xlsx) do + File.open("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx") + end + + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "Spreadsheet", from: "report_format" + find("#display_summary_row").uncheck + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.xlsx/) + downloaded_content = extract_xlsx_rows(downloaded_filename, 1..5) + fixture_content = extract_xlsx_rows(report_file_xlsx, 1..5) + expect(downloaded_content).to eq(fixture_content) + end + + def extract_xlsx_rows(file, range) + xlsx = Roo::Excelx.new(file) + range.map { |i| xlsx.row(i) } + end + end + + context "pdf files" do + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "PDF", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.pdf/) + end + end + end end end