Renaming standing order files (lib, spec)

This commit is contained in:
Rob Harrington
2018-02-02 17:02:56 +11:00
parent a9b5fd69d8
commit 902802594f
17 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
describe "StandingLineItemsCtrl", ->
scope = null
http = null
standingOrder = { id: 1 }
standingLineItem = { id: 2, variant_id: 44 }
beforeEach ->
module('admin.standingOrders')
inject ($controller, $rootScope, $httpBackend) ->
scope = $rootScope
http = $httpBackend
scope.standingOrder = standingOrder
standingOrder.standing_line_items = [standingLineItem]
$controller 'StandingLineItemsController', {$scope: scope}
describe "match", ->
describe "when newItem.variant_id matches an existing sli", ->
beforeEach ->
scope.newItem.variant_id = 44
it "returns the matching sli ", ->
expect(scope.match()).toEqual standingLineItem
describe "when newItem.variant_id dosn't match an existing sli", ->
beforeEach ->
scope.newItem.variant_id = 43
it "returns null", ->
expect(scope.match()).toEqual null
describe "addStandingLineItem", ->
beforeEach ->
scope.standing_order_form = jasmine.createSpyObj('standing_order_form', ['$setDirty'])
standingOrder.buildItem = jasmine.createSpy('buildItem')
describe "when an item with a matching variant_id is found", ->
match = null
beforeEach ->
match = { }
scope.newItem.someProperty = "lalala"
spyOn(scope, "match").and.returnValue(match)
describe "when the matching item isn't marked for destruction", ->
InfoDialog = null
beforeEach inject (_InfoDialog_) ->
InfoDialog = _InfoDialog_
spyOn(InfoDialog, "open")
it "shows a message to the user", ->
scope.addStandingLineItem()
expect(InfoDialog.open).toHaveBeenCalled()
describe "when the matching item is marked for destruction", ->
beforeEach -> match._destroy = true
it "remove the delete flag from the match and merges properties from scope.newItem", ->
scope.addStandingLineItem()
expect(match._destroy).toBeUndefined()
expect(match.someProperty).toEqual "lalala"
describe "when no match is found", ->
beforeEach ->
spyOn(scope, "match").and.returnValue(null)
it "sets the form to $dirty and called buildItem on scope.standingOrder", ->
scope.addStandingLineItem()
expect(scope.standing_order_form.$setDirty).toHaveBeenCalled()
expect(standingOrder.buildItem).toHaveBeenCalledWith(scope.newItem)

View File

@@ -0,0 +1,42 @@
describe "StandingOrdersCtrl", ->
scope = null
http = null
shops = [
{ name: "Shop 1", id: 1 }
{ name: "Shop 2", id: 2 }
{ name: "Shop 3", id: 3 }
]
beforeEach ->
module('admin.standingOrders')
module ($provide) ->
# $provide.value 'columns', []
$provide.value 'shops', shops
null
inject ($controller, $rootScope, _StandingOrderResource_, $httpBackend) ->
scope = $rootScope
http = $httpBackend
$controller 'StandingOrdersController', {$scope: scope, StandingOrderResource: _StandingOrderResource_}
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
it "has no shop pre-selected", ->
expect(scope.shop_id).toEqual null
describe "setting shop_id on scope", ->
standingOrder = { errors: {}, id: 5, customer_id: 3, schedule_id: 1 }
standingOrders = [standingOrder]
beforeEach ->
http.expectGET('/admin/standing_orders.json?q%5Bcanceled_at_null%5D=true&q%5Bshop_id_eq%5D=3').respond 200, standingOrders
scope.$apply -> scope.shop_id = 3
http.flush()
# it "sets the CurrentShop", inject (CurrentShop) ->
# expect(CurrentShop.shop).toEqual shops[2]
it "retrieves the list of standingOrders", ->
expect(scope.standingOrders).toDeepEqual standingOrders