mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge branch 'master' into laura_and_will
Conflicts: app/assets/javascripts/darkswarm/services/order.js.coffee
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
describe "enterpriseCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
Enterprise = null
|
||||
PaymentMethods = null
|
||||
ShippingMethods = null
|
||||
|
||||
beforeEach ->
|
||||
module('admin.enterprises')
|
||||
Enterprise =
|
||||
enterprise:
|
||||
payment_method_ids: [ 1, 3 ]
|
||||
shipping_method_ids: [ 2, 4 ]
|
||||
PaymentMethods =
|
||||
paymentMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
ShippingMethods =
|
||||
shippingMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'enterpriseCtrl', {$scope: scope, Enterprise: Enterprise, PaymentMethods: PaymentMethods, ShippingMethods: ShippingMethods}
|
||||
|
||||
describe "initialisation", ->
|
||||
it "stores enterprise", ->
|
||||
expect(scope.Enterprise).toEqual Enterprise.enterprise
|
||||
|
||||
it "stores payment methods", ->
|
||||
expect(scope.PaymentMethods).toBe PaymentMethods.paymentMethods
|
||||
|
||||
it "stores shipping methods", ->
|
||||
expect(scope.ShippingMethods).toBe ShippingMethods.shippingMethods
|
||||
|
||||
it "sets the selected property of each payment method", ->
|
||||
expect(PaymentMethods.paymentMethods[0].selected).toBe true
|
||||
expect(PaymentMethods.paymentMethods[1].selected).toBe false
|
||||
expect(PaymentMethods.paymentMethods[2].selected).toBe true
|
||||
expect(PaymentMethods.paymentMethods[3].selected).toBe false
|
||||
|
||||
it "sets the selected property of each shipping method", ->
|
||||
expect(ShippingMethods.shippingMethods[0].selected).toBe false
|
||||
expect(ShippingMethods.shippingMethods[1].selected).toBe true
|
||||
expect(ShippingMethods.shippingMethods[2].selected).toBe false
|
||||
expect(ShippingMethods.shippingMethods[3].selected).toBe true
|
||||
|
||||
describe "determining payment method colour", ->
|
||||
it "returns 'blue' when at least one payment method is selected", ->
|
||||
scope.PaymentMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 1
|
||||
expect(scope.paymentMethodsColor()).toBe "blue"
|
||||
|
||||
it "returns 'red' when no payment methods are selected", ->
|
||||
scope.PaymentMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 0
|
||||
expect(scope.paymentMethodsColor()).toBe "red"
|
||||
|
||||
it "returns 'red' when no payment methods exist", ->
|
||||
scope.PaymentMethods = [ ]
|
||||
spyOn(scope, "selectedPaymentMethodsCount").andReturn 1
|
||||
expect(scope.paymentMethodsColor()).toBe "red"
|
||||
|
||||
describe "counting selected payment methods", ->
|
||||
it "counts only payment methods with selected: true", ->
|
||||
scopePaymentMethods = [ { selected: true }, { selected: false }, { selected: false }, { selected: true } ]
|
||||
expect(scope.selectedPaymentMethodsCount()).toBe 2
|
||||
|
||||
describe "determining shipping method colour", ->
|
||||
it "returns 'blue' when at least one shipping method is selected", ->
|
||||
scope.ShippingMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 1
|
||||
expect(scope.shippingMethodsColor()).toBe "blue"
|
||||
|
||||
it "returns 'red' when no shipping methods are selected", ->
|
||||
scope.ShippingMethods = [ { id: 1 } ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 0
|
||||
expect(scope.shippingMethodsColor()).toBe "red"
|
||||
|
||||
it "returns 'red' when no shipping method exist", ->
|
||||
scope.ShippingMethods = [ ]
|
||||
spyOn(scope, "selectedShippingMethodsCount").andReturn 1
|
||||
expect(scope.shippingMethodsColor()).toBe "red"
|
||||
|
||||
describe "counting selected shipping methods", ->
|
||||
it "counts only shipping methods with selected: true", ->
|
||||
scope.ShippingMethods = [ { selected: true }, { selected: true }, { selected: false }, { selected: true } ]
|
||||
expect(scope.selectedShippingMethodsCount()).toBe 3
|
||||
@@ -0,0 +1,12 @@
|
||||
describe "Enterprise service", ->
|
||||
Enterprise = null
|
||||
enterprise = { name: "test ent name" }
|
||||
beforeEach ->
|
||||
module 'admin.enterprises'
|
||||
angular.module('admin.enterprises').value('enterprise', enterprise)
|
||||
|
||||
inject ($injector) ->
|
||||
Enterprise = $injector.get("Enterprise")
|
||||
|
||||
it "stores enterprise value as Enterprise.enterprise", ->
|
||||
expect(Enterprise.enterprise).toBe enterprise
|
||||
@@ -1,17 +1,17 @@
|
||||
describe "Option Value Namer", ->
|
||||
optionValueNamer = null
|
||||
OptionValueNamer = null
|
||||
|
||||
beforeEach ->
|
||||
module "ofn.admin"
|
||||
|
||||
beforeEach inject (_optionValueNamer_) ->
|
||||
optionValueNamer = _optionValueNamer_
|
||||
beforeEach inject (_OptionValueNamer_) ->
|
||||
OptionValueNamer = _OptionValueNamer_
|
||||
|
||||
describe "generating option value name", ->
|
||||
v = namer = null
|
||||
beforeEach ->
|
||||
v = {}
|
||||
namer = new optionValueNamer(v)
|
||||
namer = new OptionValueNamer(v)
|
||||
|
||||
it "when description is blank", ->
|
||||
v.unit_description = null
|
||||
@@ -43,7 +43,7 @@ describe "Option Value Namer", ->
|
||||
beforeEach ->
|
||||
p = {}
|
||||
v = { product: p }
|
||||
namer = new optionValueNamer(v)
|
||||
namer = new OptionValueNamer(v)
|
||||
|
||||
it "returns true when the product has a scale", ->
|
||||
p.variant_unit_scale = 1000
|
||||
@@ -58,7 +58,7 @@ describe "Option Value Namer", ->
|
||||
beforeEach ->
|
||||
p = {}
|
||||
v = { product: p }
|
||||
namer = new optionValueNamer(v)
|
||||
namer = new OptionValueNamer(v)
|
||||
|
||||
it "generates simple values", ->
|
||||
p.variant_unit = 'weight'
|
||||
@@ -87,7 +87,7 @@ describe "Option Value Namer", ->
|
||||
expect(namer.option_value_value_unit()).toEqual [100, unit]
|
||||
|
||||
it "generates values for all volume scales", ->
|
||||
for units in [[0.001, 'mL'], [1.0, 'L'], [1000000.0, 'ML']]
|
||||
for units in [[0.001, 'mL'], [1.0, 'L'], [1000.0, 'kL']]
|
||||
[scale, unit] = units
|
||||
p.variant_unit = 'volume'
|
||||
p.variant_unit_scale = scale
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
describe "VariantUnitManager", ->
|
||||
VariantUnitManager = null
|
||||
|
||||
beforeEach ->
|
||||
module "admin.products"
|
||||
|
||||
beforeEach inject (_VariantUnitManager_) ->
|
||||
VariantUnitManager = _VariantUnitManager_
|
||||
|
||||
describe "getScale", ->
|
||||
it "returns the largest scale for which value/scale is greater than 1", ->
|
||||
expect(VariantUnitManager.getScale(1.2,"weight")).toEqual 1.0
|
||||
expect(VariantUnitManager.getScale(1000,"weight")).toEqual 1000.0
|
||||
expect(VariantUnitManager.getScale(0.0012,"volume")).toEqual 0.001
|
||||
expect(VariantUnitManager.getScale(1001,"volume")).toEqual 1000.0
|
||||
|
||||
it "returns the smallest unit available when value is smaller", ->
|
||||
expect(VariantUnitManager.getScale(0.4,"weight")).toEqual 1
|
||||
expect(VariantUnitManager.getScale(0.0004,"volume")).toEqual 0.001
|
||||
|
||||
describe "getUnitName", ->
|
||||
it "returns the unit name based on the scale and unit type (weight/volume) provided", ->
|
||||
expect(VariantUnitManager.getUnitName(1, "weight")).toEqual "g"
|
||||
expect(VariantUnitManager.getUnitName(1000, "weight")).toEqual "kg"
|
||||
expect(VariantUnitManager.getUnitName(1000000, "weight")).toEqual "T"
|
||||
expect(VariantUnitManager.getUnitName(0.001, "volume")).toEqual "mL"
|
||||
expect(VariantUnitManager.getUnitName(1, "volume")).toEqual "L"
|
||||
expect(VariantUnitManager.getUnitName(1000, "volume")).toEqual "kL"
|
||||
|
||||
describe "unitScales", ->
|
||||
it "returns a set of scales for unit type weight", ->
|
||||
expect(VariantUnitManager.unitScales('weight')).toEqual [1.0, 1000.0, 1000000.0]
|
||||
|
||||
it "returns a set of scales for unit type volume", ->
|
||||
expect(VariantUnitManager.unitScales('volume')).toEqual [0.001, 1.0, 1000.0]
|
||||
|
||||
describe "variantUnitOptions", ->
|
||||
it "returns an array of options", ->
|
||||
expect(VariantUnitManager.variantUnitOptions()).toEqual [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
["Weight (T)", "weight_1000000"],
|
||||
["Volume (mL)", "volume_0.001"],
|
||||
["Volume (L)", "volume_1"],
|
||||
["Volume (kL)", "volume_1000"],
|
||||
["Items", "items"]
|
||||
]
|
||||
@@ -1,12 +1,13 @@
|
||||
describe "AdminOrderMgmtCtrl", ->
|
||||
ctrl = scope = httpBackend = null
|
||||
ctrl = scope = httpBackend = VariantUnitManager = null
|
||||
|
||||
beforeEach ->
|
||||
module "ofn.admin"
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend) ->
|
||||
beforeEach inject(($controller, $rootScope, $httpBackend, _VariantUnitManager_) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
httpBackend = $httpBackend
|
||||
VariantUnitManager = _VariantUnitManager_
|
||||
spyOn(window, "formatDate").andReturn "SomeDate"
|
||||
|
||||
ctrl "AdminOrderMgmtCtrl", {$scope: scope}
|
||||
@@ -337,36 +338,16 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
|
||||
it "calls Math.round with the quotient of scale and value, multiplied by 1000", ->
|
||||
unitsVariant = { variant_unit: "weight" }
|
||||
spyOn(scope,"getScale").andReturn 5
|
||||
scope.formattedValueWithUnitName(10,unitsVariant)
|
||||
spyOn(VariantUnitManager, "getScale").andReturn 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(scope,"getScale").andReturn 1000
|
||||
spyOn(scope,"getUnitName").andReturn "kg"
|
||||
spyOn(VariantUnitManager, "getScale").andReturn 1000
|
||||
spyOn(VariantUnitManager, "getUnitName").andReturn "kg"
|
||||
expect(scope.formattedValueWithUnitName(2000,unitsVariant)).toEqual "2 kg"
|
||||
|
||||
describe "getScale", ->
|
||||
it "returns the largest scale for which value/scale is greater than 1", ->
|
||||
expect(scope.getScale(1.2,"weight")).toEqual 1.0
|
||||
expect(scope.getScale(1000,"weight")).toEqual 1000.0
|
||||
expect(scope.getScale(0.0012,"volume")).toEqual 0.001
|
||||
expect(scope.getScale(1001,"volume")).toEqual 1.0
|
||||
|
||||
it "returns the smallest unit available when value is smaller", ->
|
||||
expect(scope.getScale(0.4,"weight")).toEqual 1
|
||||
expect(scope.getScale(0.0004,"volume")).toEqual 0.001
|
||||
|
||||
describe "getUnitName", ->
|
||||
it "returns the unit name based on the scale and unit type (weight/volume) provided", ->
|
||||
expect(scope.getUnitName(1,"weight")).toEqual "g"
|
||||
expect(scope.getUnitName(1000,"weight")).toEqual "kg"
|
||||
expect(scope.getUnitName(1000000,"weight")).toEqual "T"
|
||||
expect(scope.getUnitName(0.001,"volume")).toEqual "mL"
|
||||
expect(scope.getUnitName(1,"volume")).toEqual "L"
|
||||
expect(scope.getUnitName(1000000,"volume")).toEqual "ML"
|
||||
|
||||
describe "managing pending changes", ->
|
||||
dataSubmitter = pendingChangesService = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user