mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Don't display "group by size" if value is actually null or empty
+ add spec
This commit is contained in:
@@ -219,7 +219,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
|
||||
|
||||
$scope.getGroupBySizeFormattedValueWithUnitName = (value, unitsProduct, unitsVariant) ->
|
||||
scale = $scope.getScale(unitsProduct, unitsVariant)
|
||||
if scale
|
||||
if scale && value
|
||||
value = value / scale if scale != 28.35 && scale != 1 && scale != 453.6 # divide by scale if not smallest unit
|
||||
$scope.getFormattedValueWithUnitName(value, unitsProduct, unitsVariant, scale)
|
||||
else
|
||||
|
||||
@@ -348,6 +348,19 @@ describe "LineItemsCtrl", ->
|
||||
spyOn(VariantUnitManager, "getUnitName").and.returnValue "lb"
|
||||
expect(scope.formattedValueWithUnitName(2, unitsProduct, unitsVariant)).toEqual "2 lb"
|
||||
|
||||
describe "get group by size formatted value with unit name", ->
|
||||
beforeEach ->
|
||||
spyOn(VariantUnitManager, "getUnitName").and.returnValue "kg"
|
||||
|
||||
unitsProduct = { variant_unit: "weight", variant_unit_scale: 1000 }
|
||||
|
||||
it "returns the formatted value with unit name", ->
|
||||
expect(scope.getGroupBySizeFormattedValueWithUnitName(1000, unitsProduct)).toEqual "1 kg"
|
||||
|
||||
it "handle the case when the value is actually null or empty", ->
|
||||
expect(scope.getGroupBySizeFormattedValueWithUnitName(null, unitsProduct)).toEqual ""
|
||||
expect(scope.getGroupBySizeFormattedValueWithUnitName("", unitsProduct)).toEqual ""
|
||||
|
||||
|
||||
describe "updating the price upon updating the weight of a line item", ->
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user