Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
});
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
<p>{{'openlmisInputDosesPacks.DosesBracket' | message }}</p>
Expand Down
Loading