mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Match supplier of each line item with the list fetched from server
This commit is contained in:
@@ -42,7 +42,15 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.resetLineItems = ->
|
||||
$scope.lineItems = $scope.orders.reduce (lineItems,order) ->
|
||||
for i,line_item of order.line_items
|
||||
$scope.matchSupplier line_item
|
||||
line_item.order = order
|
||||
lineItems.concat order.line_items
|
||||
, []
|
||||
|
||||
$scope.matchSupplier = (line_item) ->
|
||||
for i of $scope.suppliers
|
||||
supplier = $scope.suppliers[i]
|
||||
if angular.equals(supplier, line_item.supplier)
|
||||
line_item.supplier = supplier
|
||||
break
|
||||
]
|
||||
@@ -59,8 +59,8 @@ feature %q{
|
||||
|
||||
it "displays a column for producer" do
|
||||
page.should have_selector "th.producer", text: "PRODUCER", :visible => true
|
||||
page.should have_selector "td.producer", text: li1.supplier.name, :visible => true
|
||||
page.should have_selector "td.producer", text: li2.supplier.name, :visible => true
|
||||
page.should have_selector "td.producer", text: li1.product.supplier.name, :visible => true
|
||||
page.should have_selector "td.producer", text: li2.product.supplier.name, :visible => true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,19 +36,21 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
expect(scope.resetOrders).toHaveBeenCalledWith "list of orders"
|
||||
|
||||
describe "resetting orders", ->
|
||||
it "sets the value of $scope.orders to the data received", ->
|
||||
beforeEach ->
|
||||
spyOn(scope, "resetLineItems").andReturn "nothing"
|
||||
scope.resetOrders "list of orders"
|
||||
|
||||
it "sets the value of $scope.orders to the data received", ->
|
||||
expect(scope.orders).toEqual "list of orders"
|
||||
|
||||
it "makes a call to $scope.resetLineItems", ->
|
||||
spyOn scope, "resetLineItems"
|
||||
scope.resetOrders "list of orders"
|
||||
expect(scope.resetLineItems).toHaveBeenCalled()
|
||||
|
||||
describe "resetting line items", ->
|
||||
order1 = order2 = order3 = null
|
||||
|
||||
beforeEach ->
|
||||
spyOn(scope, "matchSupplier").andReturn "nothing"
|
||||
order1 = { line_items: [ { name: "line_item1.1" }, { name: "line_item1.1" }, { name: "line_item1.1" } ] }
|
||||
order2 = { line_items: [ { name: "line_item2.1" }, { name: "line_item2.1" }, { name: "line_item2.1" } ] }
|
||||
order3 = { line_items: [ { name: "line_item3.1" }, { name: "line_item3.1" }, { name: "line_item3.1" } ] }
|
||||
@@ -64,4 +66,33 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
it "adds a reference to the parent order to each line item", ->
|
||||
expect(scope.lineItems[0].order).toEqual order1
|
||||
expect(scope.lineItems[3].order).toEqual order2
|
||||
expect(scope.lineItems[6].order).toEqual order3
|
||||
expect(scope.lineItems[6].order).toEqual order3
|
||||
|
||||
it "calls matchSupplier for each line item", ->
|
||||
expect(scope.matchSupplier.calls.length).toEqual 9
|
||||
|
||||
describe "matching supplier", ->
|
||||
it "changes the supplier of the line_item to the one which matches it from the suppliers list", ->
|
||||
s1_s =
|
||||
id: 1
|
||||
name: "S1"
|
||||
|
||||
s2_s =
|
||||
id: 2
|
||||
name: "S2"
|
||||
|
||||
s1_l =
|
||||
id: 1
|
||||
name: "S1"
|
||||
|
||||
expect(s1_s is s1_l).not.toEqual true
|
||||
scope.suppliers = [
|
||||
s1_s
|
||||
s2_s
|
||||
]
|
||||
line_item =
|
||||
id: 10
|
||||
supplier: s1_l
|
||||
|
||||
scope.matchSupplier line_item
|
||||
expect(line_item.supplier is s1_s).toEqual true
|
||||
@@ -393,7 +393,7 @@ describe "AdminProductEditCtrl", ->
|
||||
supplier: s1_p
|
||||
|
||||
scope.matchSupplier product
|
||||
expect(product.supplier).toEqual s1_s
|
||||
expect(product.supplier is s1_s).toEqual true
|
||||
|
||||
|
||||
describe "loading variant unit", ->
|
||||
|
||||
Reference in New Issue
Block a user