Skip to content

Commit

Permalink
Merge pull request #10494 from filipefurtad0/test_xlsx_reports
Browse files Browse the repository at this point in the history
Adds coverage for CSV and XLSX file download
  • Loading branch information
mkllnk authored Mar 6, 2023
2 parents fc6b61f + 56b9c28 commit b9a7ff9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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,[email protected]
Distributor,oc1,ORDER_NUMBER_1,tax_category,Country,0.025,115.0,2.88,117.88,cfname,clname,ABC123,[email protected]
Distributor,oc1,ORDER_NUMBER_2,tax_category,State,0.015,215.0,3.23,218.23,c2fname,c2lname,DEF456,[email protected]
Distributor,oc1,ORDER_NUMBER_2,tax_category,Country,0.025,215.0,5.38,220.38,c2fname,c2lname,DEF456,[email protected]
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit b9a7ff9

Please sign in to comment.