Skip to content

Commit

Permalink
update VariantUnitManager#compatibleUnitScales to return units that a…
Browse files Browse the repository at this point in the history
…re selected
  • Loading branch information
abdellani committed Nov 1, 2023
1 parent 40dd412 commit 0121747
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits)

@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
if availableUnits
available = availableUnits.split(",")
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem and available.includes(scaleInfo['name'])).sort (a, b) ->
a - b
else
(parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) ->
a - b

@systemOfMeasurement: (scale, unitType) ->
if @units[unitType][scale]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ describe "VariantUnitManager", ->
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_
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 [
Expand Down

0 comments on commit 0121747

Please sign in to comment.