Skip to content

Commit 5b46afb

Browse files
authored
Merge pull request #82 from OpenLMIS/OLMIS-8181-doses-input-disabled
OLMIS-8181: Disable doses input when net content is one
2 parents 214fcb2 + 1b0596f commit 5b46afb

3 files changed

Lines changed: 113 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
==================
66

77
Improvements:
8+
* [OLMIS-8181](https://openlmis.atlassian.net/browse/OLMIS-8181): Disable doses input when net content is one.
89
* [OLMIS-8118](https://openlmis.atlassian.net/browse/OLMIS-8118): Validate max value on positive integer inputs.
910
* [SELV3-748](https://openlmis.atlassian.net/browse/SELV3-748) Resolved cookie issue causing untranslated warning messages
1011
* [OLMIS-8192](https://openlmis.atlassian.net/browse/OLMIS-8192): Editable text inputs inside table cells now grow with their content.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* This program is part of the OpenLMIS logistics management information system platform software.
3+
* Copyright © 2017 VillageReach
4+
*
5+
* This program is free software: you can redistribute it and/or modify it under the terms
6+
* of the GNU Affero General Public License as published by the Free Software Foundation, either
7+
* version 3 of the License, or (at your option) any later version.
8+
*  
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
11+
* See the GNU Affero General Public License for more details. You should have received a copy of
12+
* the GNU Affero General Public License along with this program. If not, see
13+
* http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
14+
*/
15+
16+
describe('QuantityUnitInputController', function() {
17+
18+
let vm, $controller, quantityUnitCalculateService;
19+
20+
beforeEach(function() {
21+
module('openlmis-quantity-unit-input');
22+
23+
quantityUnitCalculateService = jasmine.createSpyObj('quantityUnitCalculateService', [
24+
'recalculateInputQuantity'
25+
]);
26+
27+
inject(function($injector) {
28+
$controller = $injector.get('$controller');
29+
});
30+
31+
vm = $controller('QuantityUnitInputController', {
32+
quantityUnitCalculateService: quantityUnitCalculateService
33+
});
34+
});
35+
36+
describe('isQuantityRemainderInDosesDisabled', function() {
37+
38+
it('should return true when netContent is equal to 1', function() {
39+
vm.netContent = 1;
40+
41+
expect(vm.isQuantityRemainderInDosesDisabled()).toBe(true);
42+
});
43+
44+
it('should return false when netContent is greater than 1', function() {
45+
vm.netContent = 10;
46+
47+
expect(vm.isQuantityRemainderInDosesDisabled()).toBe(false);
48+
});
49+
});
50+
51+
describe('onInit', function() {
52+
53+
it('should reset quantityRemainderInDoses to 0 when disabled', function() {
54+
vm.netContent = 1;
55+
vm.item = {
56+
quantityRemainderInDoses: 5
57+
};
58+
59+
vm.$onInit();
60+
61+
expect(vm.item.quantityRemainderInDoses).toBe(0);
62+
});
63+
64+
it('should not change quantityRemainderInDoses when not disabled', function() {
65+
vm.netContent = 10;
66+
vm.item = {
67+
quantityRemainderInDoses: 5
68+
};
69+
70+
vm.$onInit();
71+
72+
expect(vm.item.quantityRemainderInDoses).toBe(5);
73+
});
74+
75+
it('should not fail when item is not set', function() {
76+
vm.netContent = 1;
77+
vm.item = undefined;
78+
79+
expect(function() {
80+
vm.$onInit();
81+
}).not.toThrow();
82+
});
83+
});
84+
85+
describe('changeValue', function() {
86+
87+
it('should recalculate input quantity and emit the change', function() {
88+
const item = {
89+
quantityInPacks: 2
90+
};
91+
const recalculated = {
92+
quantityInPacks: 2,
93+
quantity: 20
94+
};
95+
vm.netContent = 10;
96+
vm.showInDoses = false;
97+
vm.onChangeQuantity = jasmine.createSpy('onChangeQuantity');
98+
quantityUnitCalculateService.recalculateInputQuantity.andReturn(recalculated);
99+
100+
vm.changeValue(item);
101+
102+
expect(quantityUnitCalculateService.recalculateInputQuantity)
103+
.toHaveBeenCalledWith(item, 10, false);
104+
105+
expect(vm.onChangeQuantity).toHaveBeenCalledWith({
106+
lineItem: recalculated
107+
});
108+
});
109+
});
110+
111+
});

src/openlmis-quantity-unit-input/openlmis-quantity-unit-input.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
ng-class="vm.inputClass"
2323
ng-model="vm.item.quantityRemainderInDoses"
2424
ng-change="vm.changeValue(vm.item)"
25-
ng-disabled="vm.disabled"
25+
ng-disabled="vm.disabled || vm.isQuantityRemainderInDosesDisabled()"
2626
placeholder="{{'openlmisInputDosesPacks.Doses' | message }}"
2727
positive-integer />
2828
<p>{{'openlmisInputDosesPacks.DosesBracket' | message }}</p>

0 commit comments

Comments
 (0)