Adds basic coverage on report file download

Moves file download into report helper

Removes pdf file assertation

Removes test on PDF file on sales tax report

Removes PDF testing from helper
This commit is contained in:
filipefurtad0
2024-08-22 17:12:47 -06:00
parent 32e32117e3
commit 2e5c526170
3 changed files with 51 additions and 38 deletions

View File

@@ -12,4 +12,20 @@ module ReportsHelper
expect(page).not_to have_selector ".loading"
expect(page).to have_button "Go", disabled: false
end
def generate_report
run_report
click_on "Download Report"
wait_for_download
end
def load_file_txt(extension, downloaded_filename)
case extension
when "csv"
CSV.read(downloaded_filename).join(" ")
when "xlsx"
xlsx = Roo::Excelx.new(downloaded_filename)
xlsx.map(&:to_a).join(" ")
end
end
end

View File

@@ -5,6 +5,7 @@ require "system_helper"
RSpec.describe "Orders And Distributors" do
include AuthenticationHelper
include WebHelper
include ReportsHelper
describe "Orders And Distributors" do
let!(:distributor) { create(:distributor_enterprise, name: "By Bike") }
@@ -19,6 +20,13 @@ RSpec.describe "Orders And Distributors" do
}
context "as an enterprise user" do
let(:header) {
["Order date", "Order Id", "Customer Name", "Customer Email", "Customer Phone",
"Customer City", "SKU", "Item name", "Variant", "Quantity", "Max Quantity",
"Cost", "Shipping Cost", "Payment Method", "Distributor", "Distributor address",
"Distributor city", "Distributor postcode", "Shipping Method",
"Shipping instructions"]
}
let(:line_item1) {
[completed_at, order.id, "John Doe", order.email, "123-456-7890", "Herndon",
"ABC", Spree::Product.first.name.to_s, "1g", "1", "none", "10.0", "none", "Check",
@@ -56,28 +64,7 @@ RSpec.describe "Orders And Distributors" do
rows = find("table.report__table").all("thead tr")
table_headers = rows.map { |r| r.all("th").map { |c| c.text.strip } }
expect(table_headers).to eq([
['Order date',
'Order Id',
'Customer Name',
'Customer Email',
'Customer Phone',
'Customer City',
'SKU',
'Item name',
'Variant',
'Quantity',
'Max Quantity',
'Cost',
'Shipping Cost',
'Payment Method',
'Distributor',
'Distributor address',
'Distributor city',
'Distributor postcode',
'Shipping Method',
'Shipping instructions']
])
expect(table_headers).to eq([header])
expect(all('table.report__table tbody tr').count).to eq(
Spree::LineItem.where(
@@ -99,6 +86,30 @@ RSpec.describe "Orders And Distributors" do
expect(table).to have_content(line_item4)
expect(table).to have_content(line_item5)
end
describe "downloading the report" do
shared_examples "reports generated as" do |output_type, extension|
context output_type.to_s do
it "downloads the #{output_type} file" do
select output_type, from: "report_format"
expect { generate_report }.to change { downloaded_filenames.length }.from(0).to(1)
expect(downloaded_filename).to match(/.*\.#{extension}/)
downloaded_file_txt = load_file_txt(extension, downloaded_filename)
expect(downloaded_file_txt).to have_text header.join(" ")
expect(downloaded_file_txt).to have_text(
"By Bike 10 Lovely Street Herndon 20170 UPS Ground", count: 5
)
end
end
end
it_behaves_like "reports generated as", "CSV", "csv"
it_behaves_like "reports generated as", "Spreadsheet", "xlsx"
end
end
context "as admin" do

View File

@@ -3,6 +3,8 @@
require 'system_helper'
RSpec.describe "Sales Tax Totals By order" do
include ReportsHelper
# Scenarion 1: added tax
# 1 producer
# 1 distributor
@@ -467,20 +469,4 @@ RSpec.describe "Sales Tax Totals By order" do
report_subtype: :sales_tax_totals_by_order
)
end
def generate_report
run_report
click_on "Download Report"
wait_for_download
end
def load_file_txt(extension, downloaded_filename)
case extension
when "csv"
CSV.read(downloaded_filename).join(" ")
when "xlsx"
xlsx = Roo::Excelx.new(downloaded_filename)
xlsx.map(&:to_a).join(" ")
end
end
end