From 2258af9cec8fd59896ab2e94e4ad002b35bc7847 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 6 Jan 2023 14:39:39 +0100 Subject: [PATCH] Don't display "group by size" if value is actually null or empty + add spec --- .../controllers/line_items_controller.js.coffee | 2 +- .../line_items_controller_spec.js.coffee | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee index fcb7be17f0..161eabac4e 100644 --- a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee +++ b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee @@ -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 diff --git a/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee b/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee index 9d496f6c26..4fc74f5b63 100644 --- a/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/line_items/controllers/line_items_controller_spec.js.coffee @@ -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 ->