Upgrading AngularJS specs to Jasmine 2 syntax

This commit is contained in:
Rob Harrington
2016-05-01 21:10:28 +10:00
parent cfbfe8416f
commit 7a498362b3
28 changed files with 177 additions and 173 deletions

View File

@@ -8,9 +8,10 @@ describe "CustomersCtrl", ->
scope = $rootScope
http = $httpBackend
$controller 'customersCtrl', {$scope: scope, CustomerResource: _CustomerResource_, shops: {}}
this.addMatchers
toAngularEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
it "has no shop pre-selected", ->
expect(scope.shop).toEqual {}
@@ -26,7 +27,7 @@ describe "CustomersCtrl", ->
http.flush()
it "retrievs the list of customers", ->
expect(scope.customers).toAngularEqual customers
expect(scope.customers).toDeepEqual customers
describe "scope.add", ->
it "creates a new customer", ->
@@ -36,7 +37,7 @@ describe "CustomersCtrl", ->
http.expectPOST('/admin/customers.json?email=' + email + '&enterprise_id=1').respond 200, newCustomer
scope.add(email)
http.flush()
expect(scope.customers).toAngularEqual customers
expect(scope.customers).toDeepEqual customers
describe "scope.deleteCustomer", ->
it "deletes a customer", ->
@@ -46,7 +47,7 @@ describe "CustomersCtrl", ->
scope.deleteCustomer(customer)
http.flush()
expect(scope.customers.length).toBe 1
expect(scope.customers[0]).not.toAngularEqual customer
expect(scope.customers[0]).not.toDeepEqual customer
describe "scope.findTags", ->
tags = [
@@ -63,7 +64,7 @@ describe "CustomersCtrl", ->
promise.then (data) ->
result = data
http.flush()
expect(result).toAngularEqual tags
expect(result).toDeepEqual tags
it "filters the tag list", ->
filtered_tags = [
@@ -75,4 +76,4 @@ describe "CustomersCtrl", ->
promise.then (data) ->
result = data
http.flush()
expect(result).toAngularEqual filtered_tags
expect(result).toDeepEqual filtered_tags

View File

@@ -53,7 +53,7 @@ describe "enterpriseCtrl", ->
expect(enterprise.users).not.toContain u4
it "ignores objects that are already in the list, and alerts the user", ->
spyOn(window, "alert").andCallThrough()
spyOn(window, "alert").and.callThrough()
u4 = { id: 3, email: "email-doesn't-matter.com" }
scope.addManager u4
expect(enterprise.users).not.toContain u4

View File

@@ -8,7 +8,7 @@ describe "EnterprisesCtrl", ->
inject ($controller, $rootScope, _Enterprises_) ->
scope = $rootScope
Enterprises = _Enterprises_
spyOn(Enterprises, "index").andReturn "list of enterprises"
spyOn(Enterprises, "index").and.returnValue "list of enterprises"
ctrl = $controller 'enterprisesCtrl', {$scope: scope, Enterprises: Enterprises}
describe "setting the shop on scope", ->

View File

@@ -20,10 +20,10 @@ describe "indexPanelCtrl", ->
deferred = null
beforeEach inject ($q) ->
spyOn(scope, "saved").andReturn false
spyOn(scope, "saved").and.returnValue false
spyOn(scope, "$emit")
deferred = $q.defer()
spyOn(Enterprises, "save").andReturn(deferred.promise)
spyOn(Enterprises, "save").and.returnValue(deferred.promise)
scope.save()
it "sets scope.saving to true", ->

View File

@@ -28,21 +28,21 @@ describe "permalinkCtrl", ->
it "sends a request to PermalinkChecker when permalink is changed", ->
deferred.resolve("")
promise = deferred.promise
spyOn(PermalinkChecker, "check").andReturn promise
spyOn(PermalinkChecker, "check").and.returnValue promise
$scope.$apply Enterprise.permalink = "somethingelse" # Change the permalink
expect(PermalinkChecker.check).toHaveBeenCalled()
it "sets available to '' when PermalinkChecker resolves permalink to the existing permalink on Enterprise ", ->
deferred.resolve({permalink: "something"})
promise = deferred.promise
spyOn(PermalinkChecker, "check").andReturn promise
spyOn(PermalinkChecker, "check").and.returnValue promise
$scope.$apply Enterprise.permalink = "somethingelse" # Change the permalink
expect($scope.availability).toEqual ""
it "sets available and permalink when PermalinkChecker resolves", ->
deferred.resolve({ available: "Available", permalink: "permalink"})
promise = deferred.promise
spyOn(PermalinkChecker, "check").andReturn promise
spyOn(PermalinkChecker, "check").and.returnValue promise
$scope.$apply Enterprise.permalink = "somethingelse" # Change the permalink
expect(Enterprise.permalink).toEqual "permalink"
expect($scope.availability).toEqual "Available"
@@ -51,7 +51,7 @@ describe "permalinkCtrl", ->
$scope.availability = "Some Availability"
deferred.reject()
promise = deferred.promise
spyOn(PermalinkChecker, "check").andReturn promise
spyOn(PermalinkChecker, "check").and.returnValue promise
$scope.$apply Enterprise.permalink = "somethingelse" # Change the permalink
expect($scope.availability).toEqual "Some Availability"
expect(Enterprise.permalink).toEqual "somethingelse"

View File

@@ -17,8 +17,8 @@ describe "menuCtrl", ->
inject ($rootScope, $controller, _SideMenu_) ->
scope = $rootScope
SideMenu = _SideMenu_
spyOn(SideMenu, "select").andCallThrough()
spyOn(SideMenu, "setItems").andCallThrough()
spyOn(SideMenu, "select").and.callThrough()
spyOn(SideMenu, "setItems").and.callThrough()
ctrl = $controller 'sideMenuCtrl', {$scope: scope, enterprise: enterprise, SideMenu: SideMenu, enterprisePermissions: {}}
describe "initialisation", ->

View File

@@ -27,16 +27,16 @@ describe "EnterprisePaymentMethods service", ->
describe "determining payment method colour", ->
it "returns 'blue' when at least one payment method is selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 1
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 1
expect(EnterprisePaymentMethods.displayColor()).toBe "blue"
it "returns 'red' when no payment methods are selected", ->
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 0
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 0
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
it "returns 'red' when no payment methods exist", ->
EnterprisePaymentMethods.paymentMethods = []
spyOn(EnterprisePaymentMethods, "selectedCount").andReturn 1
spyOn(EnterprisePaymentMethods, "selectedCount").and.returnValue 1
expect(EnterprisePaymentMethods.displayColor()).toBe "red"
describe "counting selected payment methods", ->

View File

@@ -27,16 +27,16 @@ describe "EnterpriseShippingMethods service", ->
describe "determining shipping method colour", ->
it "returns 'blue' when at least one shipping method is selected", ->
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 1
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 1
expect(EnterpriseShippingMethods.displayColor()).toBe "blue"
it "returns 'red' when no shipping methods are selected", ->
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 0
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 0
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
it "returns 'red' when no shipping methods exist", ->
EnterpriseShippingMethods.shippingMethods = []
spyOn(EnterpriseShippingMethods, "selectedCount").andReturn 1
spyOn(EnterpriseShippingMethods, "selectedCount").and.returnValue 1
expect(EnterpriseShippingMethods.displayColor()).toBe "red"
describe "counting selected shipping methods", ->

View File

@@ -4,9 +4,10 @@ describe "Enterprises service", ->
beforeEach ->
module 'admin.enterprises'
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
inject ($q, _$httpBackend_, _Enterprises_, _EnterpriseResource_) ->
Enterprises = _Enterprises_
@@ -98,14 +99,14 @@ describe "Enterprises service", ->
describe "#saved", ->
describe "when attributes of the object have been altered", ->
beforeEach ->
spyOn(Enterprises, "diff").andReturn ["attr1", "attr2"]
spyOn(Enterprises, "diff").and.returnValue ["attr1", "attr2"]
it "returns false", ->
expect(Enterprises.saved({})).toBe false
describe "when attributes of the object have not been altered", ->
beforeEach ->
spyOn(Enterprises, "diff").andReturn []
spyOn(Enterprises, "diff").and.returnValue []
it "returns false", ->
expect(Enterprises.saved({})).toBe true

View File

@@ -29,7 +29,7 @@ describe "Panels service", ->
describe "when no panel is currently selected", ->
beforeEach ->
scopeMock.getSelected = jasmine.createSpy('getSelected').andReturn(null)
scopeMock.getSelected = jasmine.createSpy('getSelected').and.returnValue(null)
Panels.toggle(12, 'panel_name')
it "calls #open on the scope", ->
@@ -37,7 +37,7 @@ describe "Panels service", ->
describe "when #toggle is called for the currently selected panel", ->
beforeEach ->
scopeMock.getSelected = jasmine.createSpy('getSelected').andReturn('panel_name')
scopeMock.getSelected = jasmine.createSpy('getSelected').and.returnValue('panel_name')
Panels.toggle(12, 'panel_name')
it "calls #close on the scope", ->
@@ -45,7 +45,7 @@ describe "Panels service", ->
describe "when #toggle is called for a different panel", ->
beforeEach ->
scopeMock.getSelected = jasmine.createSpy('getSelected').andReturn('some_other_panel_name')
scopeMock.getSelected = jasmine.createSpy('getSelected').and.returnValue('some_other_panel_name')
Panels.toggle(12, 'panel_name')
it "calls #setSelected on the scope", ->

View File

@@ -4,7 +4,7 @@ describe "Pending Changes", ->
beforeEach ->
resourcesMock =
update: jasmine.createSpy('update').andCallFake (change) ->
update: jasmine.createSpy('update').and.callFake (change) ->
$promise:
then: (successFn, errorFn) ->
return successFn({propertyName: "new_value"}) if change.success
@@ -88,7 +88,7 @@ describe "Pending Changes", ->
it "sends the correct object to dataSubmitter", ->
pendingChanges.submit change
expect(resourcesMock.update.calls.length).toEqual 1
expect(resourcesMock.update.calls.count()).toBe 1
expect(resourcesMock.update).toHaveBeenCalledWith change
describe "successful request", ->
@@ -96,9 +96,9 @@ describe "Pending Changes", ->
change.success = true
it "calls remove with id and attribute name", ->
spyOn(pendingChanges, "remove").andCallFake(->)
spyOn(pendingChanges, "remove").and.callFake(->)
pendingChanges.submit change
expect(pendingChanges.remove.calls.length).toEqual 1
expect(pendingChanges.remove.calls.count()).toBe 1
expect(pendingChanges.remove).toHaveBeenCalledWith 1, "propertyName"
it "calls reset on the relevant scope", ->
@@ -114,7 +114,7 @@ describe "Pending Changes", ->
change.success = false
it "does not call remove", ->
spyOn(pendingChanges, "remove").andCallFake(->)
spyOn(pendingChanges, "remove").and.callFake(->)
pendingChanges.submit change
expect(pendingChanges.remove).not.toHaveBeenCalled()
@@ -128,13 +128,13 @@ describe "Pending Changes", ->
describe "cycling through all changes to submit to server", ->
it "sends the correct object to dataSubmitter", ->
spyOn(pendingChanges, "submit").andCallFake(->)
spyOn(pendingChanges, "submit").and.callFake(->)
pendingChanges.pendingChanges =
1: { "prop1": { attr: "prop1", value: 1 }, "prop2": { attr: "prop2", value: 2 } }
2: { "prop1": { attr: "prop1", value: 2 }, "prop2": { attr: "prop2", value: 4 } }
7: { "prop2": { attr: "prop2", value: 5 } }
pendingChanges.submitAll()
expect(pendingChanges.submit.calls.length).toEqual 5
expect(pendingChanges.submit.calls.count()).toBe 5
expect(pendingChanges.submit).toHaveBeenCalledWith { attr: "prop1", value: 1 }
expect(pendingChanges.submit).toHaveBeenCalledWith { attr: "prop2", value: 2 }
expect(pendingChanges.submit).toHaveBeenCalledWith { attr: "prop1", value: 2 }
@@ -142,7 +142,7 @@ describe "Pending Changes", ->
expect(pendingChanges.submit).toHaveBeenCalledWith { attr: "prop2", value: 5 }
it "returns an array of promises representing all sumbit requests", ->
spyOn(pendingChanges, "submit").andCallFake (change) -> change.value
spyOn(pendingChanges, "submit").and.callFake (change) -> change.value
pendingChanges.pendingChanges =
1: { "prop1": { attr: "prop1", value: 1 } }
2: { "prop1": { attr: "prop1", value: 2 }, "prop2": { attr: "prop1", value: 4 } }

View File

@@ -8,7 +8,7 @@ describe "switchClass service", ->
elementMock =
addClass: addClass
removeClass: removeClass
timeoutMock = jasmine.createSpy('timeout').andReturn "new timeout"
timeoutMock = jasmine.createSpy('timeout').and.returnValue "new timeout"
timeoutMock.cancel = jasmine.createSpy('timeout.cancel')
beforeEach ->
@@ -22,14 +22,14 @@ describe "switchClass service", ->
it "calls addClass on the element once", ->
switchClassService elementMock, "addClass", [], false
expect(addClass).toHaveBeenCalledWith "addClass"
expect(addClass.calls.length).toEqual 1
expect(addClass.calls.count()).toBe 1
it "calls removeClass on the element for ", ->
switchClassService elementMock, "", ["remClass1", "remClass2", "remClass3"], false
expect(removeClass).toHaveBeenCalledWith "remClass1"
expect(removeClass).toHaveBeenCalledWith "remClass2"
expect(removeClass).toHaveBeenCalledWith "remClass3"
expect(removeClass.calls.length).toEqual 3
expect(removeClass.calls.count()).toBe 3
it "call cancel on element.timout only if it exists", ->
switchClassService elementMock, "", [], false

View File

@@ -9,7 +9,7 @@ describe "Views service", ->
describe "setting views", ->
beforeEach ->
spyOn(Views, "selectView").andCallThrough()
spyOn(Views, "selectView").and.callThrough()
Views.setViews
view1: { name: 'View1', visible: true }
view2: { name: 'View2', visible: false }

View File

@@ -5,9 +5,10 @@ describe "LineItemsCtrl", ->
beforeEach ->
module "admin.lineItems"
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
beforeEach inject(($controller, $rootScope, $httpBackend, _$timeout_, _VariantUnitManager_, _Enterprises_, _Orders_, _LineItems_, _OrderCycles_) ->
scope = $rootScope.$new()
@@ -19,9 +20,9 @@ describe "LineItemsCtrl", ->
LineItems = _LineItems_
OrderCycles = _OrderCycles_
VariantUnitManager = _VariantUnitManager_
spyOn(window, "daysFromToday").andReturn "SomeDate"
spyOn(window, "formatDate").andReturn "SomeDate"
spyOn(window, "parseDate").andReturn "SomeDate"
spyOn(window, "daysFromToday").and.returnValue "SomeDate"
spyOn(window, "formatDate").and.returnValue "SomeDate"
spyOn(window, "parseDate").and.returnValue "SomeDate"
supplier = { id: 1, name: "Supplier" }
distributor = { id: 5, name: "Distributor" }
@@ -51,7 +52,7 @@ describe "LineItemsCtrl", ->
expect(scope.quickSearch).toBeUndefined()
it "will not have reset the form state to pristine", ->
expect(scope.bulk_order_form.$setPristine.calls.length).toEqual 0
expect(scope.bulk_order_form.$setPristine.calls.count()).toBe 0
describe "after data is returned", ->
beforeEach ->
@@ -87,13 +88,13 @@ describe "LineItemsCtrl", ->
expect(scope.quickSearch).toBe = ""
it "resets the form state to pristine", ->
expect(scope.bulk_order_form.$setPristine.calls.length).toEqual 1
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").andReturn true
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 })
@@ -247,7 +248,7 @@ describe "LineItemsCtrl", ->
# A Units Variant is an API object which holds unit properies of a variant
beforeEach ->
spyOn(Math,"round").andCallThrough()
spyOn(Math,"round").and.callThrough()
it "returns '' if selectedUnitsVariant has no property 'variant_unit'", ->
expect(scope.formattedValueWithUnitName(1,{})).toEqual ''
@@ -267,14 +268,14 @@ describe "LineItemsCtrl", ->
it "calls Math.round with the quotient of scale and value, multiplied by 1000", ->
unitsVariant = { variant_unit: "weight" }
spyOn(VariantUnitManager, "getScale").andReturn 5
spyOn(VariantUnitManager, "getScale").and.returnValue 5
scope.formattedValueWithUnitName(10, unitsVariant)
expect(Math.round).toHaveBeenCalledWith 10/5 * 1000
it "returns the result of Math.round divided by 1000, followed by the result of getUnitName", ->
unitsVariant = { variant_unit: "weight" }
spyOn(VariantUnitManager, "getScale").andReturn 1000
spyOn(VariantUnitManager, "getUnitName").andReturn "kg"
spyOn(VariantUnitManager, "getScale").and.returnValue 1000
spyOn(VariantUnitManager, "getUnitName").and.returnValue "kg"
expect(scope.formattedValueWithUnitName(2000,unitsVariant)).toEqual "2 kg"
describe "updating the price upon updating the weight of a line item", ->

View File

@@ -4,9 +4,10 @@ describe "LineItems service", ->
beforeEach ->
module 'admin.lineItems'
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
inject ($q, _$httpBackend_, _LineItems_, _LineItemResource_) ->
LineItems = _LineItems_
@@ -72,14 +73,14 @@ describe "LineItems service", ->
describe "#isSaved", ->
describe "when attributes of the object have been altered", ->
beforeEach ->
spyOn(LineItems, "diff").andReturn ["attr1", "attr2"]
spyOn(LineItems, "diff").and.returnValue ["attr1", "attr2"]
it "returns false", ->
expect(LineItems.isSaved({})).toBe false
describe "when attributes of the object have not been altered", ->
beforeEach ->
spyOn(LineItems, "diff").andReturn []
spyOn(LineItems, "diff").and.returnValue []
it "returns false", ->
expect(LineItems.isSaved({})).toBe true

View File

@@ -18,11 +18,11 @@ describe "AdminSimpleCreateOrderCycleCtrl", ->
addSupplier: jasmine.createSpy()
addDistributor: jasmine.createSpy()
setExchangeVariants: jasmine.createSpy()
new: jasmine.createSpy().andReturn order_cycle
new: jasmine.createSpy().and.returnValue order_cycle
Enterprise =
get: jasmine.createSpy().andReturn {id: 123}
get: jasmine.createSpy().and.returnValue {id: 123}
index: jasmine.createSpy()
suppliedVariants: jasmine.createSpy().andReturn('supplied variants')
suppliedVariants: jasmine.createSpy().and.returnValue('supplied variants')
EnterpriseFee =
index: jasmine.createSpy()
ocInstance = {}

View File

@@ -4,9 +4,10 @@ describe "OrderCycles service", ->
beforeEach ->
module 'admin.orderCycles'
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
inject ($q, _$httpBackend_, _OrderCycles_, _OrderCycleResource_) ->
OrderCycles = _OrderCycles_
@@ -98,14 +99,14 @@ describe "OrderCycles service", ->
describe "#saved", ->
describe "when attributes of the object have been altered", ->
beforeEach ->
spyOn(OrderCycles, "diff").andReturn ["attr1", "attr2"]
spyOn(OrderCycles, "diff").and.returnValue ["attr1", "attr2"]
it "returns false", ->
expect(OrderCycles.saved({})).toBe false
describe "when attributes of the object have not been altered", ->
beforeEach ->
spyOn(OrderCycles, "diff").andReturn []
spyOn(OrderCycles, "diff").and.returnValue []
it "returns false", ->
expect(OrderCycles.saved({})).toBe true

View File

@@ -4,9 +4,10 @@ describe "Orders service", ->
beforeEach ->
module 'admin.orders'
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
inject ($q, _$httpBackend_, _Orders_, _OrderResource_) ->
Orders = _Orders_
@@ -74,14 +75,14 @@ describe "Orders service", ->
describe "#saved", ->
describe "when attributes of the object have been altered", ->
beforeEach ->
spyOn(Orders, "diff").andReturn ["attr1", "attr2"]
spyOn(Orders, "diff").and.returnValue ["attr1", "attr2"]
it "returns false", ->
expect(Orders.saved({})).toBe false
describe "when attributes of the object have not been altered", ->
beforeEach ->
spyOn(Orders, "diff").andReturn []
spyOn(Orders, "diff").and.returnValue []
it "returns false", ->
expect(Orders.saved({})).toBe true

View File

@@ -15,26 +15,26 @@ describe "Option Value Namer", ->
it "when description is blank", ->
v.unit_description = null
spyOn(namer, "value_scaled").andReturn true
spyOn(namer, "option_value_value_unit").andReturn ["value", "unit"]
spyOn(namer, "value_scaled").and.returnValue true
spyOn(namer, "option_value_value_unit").and.returnValue ["value", "unit"]
expect(namer.name()).toBe "valueunit"
it "when description is present", ->
v.unit_description = 'desc'
spyOn(namer, "option_value_value_unit").andReturn ["value", "unit"]
spyOn(namer, "value_scaled").andReturn true
spyOn(namer, "option_value_value_unit").and.returnValue ["value", "unit"]
spyOn(namer, "value_scaled").and.returnValue true
expect(namer.name()).toBe "valueunit desc"
it "when value is blank and description is present", ->
v.unit_description = 'desc'
spyOn(namer, "option_value_value_unit").andReturn [null, null]
spyOn(namer, "value_scaled").andReturn true
spyOn(namer, "option_value_value_unit").and.returnValue [null, null]
spyOn(namer, "value_scaled").and.returnValue true
expect(namer.name()).toBe "desc"
it "spaces value and unit when value is unscaled", ->
v.unit_description = null
spyOn(namer, "option_value_value_unit").andReturn ["value", "unit"]
spyOn(namer, "value_scaled").andReturn false
spyOn(namer, "option_value_value_unit").and.returnValue ["value", "unit"]
spyOn(namer, "value_scaled").and.returnValue false
expect(namer.name()).toBe "value unit"
describe "determining if a variant's value is scaled", ->
@@ -44,7 +44,7 @@ describe "Option Value Namer", ->
p = {}
v = { product: p }
namer = new OptionValueNamer(v)
it "returns true when the product has a scale", ->
p.variant_unit_scale = 1000
expect(namer.value_scaled()).toBe true
@@ -120,4 +120,4 @@ describe "Option Value Namer", ->
p.variant_unit_scale = null
p.variant_unit_name = 'foo'
v.unit_value = null
expect(namer.option_value_value_unit()).toEqual [null, null]
expect(namer.option_value_value_unit()).toEqual [null, null]

View File

@@ -73,21 +73,21 @@ describe "SideMenu service", ->
describe "hiding an item by name", ->
it "sets visible to false on the response from find_by_name", ->
mockItem = { visible: true }
spyOn(SideMenu, 'find_by_name').andReturn mockItem
spyOn(SideMenu, 'find_by_name').and.returnValue mockItem
SideMenu.hide_item_by_name()
expect(mockItem.visible).toBe false
it "doesn't crash if null is returned from find_by_name", ->
spyOn(SideMenu, 'find_by_name').andReturn null
spyOn(SideMenu, 'find_by_name').and.returnValue null
SideMenu.hide_item_by_name()
describe "showing an item by name", ->
it "sets visible to false on the response from find_by_name", ->
mockItem = { visible: false }
spyOn(SideMenu, 'find_by_name').andReturn mockItem
spyOn(SideMenu, 'find_by_name').and.returnValue mockItem
SideMenu.show_item_by_name()
expect(mockItem.visible).toBe true
it "doesn't crash if null is returned from find_by_name", ->
spyOn(SideMenu, 'find_by_name').andReturn null
spyOn(SideMenu, 'find_by_name').and.returnValue null
SideMenu.show_item_by_name()

View File

@@ -47,7 +47,7 @@ describe "TagRulesCtrl", ->
beforeEach inject ($httpBackend) ->
rule = scope.tagGroups[0].rules[0]
spyOn(window, "confirm").andReturn(true)
spyOn(window, "confirm").and.returnValue(true)
$httpBackend.expectDELETE('/admin/enterprises/45/tag_rules/1.json').respond(status: 204)
scope.deleteTagRule(scope.tagGroups[0], rule)
$httpBackend.flush()

View File

@@ -10,7 +10,7 @@ describe "AdminOrderMgmtCtrl", ->
ctrl = $controller
httpBackend = $httpBackend
VariantUnitManager = _VariantUnitManager_
spyOn(window, "formatDate").andReturn "SomeDate"
spyOn(window, "formatDate").and.returnValue "SomeDate"
ctrl "AdminOrderMgmtCtrl", {$scope: scope}
)
@@ -24,8 +24,8 @@ describe "AdminOrderMgmtCtrl", ->
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[sells_in][]=own&q[sells_in][]=any").respond returnedDistributors
httpBackend.expectGET("/api/order_cycles/accessible?as=distributor&q[orders_close_at_gt]=SomeDate").respond returnedOrderCycles
spyOn(scope, "initialiseVariables").andCallThrough()
spyOn(scope, "fetchOrders").andReturn "nothing"
spyOn(scope, "initialiseVariables").and.callThrough()
spyOn(scope, "fetchOrders").and.returnValue "nothing"
#spyOn(returnedSuppliers, "unshift")
#spyOn(returnedDistributors, "unshift")
#spyOn(returnedOrderCycles, "unshift")
@@ -36,8 +36,8 @@ describe "AdminOrderMgmtCtrl", ->
expect(scope.distributors).toEqual [ { id : '0', name : 'All' }, 'list of distributors' ]
expect(scope.orderCycles).toEqual [ { id : '0', name : 'All' }, 'oc1', 'oc2', 'oc3' ]
expect(scope.initialiseVariables.calls.length).toBe 1
expect(scope.fetchOrders.calls.length).toBe 1
expect(scope.initialiseVariables.calls.count()).toBe 1
expect(scope.fetchOrders.calls.count()).toBe 1
expect(scope.spree_api_key_ok).toBe true
describe "fetching orders", ->
@@ -63,8 +63,8 @@ describe "AdminOrderMgmtCtrl", ->
describe "resetting orders", ->
beforeEach ->
spyOn(scope, "matchObject").andReturn "nothing"
spyOn(scope, "resetLineItems").andReturn "nothing"
spyOn(scope, "matchObject").and.returnValue "nothing"
spyOn(scope, "resetLineItems").and.returnValue "nothing"
scope.resetOrders [ "order1", "order2", "order3" ]
it "sets the value of $scope.orders to the data received", ->
@@ -77,8 +77,8 @@ describe "AdminOrderMgmtCtrl", ->
order1 = order2 = order3 = null
beforeEach ->
spyOn(scope, "matchObject").andReturn "nothing"
spyOn(scope, "lineItemOrder").andReturn "copied order"
spyOn(scope, "matchObject").and.returnValue "nothing"
spyOn(scope, "lineItemOrder").and.returnValue "copied order"
order1 = { name: "order1", line_items: [ { name: "line_item1.1" }, { name: "line_item1.1" }, { name: "line_item1.1" } ] }
order2 = { name: "order2", line_items: [ { name: "line_item2.1" }, { name: "line_item2.1" }, { name: "line_item2.1" } ] }
order3 = { name: "order3", line_items: [ { name: "line_item3.1" }, { name: "line_item3.1" }, { name: "line_item3.1" } ] }
@@ -92,18 +92,18 @@ describe "AdminOrderMgmtCtrl", ->
expect(scope.lineItems[6].name).toEqual "line_item3.1"
it "adds a reference to a modified parent order object to each line item", ->
expect(scope.lineItemOrder.calls.length).toEqual scope.orders.length
expect(scope.lineItemOrder.calls.count()).toBe scope.orders.length
expect("copied order").toEqual line_item.order for line_item in scope.lineItems
it "calls matchObject once for each line item", ->
expect(scope.matchObject.calls.length).toEqual scope.lineItems.length
expect(scope.matchObject.calls.count()).toBe scope.lineItems.length
describe "copying orders", ->
order1copy = null
beforeEach ->
spyOn(scope, "lineItemOrder").andCallThrough()
spyOn(scope, "matchObject").andReturn "matched object"
spyOn(scope, "lineItemOrder").and.callThrough()
spyOn(scope, "matchObject").and.returnValue "matched object"
order1 = { name: "order1", line_items: [ ] }
scope.orders = [ order1 ]
order1copy = scope.lineItemOrder order1
@@ -112,7 +112,7 @@ describe "AdminOrderMgmtCtrl", ->
expect(order1copy.hasOwnProperty("line_items")).toEqual false
it "calls matchObject twice for each order (once for distributor and once for order cycle)", ->
expect(scope.matchObject.calls.length).toEqual scope.lineItemOrder.calls.length * 2
expect(scope.matchObject.calls.count()).toBe scope.lineItemOrder.calls.count() * 2
expect(order1copy.distributor).toEqual "matched object"
expect(order1copy.distributor).toEqual "matched object"
@@ -166,7 +166,7 @@ describe "AdminOrderMgmtCtrl", ->
beforeEach ->
scope.initialiseVariables()
spyOn(window,"confirm").andReturn true
spyOn(window,"confirm").and.returnValue true
order = { number: "R12345678", line_items: [] }
line_item1 = { id: 1, order: order }
line_item2 = { id: 2, order: order }
@@ -317,7 +317,7 @@ describe "AdminOrderMgmtCtrl", ->
# A Units Variant is an API object which holds unit properies of a variant
beforeEach ->
spyOn(Math,"round").andCallThrough()
spyOn(Math,"round").and.callThrough()
it "returns '' if selectedUnitsVariant has no property 'variant_unit'", ->
expect(scope.formattedValueWithUnitName(1,{})).toEqual ''
@@ -337,14 +337,14 @@ describe "AdminOrderMgmtCtrl", ->
it "calls Math.round with the quotient of scale and value, multiplied by 1000", ->
unitsVariant = { variant_unit: "weight" }
spyOn(VariantUnitManager, "getScale").andReturn 5
spyOn(VariantUnitManager, "getScale").and.returnValue 5
scope.formattedValueWithUnitName(10, unitsVariant)
expect(Math.round).toHaveBeenCalledWith 10/5 * 1000
it "returns the result of Math.round divided by 1000, followed by the result of getUnitName", ->
unitsVariant = { variant_unit: "weight" }
spyOn(VariantUnitManager, "getScale").andReturn 1000
spyOn(VariantUnitManager, "getUnitName").andReturn "kg"
spyOn(VariantUnitManager, "getScale").and.returnValue 1000
spyOn(VariantUnitManager, "getUnitName").and.returnValue "kg"
expect(scope.formattedValueWithUnitName(2000,unitsVariant)).toEqual "2 kg"
describe "updating the price upon updating the weight of a line item", ->

