diff --git a/CHANGELOG.md b/CHANGELOG.md index f542e1c0..b2eabb14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ================== Improvements: +* [OLMIS-8181](https://openlmis.atlassian.net/browse/OLMIS-8181): Disable doses input when net content is one. * [OLMIS-8118](https://openlmis.atlassian.net/browse/OLMIS-8118): Validate max value on positive integer inputs. * [SELV3-748](https://openlmis.atlassian.net/browse/SELV3-748) Resolved cookie issue causing untranslated warning messages * [OLMIS-8192](https://openlmis.atlassian.net/browse/OLMIS-8192): Editable text inputs inside table cells now grow with their content. diff --git a/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.controller.spec.js b/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.controller.spec.js new file mode 100644 index 00000000..617d9321 --- /dev/null +++ b/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.controller.spec.js @@ -0,0 +1,111 @@ +/* + * This program is part of the OpenLMIS logistics management information system platform software. + * Copyright © 2017 VillageReach + * + * This program is free software: you can redistribute it and/or modify it under the terms + * of the GNU Affero General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. You should have received a copy of + * the GNU Affero General Public License along with this program. If not, see + * http://www.gnu.org/licenses. For additional information contact info@OpenLMIS.org. + */ + +describe('QuantityUnitInputController', function() { + + let vm, $controller, quantityUnitCalculateService; + + beforeEach(function() { + module('openlmis-quantity-unit-input'); + + quantityUnitCalculateService = jasmine.createSpyObj('quantityUnitCalculateService', [ + 'recalculateInputQuantity' + ]); + + inject(function($injector) { + $controller = $injector.get('$controller'); + }); + + vm = $controller('QuantityUnitInputController', { + quantityUnitCalculateService: quantityUnitCalculateService + }); + }); + + describe('isQuantityRemainderInDosesDisabled', function() { + + it('should return true when netContent is equal to 1', function() { + vm.netContent = 1; + + expect(vm.isQuantityRemainderInDosesDisabled()).toBe(true); + }); + + it('should return false when netContent is greater than 1', function() { + vm.netContent = 10; + + expect(vm.isQuantityRemainderInDosesDisabled()).toBe(false); + }); + }); + + describe('onInit', function() { + + it('should reset quantityRemainderInDoses to 0 when disabled', function() { + vm.netContent = 1; + vm.item = { + quantityRemainderInDoses: 5 + }; + + vm.$onInit(); + + expect(vm.item.quantityRemainderInDoses).toBe(0); + }); + + it('should not change quantityRemainderInDoses when not disabled', function() { + vm.netContent = 10; + vm.item = { + quantityRemainderInDoses: 5 + }; + + vm.$onInit(); + + expect(vm.item.quantityRemainderInDoses).toBe(5); + }); + + it('should not fail when item is not set', function() { + vm.netContent = 1; + vm.item = undefined; + + expect(function() { + vm.$onInit(); + }).not.toThrow(); + }); + }); + + describe('changeValue', function() { + + it('should recalculate input quantity and emit the change', function() { + const item = { + quantityInPacks: 2 + }; + const recalculated = { + quantityInPacks: 2, + quantity: 20 + }; + vm.netContent = 10; + vm.showInDoses = false; + vm.onChangeQuantity = jasmine.createSpy('onChangeQuantity'); + quantityUnitCalculateService.recalculateInputQuantity.andReturn(recalculated); + + vm.changeValue(item); + + expect(quantityUnitCalculateService.recalculateInputQuantity) + .toHaveBeenCalledWith(item, 10, false); + + expect(vm.onChangeQuantity).toHaveBeenCalledWith({ + lineItem: recalculated + }); + }); + }); + +}); diff --git a/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.html b/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.html index 591aa4bc..6d57b36c 100644 --- a/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.html +++ b/src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.html @@ -22,7 +22,7 @@ ng-class="vm.inputClass" ng-model="vm.item.quantityRemainderInDoses" ng-change="vm.changeValue(vm.item)" - ng-disabled="vm.disabled" + ng-disabled="vm.disabled || vm.isQuantityRemainderInDosesDisabled()" placeholder="{{'openlmisInputDosesPacks.Doses' | message }}" positive-integer />
{{'openlmisInputDosesPacks.DosesBracket' | message }}