Angularising Order Cycles Index

This commit is contained in:
Rob Harrington
2016-06-24 10:37:19 +10:00
parent bf69ed0008
commit 2a5f598fb0
24 changed files with 437 additions and 182 deletions

View File

@@ -35,9 +35,9 @@ describe "LineItemsCtrl", ->
httpBackend.expectGET("/admin/orders.json?q%5Bcompleted_at_gt%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bstate_not_eq%5D=canceled").respond [order]
httpBackend.expectGET("/admin/bulk_line_items.json?q%5Border%5D%5Bcompleted_at_gt%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]
httpBackend.expectGET("/admin/enterprises/for_line_items.json?ams_prefix=basic&q%5Bsells_in%5D%5B%5D=own&q%5Bsells_in%5D%5B%5D=any").respond [distributor]
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/for_line_items.json?ams_prefix=basic&q%5Bis_primary_producer_eq%5D=true").respond [supplier]
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bis_primary_producer_eq%5D=true").respond [supplier]
scope.bulk_order_form = jasmine.createSpyObj('bulk_order_form', ['$setPristine'])

View File

@@ -0,0 +1,60 @@
describe "OrderCyclesCtrl", ->
ctrl = scope = httpBackend = Enterprises = OrderCycles = null
coordinator = producer = shop = orderCycle = null
beforeEach ->
module "admin.orderCycles"
module ($provide) ->
$provide.value 'columns', []
null
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
beforeEach inject(($controller, $rootScope, $httpBackend, _OrderCycles_, _Enterprises_) ->
scope = $rootScope.$new()
ctrl = $controller
httpBackend = $httpBackend
Enterprises = _Enterprises_
OrderCycles = _OrderCycles_
spyOn(window, "daysFromToday").and.returnValue "SomeDate"
coordinator = { id: 3, name: "Coordinator" }
producer = { id: 1, name: "Producer" }
shop = { id: 5, name: "Shop" }
orderCycle = { id: 4, name: "OC1", coordinator: {id: 3}, shops: [{id: 3},{id: 5}], producers: [{id: 1}] }
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic").respond [coordinator, producer, shop]
httpBackend.expectGET("/admin/order_cycles.json?ams_prefix=index&q%5Borders_close_at_gt%5D=SomeDate").respond [orderCycle]
ctrl "OrderCyclesCtrl", {$scope: scope, Enterprises: Enterprises, OrderCycles: OrderCycles}
)
describe "before data is returned", ->
it "the RequestMonitor will have a state of loading", ->
expect(scope.RequestMonitor.loading).toBe true
describe "after data is returned", ->
beforeEach ->
httpBackend.flush()
describe "initialisation", ->
it "gets suppliers, adds a blank option as the first in the list", ->
expect(scope.enterprises).toDeepEqual [ { id : '0', name : 'All' }, coordinator, producer, shop ]
it "stores enterprises in an list that is accessible by id", ->
expect(Enterprises.enterprisesByID["5"]).toDeepEqual shop
it "gets order cycles, with dereferenced coordinator, shops and producers", ->
oc = OrderCycles.orderCyclesByID["4"]
expect(scope.orderCycles).toDeepEqual [oc]
expect(oc.coordinator).toDeepEqual coordinator
expect(oc.shops).toDeepEqual [coordinator,shop]
expect(oc.producers).toDeepEqual [producer]
expect(oc.shopNames).toEqual "Coordinator, Shop"
expect(oc.producerNames).toEqual "Producer"
it "the RequestMonitor will not longer have a state of loading", ->
expect(scope.RequestMonitor.loading).toBe false

View File

@@ -103,10 +103,11 @@ describe "OrderCycles service", ->
describe "diff", ->
beforeEach ->
OrderCycles.pristineByID = { 23: { id: 23, name: "ent1", is_primary_producer: true } }
OrderCycles.pristineByID = { 23: { id: 23, name: "orderCycle321", orders_open_at: '123' } }
it "returns a list of properties that have been altered", ->
expect(OrderCycles.diff({ id: 23, name: "orderCycle123", is_primary_producer: true })).toEqual ["name"]
it "returns a list of properties that have been altered, if they are in attrsToSave()", ->
spyOn(OrderCycles, "attrsToSave").and.returnValue(["orders_open_at"])
expect(OrderCycles.diff({ id: 23, name: "orderCycle123", orders_open_at: '321' })).toEqual ["orders_open_at"]
describe "resetAttribute", ->