View File

@@ -258,10 +258,10 @@ describe "AdminProductEditCtrl", ->
describe "loading data upon initialisation", ->
it "gets a list of producers and then resets products with a list of data", ->
$httpBackend.expectGET("/api/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
spyOn($scope, "fetchProducts").andReturn "nothing"
spyOn($scope, "fetchProducts").and.returnValue "nothing"
$scope.initialise()
$httpBackend.flush()
expect($scope.fetchProducts.calls.length).toEqual 1
expect($scope.fetchProducts.calls.count()).toBe 1
expect($scope.spree_api_key_ok).toEqual true
@@ -277,7 +277,7 @@ describe "AdminProductEditCtrl", ->
deferred = $q.defer()
deferred.resolve()
spyOn $scope, "resetProducts"
spyOn(BulkProducts, "fetch").andReturn deferred.promise
spyOn(BulkProducts, "fetch").and.returnValue deferred.promise
it "calls resetProducts after data has been received", ->
$scope.fetchProducts()
@@ -312,13 +312,13 @@ describe "AdminProductEditCtrl", ->
describe "updating the product on hand count", ->
it "updates when product is not available on demand", ->
spyOn($scope, "onHand").andReturn 123
spyOn($scope, "onHand").and.returnValue 123
product = {on_demand: false}
$scope.updateOnHand(product)
expect(product.on_hand).toEqual 123
it "updates when product's variants are not available on demand", ->
spyOn($scope, "onHand").andReturn 123
spyOn($scope, "onHand").and.returnValue 123
product = {on_demand: false, variants: [{on_demand: false}]}
$scope.updateOnHand(product)
expect(product.on_hand).toEqual 123
@@ -610,7 +610,7 @@ describe "AdminProductEditCtrl", ->
describe "filtering products", ->
beforeEach ->
spyOn $scope, "packProduct"
spyOn(window, "filterSubmitProducts").andReturn [
spyOn(window, "filterSubmitProducts").and.returnValue [
{
id: 1
value: 3
@@ -632,7 +632,7 @@ describe "AdminProductEditCtrl", ->
$scope.submitProducts()
it "packs all products and all dirty products", ->
expect($scope.packProduct.calls.length).toEqual 4
expect($scope.packProduct.calls.count()).toBe 4
it "filters returned dirty products", ->
expect(filterSubmitProducts).toHaveBeenCalledWith
@@ -734,7 +734,7 @@ describe "AdminProductEditCtrl", ->
describe "deleting products", ->
it "deletes products with a http delete request to /api/products/id/soft_delete", ->
spyOn(window, "confirm").andReturn true
spyOn(window, "confirm").and.returnValue true
$scope.products = [
{
id: 9
@@ -751,7 +751,7 @@ describe "AdminProductEditCtrl", ->
$httpBackend.flush()
it "removes the specified product from both $scope.products and $scope.dirtyProducts (if it exists there)", ->
spyOn(window, "confirm").andReturn true
spyOn(window, "confirm").and.returnValue true
$scope.products = [
{
id: 9
@@ -790,7 +790,7 @@ describe "AdminProductEditCtrl", ->
describe "when the variant has not been saved", ->
it "removes the variant from products and dirtyProducts", ->
spyOn(window, "confirm").andReturn true
spyOn(window, "confirm").and.returnValue true
$scope.products = [
{id: 1, variants: [{id: -1},{id: -2}]}
]
@@ -806,7 +806,7 @@ describe "AdminProductEditCtrl", ->
describe "when the variant has been saved", ->
it "deletes variants with a http delete request to /api/products/product_permalink/variants/(variant_id)/soft_delete", ->
spyOn(window, "confirm").andReturn true
spyOn(window, "confirm").and.returnValue true
$scope.products = [
{
id: 9
@@ -832,7 +832,7 @@ describe "AdminProductEditCtrl", ->
$httpBackend.flush()
it "removes the specified variant from both the variants object and $scope.dirtyProducts (if it exists there)", ->
spyOn(window, "confirm").andReturn true
spyOn(window, "confirm").and.returnValue true
$scope.products = [
{
id: 9
@@ -927,7 +927,7 @@ describe "converting arrays of objects with ids to an object with ids as keys",
it "sends arrays with the key 'variants' to itself", ->
spyOn(window, "toObjectWithIDKeys").andCallThrough()
spyOn(window, "toObjectWithIDKeys").and.callThrough()
array = [
{
id: 1

View File

@@ -30,7 +30,7 @@ describe "CheckoutCtrl", ->
beforeEach ->
inject ($controller, $rootScope, _storage_) ->
storage = _storage_
spyOn(storage, "bind").andCallThrough()
spyOn(storage, "bind").and.callThrough()
scope = $rootScope.$new()
CurrentUser = { id: 1 }
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: CurrentUser }

View File

@@ -131,7 +131,7 @@ describe 'Cart service', ->
it "reduces the quantity in the cart", ->
li = {variant: {id: 1}, quantity: 5}
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.quantity).toEqual 0
expect(li.max_quantity).toBeUndefined()
@@ -139,14 +139,14 @@ describe 'Cart service', ->
it "reduces the max_quantity in the cart", ->
li = {variant: {id: 1}, quantity: 5, max_quantity: 6}
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.max_quantity).toEqual 0
it "resets the count on hand available", ->
li = {variant: {id: 1, count_on_hand: 10}, quantity: 5}
stockLevels = {1: {quantity: 0, max_quantity: 0, on_hand: 0}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.variant.count_on_hand).toEqual 0
@@ -154,7 +154,7 @@ describe 'Cart service', ->
it "reduces the quantity in the cart", ->
li = {variant: {id: 1}, quantity: 6}
stockLevels = {1: {quantity: 5, on_hand: 5}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.quantity).toEqual 5
expect(li.max_quantity).toBeUndefined()
@@ -162,14 +162,14 @@ describe 'Cart service', ->
it "does not reduce the max_quantity in the cart", ->
li = {variant: {id: 1}, quantity: 6, max_quantity: 7}
stockLevels = {1: {quantity: 5, max_quantity: 5, on_hand: 5}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.max_quantity).toEqual 7
it "resets the count on hand available", ->
li = {variant: {id: 1}, quantity: 6}
stockLevels = {1: {quantity: 5, on_hand: 6}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.variant.count_on_hand).toEqual 6
@@ -177,7 +177,7 @@ describe 'Cart service', ->
it "does not reset the quantity", ->
li = {variant: {id: 1}, quantity: 6}
stockLevels = {1: {quantity: 5, on_hand: 6}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.quantity).toEqual 6
expect(li.max_quantity).toBeUndefined()
@@ -185,7 +185,7 @@ describe 'Cart service', ->
it "does not reset the max_quantity", ->
li = {variant: {id: 1}, quantity: 5, max_quantity: 7}
stockLevels = {1: {quantity: 5, max_quantity: 6, on_hand: 7}}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels stockLevels
expect(li.quantity).toEqual 5
expect(li.max_quantity).toEqual 7
@@ -193,14 +193,14 @@ describe 'Cart service', ->
describe "when the client-side quantity has been changed from 0 to 1 during the request", ->
it "does not reset the quantity", ->
li = {variant: {id: 1}, quantity: 1}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels {}
expect(li.quantity).toEqual 1
expect(li.max_quantity).toBeUndefined()
it "does not reset the max_quantity", ->
li = {variant: {id: 1}, quantity: 1, max_quantity: 1}
spyOn(Cart, 'line_items_present').andReturn [li]
spyOn(Cart, 'line_items_present').and.returnValue [li]
Cart.compareAndNotifyStockLevels {}
expect(li.quantity).toEqual 1
expect(li.max_quantity).toEqual 1

View File

@@ -30,6 +30,7 @@ describe 'Checkout service', ->
beforeEach ->
orderData =
id: 3102
shipping_method_id: null
payment_method_id: null
email: "test@test.com"
bill_address:
@@ -78,7 +79,7 @@ describe 'Checkout service', ->
expect(Checkout.shippingPrice()).toEqual 13
it 'Gets the current payment method', ->
expect(Checkout.paymentMethod()).toEqual null
expect(Checkout.paymentMethod()).toBeUndefined()
Checkout.order.payment_method_id = 99
expect(Checkout.paymentMethod()).toEqual paymentMethods[0]

View File

@@ -13,13 +13,13 @@ describe "Sidebar", ->
it 'is active when a location in paths is set', ->
spyOn(location, "path").andReturn "/test"
spyOn(location, "path").and.returnValue "/test"
expect(Sidebar.active()).toEqual true
it 'is inactive if location is set', ->
spyOn(location, "path").andReturn null
spyOn(location, "path").and.returnValue null
expect(Sidebar.active()).toEqual false
describe "Toggling on/off", ->
it 'toggles the current sidebar path', ->
expect(Sidebar.active()).toEqual false
@@ -32,6 +32,3 @@ describe "Sidebar", ->
spyOn(Navigation, 'navigate')
Sidebar.toggle()
expect(Navigation.navigate).toHaveBeenCalledWith("/test")

View File

@@ -13,10 +13,10 @@ describe 'OrderCycle controllers', ->
event =
preventDefault: jasmine.createSpy('preventDefault')
OrderCycle =
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').andReturn('product supplied')
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').andReturn('variant supplied')
exchangeDirection: jasmine.createSpy('exchangeDirection').andReturn('exchange direction')
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied')
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
toggleProducts: jasmine.createSpy('toggleProducts')
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
addSupplier: jasmine.createSpy('addSupplier')
@@ -28,15 +28,15 @@ describe 'OrderCycle controllers', ->
removeExchangeFee: jasmine.createSpy('removeExchangeFee')
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
create: jasmine.createSpy('create')
new: jasmine.createSpy('new').andReturn "my order cycle"
new: jasmine.createSpy('new').and.returnValue "my order cycle"
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
index: jasmine.createSpy('index').and.returnValue('enterprises list')
supplied_products: 'supplied products'
suppliedVariants: jasmine.createSpy('suppliedVariants').andReturn('supplied variants')
totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total')
suppliedVariants: jasmine.createSpy('suppliedVariants').and.returnValue('supplied variants')
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
EnterpriseFee =
index: jasmine.createSpy('index').andReturn('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise')
index: jasmine.createSpy('index').and.returnValue('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
ocInstance = {}
module('admin.orderCycles')
@@ -99,7 +99,7 @@ describe 'OrderCycle controllers', ->
1: {id: 1, name: 'Eaterprises'}
2: {id: 2, name: 'Pepper Tree Place'}
3: {id: 3, name: 'South East'}
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').andReturn([2])
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2])
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
expect(scope.enterprisesWithFees()).toEqual([
{id: 2, name: 'Pepper Tree Place'}
@@ -181,10 +181,10 @@ describe 'OrderCycle controllers', ->
'example.com/admin/order_cycles/27/edit'
OrderCycle =
load: jasmine.createSpy('load')
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').andReturn('variants selected')
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').andReturn('product supplied')
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').andReturn('variant supplied')
exchangeDirection: jasmine.createSpy('exchangeDirection').andReturn('exchange direction')
exchangeSelectedVariants: jasmine.createSpy('exchangeSelectedVariants').and.returnValue('variants selected')
productSuppliedToOrderCycle: jasmine.createSpy('productSuppliedToOrderCycle').and.returnValue('product supplied')
variantSuppliedToOrderCycle: jasmine.createSpy('variantSuppliedToOrderCycle').and.returnValue('variant supplied')
exchangeDirection: jasmine.createSpy('exchangeDirection').and.returnValue('exchange direction')
toggleProducts: jasmine.createSpy('toggleProducts')
setExchangeVariants: jasmine.createSpy('setExchangeVariants')
addSupplier: jasmine.createSpy('addSupplier')
@@ -197,13 +197,13 @@ describe 'OrderCycle controllers', ->
removeDistributionOfVariant: jasmine.createSpy('removeDistributionOfVariant')
update: jasmine.createSpy('update')
Enterprise =
index: jasmine.createSpy('index').andReturn('enterprises list')
index: jasmine.createSpy('index').and.returnValue('enterprises list')
supplied_products: 'supplied products'
suppliedVariants: jasmine.createSpy('suppliedVariants').andReturn('supplied variants')
totalVariants: jasmine.createSpy('totalVariants').andReturn('variants total')
suppliedVariants: jasmine.createSpy('suppliedVariants').and.returnValue('supplied variants')
totalVariants: jasmine.createSpy('totalVariants').and.returnValue('variants total')
EnterpriseFee =
index: jasmine.createSpy('index').andReturn('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').andReturn('enterprise fees for enterprise')
index: jasmine.createSpy('index').and.returnValue('enterprise fees list')
forEnterprise: jasmine.createSpy('forEnterprise').and.returnValue('enterprise fees for enterprise')
module('admin.orderCycles')
inject ($controller) ->
@@ -265,7 +265,7 @@ describe 'OrderCycle controllers', ->
1: {id: 1, name: 'Eaterprises'}
2: {id: 2, name: 'Pepper Tree Place'}
3: {id: 3, name: 'South East'}
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').andReturn([2])
OrderCycle.participatingEnterpriseIds = jasmine.createSpy('participatingEnterpriseIds').and.returnValue([2])
EnterpriseFee.enterprise_fees = [ {enterprise_id: 2} ] # Pepper Tree Place has a fee
expect(scope.enterprisesWithFees()).toEqual([
{id: 2, name: 'Pepper Tree Place'}
@@ -376,7 +376,7 @@ describe 'OrderCycle services', ->
expect(Enterprise.supplied_products).toEqual [1, 2, 3, 4, 5, 6]
it "finds supplied variants for an enterprise", ->
spyOn(Enterprise, 'variantsOf').andReturn(10)
spyOn(Enterprise, 'variantsOf').and.returnValue(10)
Enterprise.index()
$httpBackend.flush()
expect(Enterprise.suppliedVariants(1)).toEqual [10, 10]
@@ -721,7 +721,7 @@ describe 'OrderCycle services', ->
master_id: 6
variants: [{id: 7}, {id: 8}]
spyOn(OrderCycle, 'incomingExchangesVariants').andReturn([1, 3])
spyOn(OrderCycle, 'incomingExchangesVariants').and.returnValue([1, 3])
it 'returns true for products whose master is supplied', ->
expect(OrderCycle.productSuppliedToOrderCycle(product_master_present)).toBeTruthy()
@@ -738,7 +738,7 @@ describe 'OrderCycle services', ->
describe 'checking whether a variant is supplied to the order cycle', ->
beforeEach ->
spyOn(OrderCycle, 'incomingExchangesVariants').andReturn([1, 3])
spyOn(OrderCycle, 'incomingExchangesVariants').and.returnValue([1, 3])
it 'returns true for variants that are supplied', ->
expect(OrderCycle.variantSuppliedToOrderCycle({id: 1})).toBeTruthy()
@@ -814,11 +814,11 @@ describe 'OrderCycle services', ->
describe 'creating an order cycle', ->
beforeEach ->
spyOn(OrderCycle, 'confirmNoDistributors').andReturn true
spyOn(OrderCycle, 'confirmNoDistributors').and.returnValue true
it 'redirects to the destination page on success', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
$httpBackend.expectPOST('/admin/order_cycles.json', {
order_cycle: 'this is the submit data'
}).respond {success: true}
@@ -829,7 +829,7 @@ describe 'OrderCycle services', ->
it 'does not redirect on error', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
$httpBackend.expectPOST('/admin/order_cycles.json', {
order_cycle: 'this is the submit data'
}).respond {success: false}
@@ -840,11 +840,11 @@ describe 'OrderCycle services', ->
describe 'updating an order cycle', ->
beforeEach ->
spyOn(OrderCycle, 'confirmNoDistributors').andReturn true
spyOn(OrderCycle, 'confirmNoDistributors').and.returnValue true
it 'redirects to the destination page on success', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
$httpBackend.expectPUT('/admin/order_cycles.json?reloading=1', {
order_cycle: 'this is the submit data'
}).respond {success: true}
@@ -855,7 +855,7 @@ describe 'OrderCycle services', ->
it 'does not redirect on error', ->
OrderCycle.order_cycle = 'this is the order cycle'
spyOn(OrderCycle, 'dataForSubmit').andReturn('this is the submit data')
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
$httpBackend.expectPUT('/admin/order_cycles.json?reloading=1', {
order_cycle: 'this is the submit data'
}).respond {success: false}
@@ -968,19 +968,19 @@ describe 'OrderCycle services', ->
outgoing_exchanges: []
it "returns true when there are distributors", ->
spyOn window, 'confirm'
spyOn(window, 'confirm')
OrderCycle.order_cycle = order_cycle_with_exchanges
expect(OrderCycle.confirmNoDistributors()).toBe true
expect(window.confirm).not.toHaveBeenCalled()
it "returns true when there are no distributors but the user confirms", ->
spyOn(window, 'confirm').andReturn true
spyOn(window, 'confirm').and.returnValue(true)
OrderCycle.order_cycle = order_cycle_without_exchanges
expect(OrderCycle.confirmNoDistributors()).toBe true
expect(window.confirm).toHaveBeenCalled()
it "returns false when there are no distributors and the user does not confirm", ->
spyOn(window, 'confirm').andReturn false
spyOn(window, 'confirm').and.returnValue(false)
OrderCycle.order_cycle = order_cycle_without_exchanges
expect(OrderCycle.confirmNoDistributors()).toBe false
expect(window.confirm).toHaveBeenCalled()