forked from openfoodfoundation/openfoodnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Best viewed with white-space ignored
- Loading branch information
Showing
1 changed file
with
59 additions
and
56 deletions.
There are no files selected for viewing
115 changes: 59 additions & 56 deletions
115
spec/javascripts/unit/admin/services/variant_unit_manager_spec.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,63 @@ | ||
describe "VariantUnitManager", -> | ||
VariantUnitManager = null | ||
|
||
beforeEach -> | ||
module "admin.products" | ||
module ($provide)-> | ||
$provide.value "availableUnits", "g,kg,T,mL,L,kL,lb,oz" | ||
null | ||
|
||
beforeEach inject (_VariantUnitManager_) -> | ||
VariantUnitManager = _VariantUnitManager_ | ||
|
||
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" | ||
expect(VariantUnitManager.getUnitName(453.6, "weight")).toEqual "lb" | ||
expect(VariantUnitManager.getUnitName(28.35, "weight")).toEqual "oz" | ||
|
||
describe "unitScales", -> | ||
it "returns a sorted set of scales for unit type weight", -> | ||
expect(VariantUnitManager.unitScales('weight')).toEqual [0.001, 1.0, 28.35, 453.6, 1000.0, 1000000.0] | ||
|
||
it "returns a sorted set of scales for unit type volume", -> | ||
expect(VariantUnitManager.unitScales('volume')).toEqual [0.001, 0.01, 0.1, 1.0, 4.54609, 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.35, 453.6] | ||
|
||
pending "should load only available unit", -> | ||
beforeEach -> | ||
module "admin.products" | ||
module ($provide)-> | ||
$provide.value "availableUnits", "g,T,mL,L,kL,lb" | ||
null | ||
inject (_VariantUnitManager_) -> | ||
VariantUnitManager1 = _VariantUnitManager_ | ||
describe "with default units", -> | ||
beforeEach -> | ||
module "admin.products" | ||
module ($provide)-> | ||
$provide.value "availableUnits", "g,kg,T,mL,L,kL,lb,oz" | ||
null | ||
|
||
beforeEach inject (_VariantUnitManager_) -> | ||
VariantUnitManager = _VariantUnitManager_ | ||
|
||
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" | ||
expect(VariantUnitManager.getUnitName(453.6, "weight")).toEqual "lb" | ||
expect(VariantUnitManager.getUnitName(28.35, "weight")).toEqual "oz" | ||
|
||
describe "unitScales", -> | ||
it "returns a sorted set of scales for unit type weight", -> | ||
expect(VariantUnitManager.unitScales('weight')).toEqual [0.001, 1.0, 28.35, 453.6, 1000.0, 1000000.0] | ||
|
||
it "returns a sorted set of scales for unit type volume", -> | ||
expect(VariantUnitManager.unitScales('volume')).toEqual [0.001, 0.01, 0.1, 1.0, 4.54609, 1000.0] | ||
|
||
describe "compatibleUnitScales", -> | ||
it "returns a sorted set of compatible scales based on the scale and unit type provided", -> | ||
expect(VariantUnitManager1.compatibleUnitScales(1, "weight")).toEqual [1.0, 1000000.0] | ||
expect(VariantUnitManager1.compatibleUnitScales(453.6, "weight")).toEqual [453.6] | ||
|
||
describe "variantUnitOptions", -> | ||
it "returns an array of options", -> | ||
expect(VariantUnitManager.variantUnitOptions()).toEqual [ | ||
["Weight (g)", "weight_1"], | ||
["Weight (oz)", "weight_28.35" ], | ||
["Weight (lb)", "weight_453.6" ] | ||
["Weight (kg)", "weight_1000"], | ||
["Weight (T)", "weight_1000000"], | ||
["Volume (mL)", "volume_0.001"], | ||
["Volume (L)", "volume_1"], | ||
["Volume (kL)", "volume_1000"], | ||
["Items", "items"] | ||
] | ||
expect(VariantUnitManager.compatibleUnitScales(1, "weight")).toEqual [1.0, 1000.0, 1000000.0] | ||
expect(VariantUnitManager.compatibleUnitScales(453.6, "weight")).toEqual [28.35, 453.6] | ||
|
||
describe "variantUnitOptions", -> | ||
it "returns an array of options", -> | ||
expect(VariantUnitManager.variantUnitOptions()).toEqual [ | ||
["Weight (g)", "weight_1"], | ||
["Weight (oz)", "weight_28.35" ], | ||
["Weight (lb)", "weight_453.6" ] | ||
["Weight (kg)", "weight_1000"], | ||
["Weight (T)", "weight_1000000"], | ||
["Volume (mL)", "volume_0.001"], | ||
["Volume (L)", "volume_1"], | ||
["Volume (kL)", "volume_1000"], | ||
["Items", "items"] | ||
] | ||
|
||
describe "should only load available units", -> | ||
beforeEach -> | ||
module "admin.products" | ||
module ($provide)-> | ||
$provide.value "availableUnits", "g,T,mL,L,kL,lb" | ||
null | ||
beforeEach inject (_VariantUnitManager_) -> | ||
VariantUnitManager = _VariantUnitManager_ | ||
|
||
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, 1000000.0] | ||
expect(VariantUnitManager.compatibleUnitScales(453.6, "weight")).toEqual [453.6] |