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

Reproduces bug #12835 #12841

Merged
merged 2 commits into from
Sep 5, 2024
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
Expand Up @@ -7,37 +7,74 @@ module Reports
module OrdersAndFulfillment
RSpec.describe OrderCycleSupplierTotalsByDistributor do
let!(:distributor) { create(:distributor_enterprise) }

let!(:order) do
create(:completed_order_with_totals, line_items_count: 3, distributor:)
end
let(:supplier) { order.line_items.first.variant.supplier }

let(:current_user) { distributor.owner }
let(:params) { { display_summary_row: true } }
let(:report) do
OrderCycleSupplierTotalsByDistributor.new(current_user, params)
end
describe "as the distributor" do
let(:current_user) { distributor.owner }
let(:params) { { display_summary_row: true } }
let(:report) do
OrderCycleSupplierTotalsByDistributor.new(current_user, params)
end

let(:report_table) do
report.table_rows
end
let(:report_table) do
report.table_rows
end

it "generates the report" do
expect(report_table.length).to eq(6)
end
it "generates the report" do
expect(report_table.length).to eq(6)
end

it "has a variant row under the distributor" do
supplier = order.line_items.first.variant.supplier
expect(report.rows.first.producer).to eq supplier.name
expect(report.rows.first.hub).to eq distributor.name
end

it "has a variant row under the distributor" do
supplier = order.line_items.first.variant.supplier
expect(report.rows.first.producer).to eq supplier.name
expect(report.rows.first.hub).to eq distributor.name
it "lists products sorted by name" do
order.line_items[0].variant.product.update(name: "Cucumber")
order.line_items[1].variant.product.update(name: "Apple")
order.line_items[2].variant.product.update(name: "Banane")
product_names = report.rows.map(&:product).filter(&:present?)
expect(product_names).to eq(["Apple", "Banane", "Cucumber"])
end
end

it "lists products sorted by name" do
order.line_items[0].variant.product.update(name: "Cucumber")
order.line_items[1].variant.product.update(name: "Apple")
order.line_items[2].variant.product.update(name: "Banane")
product_names = report.rows.map(&:product).filter(&:present?)
expect(product_names).to eq(["Apple", "Banane", "Cucumber"])
describe "as the supplier of the order cycle" do
before do
pending("S2 bug fix - #12835")
end

let!(:current_user) { supplier.owner }
let!(:params) { { display_summary_row: true } }
let!(:report) do
OrderCycleSupplierTotalsByDistributor.new(current_user, params)
end

let!(:report_table) do
report.table_rows
end

it "generates the report" do
expect(report_table.length).to eq(2)
end

it "has a variant row under the distributor" do
expect(report.rows.first.producer).to eq supplier.name
expect(report.rows.first.hub).to eq distributor.name
end

it "lists products sorted by name" do
order.line_items[0].variant.product.update(name: "Cucumber")
order.line_items[1].variant.product.update(name: "Apple")
order.line_items[2].variant.product.update(name: "Banane")
product_names = report.rows.map(&:product).filter(&:present?)
# only the supplier's variant is displayed
expect(product_names).to include("Cucumber")
expect(product_names).not_to include("Apple", "Banane")
end
end
end
end
Expand Down
134 changes: 88 additions & 46 deletions spec/system/admin/reports/orders_and_fulfillment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,82 +341,124 @@
end

describe "Totals by Distributor" do
before do
click_link "Order Cycle Supplier Totals by Distributor"
end
context "as the distributor" do
let(:current_user) { distributor.owner }

context "with the header row option not selected" do
before do
find("#display_header_row").set(false) # hides the header row
run_report
login_as(current_user)
visit admin_reports_path
click_link "Order Cycle Supplier Totals by Distributor"
end

it "displays the report" do
rows = find("table.report__table").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
context "with the header row option not selected" do
before do
find("#display_header_row").set(false) # hides the header row
run_report
end

