-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathopenlmis-quantity-unit-input.controller.spec.js
More file actions
111 lines (85 loc) · 3.57 KB
/
Copy pathopenlmis-quantity-unit-input.controller.spec.js
File metadata and controls
111 lines (85 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
});
});
});
});