mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Delete that getScale method which is now useless
since we now rely on the serialized variant_unit_scale
This commit is contained in:
@@ -37,17 +37,6 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)
|
||||
options.push [[I18n.t('items'), 'items']]
|
||||
options = [].concat options...
|
||||
|
||||
@getScale: (value, unitType) ->
|
||||
scaledValue = null
|
||||
validScales = []
|
||||
unitScales = VariantUnitManager.unitScales(unitType)
|
||||
|
||||
validScales.unshift scale for scale in unitScales when value/scale >= 1
|
||||
if validScales.length > 0
|
||||
validScales[0]
|
||||
else
|
||||
unitScales[0]
|
||||
|
||||
@getUnitName: (scale, unitType) ->
|
||||
if @units[unitType][scale]
|
||||
@units[unitType][scale]['name']
|
||||
|
||||
@@ -10,21 +10,6 @@ describe "VariantUnitManager", ->
|
||||
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
|
||||
|
||||
it "returns the right unit when using imperial units", ->
|
||||
expect(VariantUnitManager.getScale(453.6, "weight")).toEqual 453.6
|
||||
expect(VariantUnitManager.getScale(28.35, "weight")).toEqual 28.35
|
||||
|
||||
describe "getUnitName", ->
|
||||
it "returns the unit name based on the scale and unit type (weight/volume) provided", ->
|
||||
expect(VariantUnitManager.getUnitName(1, "weight")).toEqual "g"
|
||||
|
||||
Reference in New Issue
Block a user