Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds coverage for CSV and XLSX file download #10494

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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