# displays the producer column
expect(table).to eq([
["Producer",
"Product",
"Variant",
"Hub",
"Quantity",
"Curr. Cost per Unit",
"Total Cost",
"Shipping Method"]
])
it "displays the report" do
rows = find("table.report__table").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }

# displays the producer column
expect(table).to eq([
["Producer",
"Product",
"Variant",
"Hub",
"Quantity",
"Curr. Cost per Unit",
"Total Cost",
"Shipping Method"]
])

# displays the producer name in the respective column
# does not display the header row
within "td" do
expect(page).to have_content("Supplier Name")
expect(page).not_to have_css("td.header-row")
end
end

# displays the producer name in the respective column
# does not display the header row
within "td" do
expect(page).to have_content("Supplier Name")
expect(page).not_to have_css("td.header-row")
xit "aggregates results per variant" do
pending '#9678'
expect(all('table.report__table tbody tr').count).to eq(4)
# 1 row per variant = 2 rows
# 2 TOTAL rows
# 4 rows total

rows = find("table.report__table").all("tbody tr")
table = rows.map { |r| r.all("td").map { |c| c.text.strip } }

expect(table[0]).to eq(["Supplier Name", "Baked Beans", "1g Small, S",
"Distributor Name", "7", "10.0", "70.0", "UPS Ground"])
expect(table[1]).to eq(["", "", "", "TOTAL", "7", "", "70.0", ""])
expect(table[2]).to eq(["Supplier Name", "Baked Beans", "1g Big, S",
"Distributor Name", "3", "10.0", "30.0", "UPS Ground"])
expect(table[3]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""])
end
end

xit "aggregates results per variant" do
pending '#9678'
expect(all('table.report__table tbody tr').count).to eq(4)
# 1 row per variant = 2 rows
# 2 TOTAL rows
# 4 rows total

rows = find("table.report__table").all("tbody tr")
table = rows.map { |r| r.all("td").map { |c| c.text.strip } }
context "with the header row option selected" do
before do
find("#display_header_row").set(true) # displays the header row
run_report
end

expect(table[0]).to eq(["Supplier Name", "Baked Beans", "1g Small, S",
"Distributor Name", "7", "10.0", "70.0", "UPS Ground"])
expect(table[1]).to eq(["", "", "", "TOTAL", "7", "", "70.0", ""])
expect(table[2]).to eq(["Supplier Name", "Baked Beans", "1g Big, S",
"Distributor Name", "3", "10.0", "30.0", "UPS Ground"])
expect(table[3]).to eq(["", "", "", "TOTAL", "3", "", "30.0", ""])
it "displays the report" do
rows = find("table.report__table").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }

# hides the producer column
expect(table).to eq([
["Product",
"Variant",
"Quantity",
"Curr. Cost per Unit",
"Total Cost",
"Shipping Method"]
])

# displays the producer name in own row
within "td.header-row" do
expect(page).to have_content("Supplier Name")
end
end
end
end

context "with the header row option selected" do
context "as the supplier" do
let(:current_user) { supplier.owner }

before do
find("#display_header_row").set(true) # displays the header row
pending("S2 bug fix - #12835")
login_as(current_user)
visit admin_reports_path
click_link "Order Cycle Supplier Totals by Distributor"
run_report
end

it "displays the report" do
rows = find("table.report__table").all("thead tr")
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
Comment on lines 442 to 443
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be in a helper method on your other PR. We can rebase on that branch to include it, but for now I'll focus on the actual bug...


# hides the producer column
# displays the producer column
expect(table).to eq([
["Product",
["Producer",
"Product",
"Variant",
"Hub",
"Quantity",
"Curr. Cost per Unit",
"Total Cost",
"Shipping Method"]
])

# displays the producer name in own row
within "td.header-row" do
# displays the producer name in the respective column
# does not display the header row
within "td" do
expect(page).to have_content("Supplier Name")
expect(page).not_to have_css("td.header-row")
end
end
end
Expand Down
Loading