mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Adds test cases to OC Supplier Totals by Distributor
This commit is contained in:
@@ -17,7 +17,10 @@ describe "Orders And Fulfillment" do
|
||||
let(:distributor_address) {
|
||||
create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
|
||||
}
|
||||
let(:distributor) { create(:distributor_enterprise, address: distributor_address) }
|
||||
let(:distributor) {
|
||||
create(:distributor_enterprise, address: distributor_address,
|
||||
name: "Distributor Name")
|
||||
}
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:order1) {
|
||||
create(:completed_order_with_totals, line_items_count: 0, distributor: distributor,
|
||||
@@ -144,73 +147,8 @@ describe "Orders And Fulfillment" do
|
||||
end
|
||||
end
|
||||
|
||||
describe "Order Cycle Supplier Totals" do
|
||||
before do
|
||||
click_link "Order Cycle Supplier Totals"
|
||||
end
|
||||
|
||||
context "with the header row option not selected" do
|
||||
before do
|
||||
find("#display_header_row").set(false) # hides the header row
|
||||
end
|
||||
|
||||
it "displays the report" do
|
||||
click_button 'Go'
|
||||
|
||||
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",
|
||||
"Quantity",
|
||||
"Total Units",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# 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
|
||||
|
||||
context "with the header row option selected" do
|
||||
before do
|
||||
find("#display_header_row").set(true) # displays the header row
|
||||
end
|
||||
|
||||
it "displays the report" do
|
||||
click_button 'Go'
|
||||
|
||||
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",
|
||||
"Total Units",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# displays the producer name in own row
|
||||
within "td.header-row" do
|
||||
expect(page).to have_content("Supplier Name")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for two different orders" do
|
||||
describe "Order Cycle Supplier" do
|
||||
context "for three different orders" do
|
||||
let(:order3) {
|
||||
create(:completed_order_with_totals, line_items_count: 0,
|
||||
distributor: distributor,
|
||||
@@ -221,71 +159,229 @@ describe "Orders And Fulfillment" do
|
||||
before do
|
||||
create(:line_item_with_shipment, variant: variant2, quantity: 4, order: order1)
|
||||
order3.finalize!
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
it "aggregates results per variant" do
|
||||
expect(all('table.report__table tbody tr').count).to eq(3)
|
||||
# 1 row per variant = 2 rows
|
||||
# 1 summary row
|
||||
# 3 rows total
|
||||
describe "Totals" do
|
||||
before do
|
||||
click_link "Order Cycle Supplier Totals"
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
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 not selected" do
|
||||
before do
|
||||
find("#display_header_row").set(false) # hides the header row
|
||||
end
|
||||
|
||||
expect(table[0]).to eq([
|
||||
"Supplier Name",
|
||||
"Baked Beans",
|
||||
"1g Big, S",
|
||||
"3",
|
||||
"0.003",
|
||||
"10.0",
|
||||
"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 } }
|
||||
|
||||
expect(table[1]).to eq([
|
||||
"Supplier Name",
|
||||
"Baked Beans",
|
||||
"1g Small, S",
|
||||
"7",
|
||||
"0.007",
|
||||
"10.0",
|
||||
"70.0"
|
||||
])
|
||||
expect(table[2]).to eq([
|
||||
"",
|
||||
"",
|
||||
"TOTAL",
|
||||
"10",
|
||||
"0.01",
|
||||
"",
|
||||
"100.0"
|
||||
])
|
||||
# displays the producer column
|
||||
expect(table).to eq([
|
||||
["Producer",
|
||||
"Product",
|
||||
"Variant",
|
||||
"Quantity",
|
||||
"Total Units",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# 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
|
||||
|
||||
it "aggregates results per variant" do
|
||||
expect(all('table.report__table tbody tr').count).to eq(3)
|
||||
# 1 row per variant = 2 rows
|
||||
# 1 summary row
|
||||
# 3 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 Big, S",
|
||||
"3",
|
||||
"0.003",
|
||||
"10.0",
|
||||
"30.0"
|
||||
])
|
||||
|
||||
expect(table[1]).to eq([
|
||||
"Supplier Name",
|
||||
"Baked Beans",
|
||||
"1g Small, S",
|
||||
"7",
|
||||
"0.007",
|
||||
"10.0",
|
||||
"70.0"
|
||||
])
|
||||
expect(table[2]).to eq([
|
||||
"",
|
||||
"",
|
||||
"TOTAL",
|
||||
"10",
|
||||
"0.01",
|
||||
"",
|
||||
"100.0"
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
context "with the header row option selected" do
|
||||
before do
|
||||
find("#display_header_row").set(true) # displays the header row
|
||||
click_button 'Go'
|
||||
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 } }
|
||||
|
||||
# hides the producer column
|
||||
expect(table).to eq([
|
||||
["Product",
|
||||
"Variant",
|
||||
"Quantity",
|
||||
"Total Units",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# displays the producer name in own row
|
||||
within "td.header-row" do
|
||||
expect(page).to have_content("Supplier Name")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Order Cycle Supplier Totals by Distributor" do
|
||||
before do
|
||||
click_link "Order Cycle Supplier Totals by Distributor"
|
||||
end
|
||||
describe "Totals by Distributor" do
|
||||
before do
|
||||
click_link "Order Cycle Supplier Totals by Distributor"
|
||||
end
|
||||
|
||||
it "displays the report" do
|
||||
click_button 'Go'
|
||||
context "with the header row option not selected" do
|
||||
before do
|
||||
find("#display_header_row").set(false) # hides the header row
|
||||
click_button 'Go'
|
||||
end
|
||||
|
||||
rows = find("table.report__table").all("thead tr")
|
||||
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
|
||||
expect(table).to eq([
|
||||
["Producer",
|
||||
"Product",
|
||||
"Variant",
|
||||
"Hub",
|
||||
"Quantity",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost",
|
||||
"Shipping Method"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
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"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# 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
|
||||
|
||||
it "aggregates results per variant" do
|
||||
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
|
||||
|
||||
context "with the header row option selected" do
|
||||
before do
|
||||
find("#display_header_row").set(true) # displays the header row
|
||||
click_button 'Go'
|
||||
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 } }
|
||||
|
||||
# hides the producer column
|
||||
expect(table).to eq([
|
||||
["Product",
|
||||
"Variant",
|
||||
"Quantity",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost",
|
||||
"Shipping Method"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
|
||||
# displays the producer name in own row
|
||||
within "td.header-row" do
|
||||
expect(page).to have_content("Supplier Name")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -299,18 +395,6 @@ describe "Orders And Fulfillment" do
|
||||
|
||||
rows = find("table.report__table").all("thead tr")
|
||||
table = rows.map { |r| r.all("th").map { |c| c.text.strip } }
|
||||
expect(table).to eq([
|
||||
["Hub",
|
||||
"Producer",
|
||||
"Product",
|
||||
"Variant",
|
||||
"Quantity",
|
||||
"Curr. Cost per Unit",
|
||||
"Total Cost",
|
||||
"Total Shipping Cost",
|
||||
"Shipping Method"]
|
||||
.map(&:upcase)
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user