mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Generate variantUnitOptions - DRY
This commit is contained in:
@@ -11,15 +11,13 @@ angular.module("admin.products").factory "VariantUnitManager", ->
|
||||
1000.0: 'kL'
|
||||
|
||||
@variantUnitOptions: ->
|
||||
[
|
||||
["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"]
|
||||
]
|
||||
options = for unit_type, scale_with_name of @unitNames
|
||||
unit_type_cap = unit_type[0].toUpperCase() + unit_type[1..-1]
|
||||
for scale in @unitScales(unit_type)
|
||||
name = @getUnitName(scale, unit_type)
|
||||
["#{unit_type_cap} (#{name})", "#{unit_type}_#{scale}"]
|
||||
options.push [['Items', 'items']]
|
||||
[].concat options...
|
||||
|
||||
@getScale: (value, unitType) ->
|
||||
scaledValue = null
|
||||
|
||||
@@ -33,3 +33,15 @@ describe "VariantUnitManager", ->
|
||||
|
||||
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"]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user