mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Merge pull request #5099 from Matt-Yorkley/ticking-time-bom
Improve BOM
This commit is contained in:
@@ -13,23 +13,23 @@ describe "LineItemsCtrl", ->
|
||||
compare: (actual, expected) ->
|
||||
{ pass: angular.equals(actual, expected) }
|
||||
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _$timeout_, _VariantUnitManager_, _Enterprises_, _Orders_, _LineItems_, _OrderCycles_) ->
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _$timeout_, _VariantUnitManager_, _Enterprises_, _Orders_, _OrderCycles_) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
$timeout = _$timeout_
|
||||
httpBackend = $httpBackend
|
||||
Enterprises = _Enterprises_
|
||||
Orders = _Orders_
|
||||
LineItems = _LineItems_
|
||||
OrderCycles = _OrderCycles_
|
||||
VariantUnitManager = _VariantUnitManager_
|
||||
momentMock = jasmine.createSpyObj('moment', ['format', 'startOf', 'endOf', 'subtract', 'add'])
|
||||
momentMock = jasmine.createSpyObj('moment', ['format', 'startOf', 'endOf', 'subtract', 'add', 'isValid'])
|
||||
spyOn(window,"moment").and.returnValue momentMock
|
||||
momentMock.startOf.and.returnValue momentMock
|
||||
momentMock.endOf.and.returnValue momentMock
|
||||
momentMock.subtract.and.returnValue momentMock
|
||||
momentMock.add.and.returnValue momentMock
|
||||
momentMock.format.and.returnValue "SomeDate"
|
||||
momentMock.isValid.and.returnValue true
|
||||
|
||||
supplier = { id: 1, name: "Supplier" }
|
||||
distributor = { id: 5, name: "Distributor" }
|
||||
@@ -37,8 +37,11 @@ describe "LineItemsCtrl", ->
|
||||
order = { id: 9, order_cycle: { id: 4 }, distributor: { id: 5 }, number: "R123456" }
|
||||
lineItem = { id: 7, quantity: 3, order: { id: 9 }, supplier: { id: 1 } }
|
||||
|
||||
httpBackend.expectGET("/api/orders.json?q%5Bcompleted_at_gteq%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bstate_not_eq%5D=canceled").respond {orders: [order], pagination: {page: 1, pages: 1, results: 1}}
|
||||
httpBackend.expectGET("/admin/bulk_line_items.json?q%5Border%5D%5Bcompleted_at_gteq%5D=SomeDate&q%5Border%5D%5Bcompleted_at_lt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_not_null%5D=true&q%5Border%5D%5Bstate_not_eq%5D=canceled").respond [lineItem]
|
||||
LineItems =
|
||||
index: jasmine.createSpy('index').and.returnValue(lineItem)
|
||||
all: [lineItem]
|
||||
|
||||
httpBackend.expectGET("/api/orders.json?q%5Bcompleted_at_gteq%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bdistributor_id_eq%5D=&q%5Border_cycle_id_eq%5D=&q%5Bstate_not_eq%5D=canceled").respond {orders: [order], pagination: {page: 1, pages: 1, results: 1}}
|
||||
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bsells_in%5D%5B%5D=own&q%5Bsells_in%5D%5B%5D=any").respond [distributor]
|
||||
httpBackend.expectGET("/admin/order_cycles.json?ams_prefix=basic&as=distributor&q%5Borders_close_at_gt%5D=SomeDate").respond [orderCycle]
|
||||
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bis_primary_producer_eq%5D=true").respond [supplier]
|
||||
@@ -52,12 +55,6 @@ describe "LineItemsCtrl", ->
|
||||
it "the RequestMonitor will have a state of loading", ->
|
||||
expect(scope.RequestMonitor.loading).toBe true
|
||||
|
||||
it "will not have reset the select filters", ->
|
||||
expect(scope.distributorFilter).toBeUndefined()
|
||||
expect(scope.supplierFilter).toBeUndefined()
|
||||
expect(scope.orderCycleFilter).toBeUndefined()
|
||||
expect(scope.quickSearch).toBeUndefined()
|
||||
|
||||
it "will not have reset the form state to pristine", ->
|
||||
expect(scope.bulk_order_form.$setPristine.calls.count()).toBe 0
|
||||
|
||||
@@ -83,49 +80,20 @@ describe "LineItemsCtrl", ->
|
||||
expect(scope.orders).toDeepEqual [ { id: 9, order_cycle: orderCycle, distributor: distributor, number: "R123456" } ]
|
||||
|
||||
it "gets line_items, with dereferenced orders and suppliers", ->
|
||||
expect(scope.lineItems).toDeepEqual [ { id: 7, quantity: 3, order: scope.orders[0], supplier: supplier } ]
|
||||
expect(scope.line_items).toDeepEqual [ { id: 7, quantity: 3, order: scope.orders[0], supplier: supplier } ]
|
||||
|
||||
it "the RequestMonitor will have a state of loaded", ->
|
||||
expect(scope.RequestMonitor.loading).toBe false
|
||||
|
||||
it "resets the select filters", ->
|
||||
expect(scope.distributorFilter).toBe 0
|
||||
expect(scope.supplierFilter).toBe 0
|
||||
expect(scope.orderCycleFilter).toBe 0
|
||||
expect(scope.distributorFilter).toBe ''
|
||||
expect(scope.supplierFilter).toBe ''
|
||||
expect(scope.orderCycleFilter).toBe ''
|
||||
expect(scope.quickSearch).toBe = ""
|
||||
|
||||
it "resets the form state to pristine", ->
|
||||
expect(scope.bulk_order_form.$setPristine.calls.count()).toBe 1
|
||||
|
||||
describe "deleting a line item", ->
|
||||
order = line_item1 = line_item2 = null
|
||||
|
||||
beforeEach inject((LineItemResource) ->
|
||||
spyOn(window,"confirm").and.returnValue true
|
||||
order = { number: "R12345678" }
|
||||
line_item1 = new LineItemResource({ id: 1, order: order })
|
||||
line_item2 = new LineItemResource({ id: 2, order: order })
|
||||
scope.lineItems= [ line_item1, line_item2 ]
|
||||
)
|
||||
|
||||
describe "where the request is successful", ->
|
||||
beforeEach ->
|
||||
httpBackend.expectDELETE("/admin/bulk_line_items/1.json").respond "nothing"
|
||||
scope.deleteLineItem line_item1
|
||||
httpBackend.flush()
|
||||
|
||||
it "removes the deleted item from the line_items array", ->
|
||||
expect(scope.lineItems).toEqual [line_item2]
|
||||
|
||||
describe "where the request is unsuccessful", ->
|
||||
beforeEach ->
|
||||
httpBackend.expectDELETE("/admin/bulk_line_items/1.json").respond 404, "NO CONTENT"
|
||||
scope.deleteLineItem line_item1
|
||||
httpBackend.flush()
|
||||
|
||||
it "does not remove line_item from the line_items array", ->
|
||||
expect(scope.lineItems).toEqual [line_item1, line_item2]
|
||||
|
||||
describe "deleting 'checked' line items", ->
|
||||
line_item1 = line_item2 = line_item3 = line_item4 = null
|
||||
|
||||
@@ -134,11 +102,11 @@ describe "LineItemsCtrl", ->
|
||||
line_item2 = { name: "line item 2", checked: true }
|
||||
line_item3 = { name: "line item 3", checked: false }
|
||||
line_item4 = { name: "line item 4", checked: true }
|
||||
scope.lineItems = [ line_item1, line_item2, line_item3, line_item4 ]
|
||||
scope.line_items = [ line_item1, line_item2, line_item3, line_item4 ]
|
||||
|
||||
it "calls deletedLineItem for each 'checked' line item", ->
|
||||
spyOn(scope, "deleteLineItem")
|
||||
scope.deleteLineItems(scope.lineItems)
|
||||
scope.deleteLineItems(scope.line_items)
|
||||
expect(scope.deleteLineItem).toHaveBeenCalledWith(line_item2)
|
||||
expect(scope.deleteLineItem).toHaveBeenCalledWith(line_item4)
|
||||
expect(scope.deleteLineItem).not.toHaveBeenCalledWith(line_item1)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe "LineItems service", ->
|
||||
LineItems = LineItemResource = lineItems = $httpBackend = null
|
||||
LineItems = LineItemResource = lineItems = $httpBackend = $rootScope = $timeout = null
|
||||
|
||||
beforeEach ->
|
||||
module 'admin.lineItems'
|
||||
@@ -15,24 +15,27 @@ describe "LineItems service", ->
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
describe "#index", ->
|
||||
result = response = null
|
||||
result = response = line_item = null
|
||||
|
||||
beforeEach ->
|
||||
response = [{ id: 5, name: 'LineItem 1'}]
|
||||
line_item = { id: 5, name: 'LineItem 1'}
|
||||
response = { line_items: [line_item] }
|
||||
$httpBackend.expectGET('/admin/bulk_line_items.json').respond 200, response
|
||||
result = LineItems.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# LineItemResource returns instances of Resource rather than raw objects
|
||||
expect(LineItems.byID).toDeepEqual { 5: response[0] }
|
||||
expect(LineItems.byID).toDeepEqual { 5: response['line_items'][0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(LineItems.pristineByID).toDeepEqual { 5: response[0] }
|
||||
expect(LineItems.pristineByID).toDeepEqual { 5: response['line_items'][0] }
|
||||
|
||||
it "stores returned data in @all, as an array", ->
|
||||
expect(LineItems.all).toDeepEqual [line_item]
|
||||
|
||||
it "returns an array of line items", ->
|
||||
expect(result).toDeepEqual response
|
||||
|
||||
expect(result).toDeepEqual [line_item]
|
||||
|
||||
describe "#save", ->
|
||||
describe "success", ->
|
||||
@@ -115,6 +118,7 @@ describe "LineItems service", ->
|
||||
lineItem = new LineItemResource({ id: 15, order: { number: '12345678'} })
|
||||
LineItems.pristineByID[15] = lineItem
|
||||
LineItems.byID[15] = lineItem
|
||||
LineItems.all = [lineItem]
|
||||
$httpBackend.expectDELETE('/admin/bulk_line_items/15.json').respond 200, { id: 15, name: 'LineItem 1'}
|
||||
LineItems.delete(lineItem, callback).then( -> resolved = true).catch( -> rejected = true)
|
||||
$httpBackend.flush()
|
||||
@@ -122,6 +126,7 @@ describe "LineItems service", ->
|
||||
it "updates the pristine copy of the lineItem", ->
|
||||
expect(LineItems.pristineByID[15]).toBeUndefined()
|
||||
expect(LineItems.byID[15]).toBeUndefined()
|
||||
expect(LineItems.all).toEqual([])
|
||||
|
||||
it "runs the callback", ->
|
||||
expect(callback).toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user