Add new ordersCtrl spec

This commit is contained in:
Matt-Yorkley
2018-09-18 09:51:11 +01:00
parent 64620c2797
commit 9ce32e3c14

View File

@@ -0,0 +1,37 @@
describe "ordersCtrl", ->
ctrl = null
Orders = null
$scope = null
orders = [
{ id: 8, order_cycle: { id: 4 }, distributor: { id: 5 }, number: "R123456" }
{ id: 9, order_cycle: { id: 5 }, distributor: { id: 7 }, number: "R213776" }
]
form = {
q: {
created_at_lt: ''
created_at_gt: ''
completed_at_not_null: true
}
}
beforeEach ->
module 'admin.orders'
inject ($controller, $rootScope, RequestMonitor, SortOptions) ->
$scope = $rootScope.$new()
Orders =
index: jasmine.createSpy('index').and.returnValue(orders)
all: orders
ctrl = $controller 'ordersCtrl', { $scope: $scope, RequestMonitor: RequestMonitor, SortOptions: SortOptions, Orders: Orders }
$scope.q = form.q
describe "initialising the controller", ->
it "fetches orders", ->
$scope.initialise()
expect(Orders.index).toHaveBeenCalled()
expect($scope.orders).toEqual orders
describe "using pagination", ->
it "changes the page", ->
$scope.changePage(2)
expect($scope.page).toEqual 2
expect(Orders.index).toHaveBeenCalled()