mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
add compatibleUnitScales function and spec
This commit is contained in:
@@ -54,4 +54,7 @@ angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
(parseFloat(scale) for scale in Object.keys(@units[unitType])).sort (a, b) ->
|
||||
a - b
|
||||
|
||||
@compatibleUnitScales
|
||||
@compatibleUnitScales: (scale, unitType) ->
|
||||
scaleSystem = @units[unitType][scale]['system']
|
||||
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) ->
|
||||
a - b
|
||||
|
||||
@@ -34,6 +34,11 @@ describe "VariantUnitManager", ->
|
||||
it "returns a sorted set of scales for unit type volume", ->
|
||||
expect(VariantUnitManager.unitScales('volume')).toEqual [0.001, 1.0, 1000.0]
|
||||
|
||||
describe "compatibleUnitScales", ->
|
||||
it "returns a sorted set of compatible scales based on the scale and unit type provided", ->
|
||||
expect(VariantUnitManager.compatibleUnitScales(1, "weight")).toEqual [1.0, 1000.0, 1000000.0]
|
||||
expect(VariantUnitManager.compatibleUnitScales(453.6, "weight")).toEqual [28.34952, 453.6]
|
||||
|
||||
describe "variantUnitOptions", ->
|
||||
it "returns an array of options", ->
|
||||
expect(VariantUnitManager.variantUnitOptions()).toEqual [
|
||||
|
||||
Reference in New Issue
Block a user