Don't display "group by size" if value is actually null or empty

+ add spec
This commit is contained in:
Jean-Baptiste Bellet
2023-01-06 14:39:39 +01:00
parent 6b3a0fa14a
commit 2258af9cec
2 changed files with 14 additions and 1 deletions

View File

@@ -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

View File

@@ -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 ->