@hedia/recommendation-screen 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.d.ts +2 -2
- package/coverage/clover.xml +700 -0
- package/coverage/coverage-final.json +28 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +79 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +201 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +170 -0
- package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1460 -0
- package/coverage/lcov-report/src/__tests__/index.html +111 -0
- package/coverage/lcov-report/src/__tests__/utils.tsx.html +512 -0
- package/coverage/lcov-report/src/components/Header.tsx.html +347 -0
- package/coverage/lcov-report/src/components/InfoBars.tsx.html +404 -0
- package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +374 -0
- package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +191 -0
- package/coverage/lcov-report/src/components/LineSeparator.tsx.html +152 -0
- package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +383 -0
- package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +737 -0
- package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +857 -0
- package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +605 -0
- package/coverage/lcov-report/src/components/Remeasure.tsx.html +440 -0
- package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +380 -0
- package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +635 -0
- package/coverage/lcov-report/src/components/activity/Activity.tsx.html +311 -0
- package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +242 -0
- package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +257 -0
- package/coverage/lcov-report/src/components/activity/index.html +141 -0
- package/coverage/lcov-report/src/components/index.html +276 -0
- package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +278 -0
- package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +260 -0
- package/coverage/lcov-report/src/components/mood/index.html +126 -0
- package/coverage/lcov-report/src/index.html +111 -0
- package/coverage/lcov-report/src/locale/i18nUtils.ts.html +161 -0
- package/coverage/lcov-report/src/locale/index.html +111 -0
- package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +326 -0
- package/coverage/lcov-report/src/utils/Constants.ts.html +176 -0
- package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +500 -0
- package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +467 -0
- package/coverage/lcov-report/src/utils/Translations.ts.html +107 -0
- package/coverage/lcov-report/src/utils/Utils.ts.html +263 -0
- package/coverage/lcov-report/src/utils/Validations.ts.html +815 -0
- package/coverage/lcov-report/src/utils/index.html +201 -0
- package/coverage/lcov.info +1581 -0
- package/jest.config.js +2 -1
- package/package.json +2 -2
- package/src/RecommendationScreen.d.ts +2 -3
- package/src/__tests__/components/Emotion.test.jsx +7 -8
- package/src/components/Icon.d.ts +13 -0
- package/src/components/Icon.jsx +42 -0
- package/src/components/LimitationMessage.d.ts +1 -2
- package/src/components/RecommendationModal.d.ts +2 -3
- package/src/components/RecommendationModal.jsx +2 -1
- package/src/components/activity/ActivityIntensity.jsx +4 -3
- package/src/utils/AttentionMessages.d.ts +16 -10
- package/src/utils/AttentionMessages.jsx +15 -10
- package/src/utils/RecommendationUtils.d.ts +2 -3
- package/src/utils/RecommendationUtils.js +10 -6
- package/src/utils/Utils.d.ts +1 -0
- package/src/utils/Utils.js +4 -0
- package/tsconfig.json +7 -5
- package/App.tsx +0 -140
- package/index.ts +0 -6
- package/src/RecommendationScreen.tsx +0 -461
- package/src/__tests__/RecommendationScreen.test.tsx +0 -1231
- package/src/__tests__/RecommendationUtils.test.ts +0 -332
- package/src/__tests__/Translate.test.tsx +0 -31
- package/src/__tests__/Utils.test.ts +0 -91
- package/src/__tests__/Validations.test.ts +0 -648
- package/src/__tests__/components/Activity.test.tsx +0 -163
- package/src/__tests__/components/Emotion.test.tsx +0 -110
- package/src/__tests__/components/Header.test.tsx +0 -44
- package/src/__tests__/components/InfoBars.test.tsx +0 -152
- package/src/__tests__/components/InvisibleNumberInput.test.tsx +0 -294
- package/src/__tests__/components/LimitationMessage.test.tsx +0 -58
- package/src/__tests__/components/MoodIcon.test.tsx +0 -45
- package/src/__tests__/components/RecommendationModal.test.tsx +0 -169
- package/src/__tests__/components/RecommendedCarbs.test.tsx +0 -234
- package/src/__tests__/components/RecommendedInsulin.test.tsx +0 -241
- package/src/__tests__/components/Remeasure.test.tsx +0 -97
- package/src/__tests__/components/TransferToLogbook.test.tsx +0 -38
- package/src/__tests__/components/TwoOptionModal.test.tsx +0 -72
- package/src/__tests__/utils.tsx +0 -144
- package/src/components/Header.tsx +0 -89
- package/src/components/Icon.js +0 -41
- package/src/components/InfoBars.tsx +0 -108
- package/src/components/InvisibleNumberInput.tsx +0 -98
- package/src/components/LimitationMessage.tsx +0 -38
- package/src/components/LineSeparator.tsx +0 -24
- package/src/components/RecentInsulin.tsx +0 -101
- package/src/components/RecommendationModal.tsx +0 -224
- package/src/components/RecommendedCarbs.tsx +0 -259
- package/src/components/RecommendedInsulin.tsx +0 -175
- package/src/components/Remeasure.tsx +0 -120
- package/src/components/TransferToLogbook.tsx +0 -100
- package/src/components/TwoOptionModal.tsx +0 -185
- package/src/components/activity/Activity.tsx +0 -77
- package/src/components/activity/ActivityIcon.tsx +0 -54
- package/src/components/activity/ActivityIntensity.tsx +0 -58
- package/src/components/mood/Emotion.tsx +0 -66
- package/src/components/mood/MoodIcon.tsx +0 -60
- package/src/locale/CleanLanguage.ts +0 -13
- package/src/locale/i18nUtils.ts +0 -27
- package/src/types/enum.ts +0 -108
- package/src/types/types.ts +0 -16
- package/src/utils/AttentionMessages.tsx +0 -75
- package/src/utils/Constants.ts +0 -32
- package/src/utils/RecommendationError.tsx +0 -140
- package/src/utils/RecommendationUtils.ts +0 -125
- package/src/utils/Translations.ts +0 -9
- package/src/utils/Utils.ts +0 -57
- package/src/utils/Validations.ts +0 -245
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
3
|
-
|
|
4
|
-
import InvisibleNumberInput from "../../components/InvisibleNumberInput";
|
|
5
|
-
import RecommendedCarbs from "../../components/RecommendedCarbs";
|
|
6
|
-
import { RecommendedCarbsTestIds } from "../../types/enum";
|
|
7
|
-
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
8
|
-
|
|
9
|
-
describe(`Calculation Component`, (): void => {
|
|
10
|
-
afterEach(cleanup);
|
|
11
|
-
|
|
12
|
-
test(`calculate total carbs`, (): void => {
|
|
13
|
-
const removeMock = jest.fn();
|
|
14
|
-
const changeMock = jest.fn();
|
|
15
|
-
const newValue = 40;
|
|
16
|
-
const wrapper = render(
|
|
17
|
-
<RecommendedCarbs
|
|
18
|
-
enteredCarbs={`10`}
|
|
19
|
-
recommendedCarbs={`25`}
|
|
20
|
-
changedRecommendedCarbs={changeMock}
|
|
21
|
-
removeRecommendedCarbs={removeMock}
|
|
22
|
-
/>,
|
|
23
|
-
);
|
|
24
|
-
expectTextExists(wrapper, `Food`);
|
|
25
|
-
expectTextExists(wrapper, `Additional`);
|
|
26
|
-
expectTextExists(wrapper, `10`);
|
|
27
|
-
expectTextExists(wrapper, `25`);
|
|
28
|
-
expectTextExists(wrapper, `35`);
|
|
29
|
-
|
|
30
|
-
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
31
|
-
|
|
32
|
-
fireEvent(invisInput, `onEnd`, newValue);
|
|
33
|
-
expect(changeMock).toBeCalledWith(newValue);
|
|
34
|
-
|
|
35
|
-
wrapper.rerender(
|
|
36
|
-
<RecommendedCarbs
|
|
37
|
-
enteredCarbs={`10`}
|
|
38
|
-
recommendedCarbs={`${newValue}`}
|
|
39
|
-
changedRecommendedCarbs={changeMock}
|
|
40
|
-
removeRecommendedCarbs={removeMock}
|
|
41
|
-
/>,
|
|
42
|
-
);
|
|
43
|
-
expectTextExists(wrapper, `10`);
|
|
44
|
-
expectTextExists(wrapper, `${newValue}`);
|
|
45
|
-
expectTextExists(wrapper, `50`);
|
|
46
|
-
expectTextNotExists(wrapper, `35`);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test(`25 recommended carbs`, (): void => {
|
|
50
|
-
const removeMock = jest.fn();
|
|
51
|
-
const changeMock = jest.fn();
|
|
52
|
-
const wrapper = render(
|
|
53
|
-
<RecommendedCarbs
|
|
54
|
-
enteredCarbs={`0`}
|
|
55
|
-
recommendedCarbs={`25`}
|
|
56
|
-
changedRecommendedCarbs={changeMock}
|
|
57
|
-
removeRecommendedCarbs={removeMock}
|
|
58
|
-
/>,
|
|
59
|
-
);
|
|
60
|
-
expectTextExists(wrapper, `Food`);
|
|
61
|
-
expectTextExists(wrapper, `Additional`);
|
|
62
|
-
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test(`25.5 recommended carbs get rounded to 26`, (): void => {
|
|
66
|
-
const removeMock = jest.fn();
|
|
67
|
-
const changeMock = jest.fn();
|
|
68
|
-
const wrapper = render(
|
|
69
|
-
<RecommendedCarbs
|
|
70
|
-
enteredCarbs={`0`}
|
|
71
|
-
recommendedCarbs={`25.5`}
|
|
72
|
-
changedRecommendedCarbs={changeMock}
|
|
73
|
-
removeRecommendedCarbs={removeMock}
|
|
74
|
-
/>,
|
|
75
|
-
);
|
|
76
|
-
expectTextExists(wrapper, `Food`);
|
|
77
|
-
expectTextExists(wrapper, `Additional`);
|
|
78
|
-
expect(wrapper.getAllByText(`26`).length).toBe(2);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test(`Negative recommended carbs does not render 'recommended additional g carbs'`, (): void => {
|
|
82
|
-
const removeMock = jest.fn();
|
|
83
|
-
const changeMock = jest.fn();
|
|
84
|
-
const wrapper = render(
|
|
85
|
-
<RecommendedCarbs
|
|
86
|
-
enteredCarbs={`0`}
|
|
87
|
-
recommendedCarbs={`-25`}
|
|
88
|
-
changedRecommendedCarbs={changeMock}
|
|
89
|
-
removeRecommendedCarbs={removeMock}
|
|
90
|
-
/>,
|
|
91
|
-
);
|
|
92
|
-
expectTextExists(wrapper, `Food`);
|
|
93
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
94
|
-
expectTextNotExists(wrapper, `-25`);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test(`No recommended carbs does not render 'recommended additional g carbs'`, (): void => {
|
|
98
|
-
const removeMock = jest.fn();
|
|
99
|
-
const changeMock = jest.fn();
|
|
100
|
-
const wrapper = render(
|
|
101
|
-
<RecommendedCarbs
|
|
102
|
-
enteredCarbs={`0`}
|
|
103
|
-
changedRecommendedCarbs={changeMock}
|
|
104
|
-
removeRecommendedCarbs={removeMock}
|
|
105
|
-
/>,
|
|
106
|
-
);
|
|
107
|
-
expectTextExists(wrapper, `Food`);
|
|
108
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
test(`Editing recommended carbs`, (): void => {
|
|
112
|
-
const removeMock = jest.fn();
|
|
113
|
-
const changeMock = jest.fn();
|
|
114
|
-
const wrapper = render(
|
|
115
|
-
<RecommendedCarbs
|
|
116
|
-
enteredCarbs={`0`}
|
|
117
|
-
changedRecommendedCarbs={changeMock}
|
|
118
|
-
removeRecommendedCarbs={removeMock}
|
|
119
|
-
recommendedCarbs={`12`}
|
|
120
|
-
/>,
|
|
121
|
-
);
|
|
122
|
-
expectTextExists(wrapper, `Food`);
|
|
123
|
-
expectTextExists(wrapper, `Additional`);
|
|
124
|
-
expect(wrapper.getAllByText(`12`).length).toBe(2);
|
|
125
|
-
|
|
126
|
-
const carbButton = wrapper.getByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
127
|
-
fireEvent(carbButton, `onPress`);
|
|
128
|
-
|
|
129
|
-
expect(wrapper.getAllByText(`12`).length).toBe(2);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test(`Finished editing recommended carbs with carbs >= 0`, (): void => {
|
|
133
|
-
const removeMock = jest.fn();
|
|
134
|
-
const changeMock = jest.fn();
|
|
135
|
-
const wrapper = render(
|
|
136
|
-
<RecommendedCarbs
|
|
137
|
-
enteredCarbs={`0`}
|
|
138
|
-
changedRecommendedCarbs={changeMock}
|
|
139
|
-
removeRecommendedCarbs={removeMock}
|
|
140
|
-
recommendedCarbs={`12`}
|
|
141
|
-
/>,
|
|
142
|
-
);
|
|
143
|
-
expectTextExists(wrapper, `Food`);
|
|
144
|
-
expectTextExists(wrapper, `Additional`);
|
|
145
|
-
|
|
146
|
-
const carbButton = wrapper.getByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
147
|
-
|
|
148
|
-
fireEvent(carbButton, `onPress`);
|
|
149
|
-
|
|
150
|
-
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
151
|
-
|
|
152
|
-
fireEvent(invisInput, `onEndEditing`);
|
|
153
|
-
expect(changeMock).toBeCalledWith(Number(`12`));
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
test(`Negative recommendedCarbs removes recommendedCarbs render`, (): void => {
|
|
157
|
-
const removeMock = jest.fn();
|
|
158
|
-
const changeMock = jest.fn();
|
|
159
|
-
const wrapper = render(
|
|
160
|
-
<RecommendedCarbs
|
|
161
|
-
enteredCarbs={`0`}
|
|
162
|
-
changedRecommendedCarbs={changeMock}
|
|
163
|
-
removeRecommendedCarbs={removeMock}
|
|
164
|
-
recommendedCarbs={`-12`}
|
|
165
|
-
/>,
|
|
166
|
-
);
|
|
167
|
-
expectTextExists(wrapper, `Food`);
|
|
168
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
169
|
-
|
|
170
|
-
const carbButton = wrapper.queryByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
171
|
-
expect(carbButton).toBeNull();
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test(`Negative carbs doesn't invoke changedRecommendedCarbs callback`, (): void => {
|
|
175
|
-
const removeMock = jest.fn();
|
|
176
|
-
const changeMock = jest.fn();
|
|
177
|
-
const wrapper = render(
|
|
178
|
-
<RecommendedCarbs
|
|
179
|
-
enteredCarbs={`0`}
|
|
180
|
-
changedRecommendedCarbs={changeMock}
|
|
181
|
-
removeRecommendedCarbs={removeMock}
|
|
182
|
-
recommendedCarbs={`1`}
|
|
183
|
-
/>,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const numberInput = wrapper.UNSAFE_getByType(InvisibleNumberInput);
|
|
187
|
-
|
|
188
|
-
fireEvent(numberInput, `onEnd`, -12);
|
|
189
|
-
|
|
190
|
-
expect(removeMock).not.toBeCalled();
|
|
191
|
-
expect(changeMock).not.toBeCalled();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test(`Carb error limit is > 300`, (): void => {
|
|
195
|
-
const removeMock = jest.fn();
|
|
196
|
-
const changeMock = jest.fn();
|
|
197
|
-
const wrapper = render(
|
|
198
|
-
<RecommendedCarbs
|
|
199
|
-
enteredCarbs={`0`}
|
|
200
|
-
recommendedCarbs={`25`}
|
|
201
|
-
changedRecommendedCarbs={changeMock}
|
|
202
|
-
removeRecommendedCarbs={removeMock}
|
|
203
|
-
/>,
|
|
204
|
-
);
|
|
205
|
-
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
206
|
-
|
|
207
|
-
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
208
|
-
|
|
209
|
-
fireEvent(invisInput, `onEnd`, 302);
|
|
210
|
-
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
211
|
-
expectTextNotExists(wrapper, `302`);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
test(`Pressing on the remove button invokes the removeRecommendedCarbs callback`, (): void => {
|
|
215
|
-
const removeMock = jest.fn();
|
|
216
|
-
const changeMock = jest.fn();
|
|
217
|
-
const wrapper = render(
|
|
218
|
-
<RecommendedCarbs
|
|
219
|
-
enteredCarbs={`0`}
|
|
220
|
-
changedRecommendedCarbs={changeMock}
|
|
221
|
-
removeRecommendedCarbs={removeMock}
|
|
222
|
-
recommendedCarbs={`1`}
|
|
223
|
-
/>,
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
expect(removeMock).not.toBeCalled();
|
|
227
|
-
|
|
228
|
-
const removeButton = wrapper.getByA11yLabel(`removeRecommendedCarbs`);
|
|
229
|
-
|
|
230
|
-
fireEvent(removeButton, `onPress`);
|
|
231
|
-
|
|
232
|
-
expect(removeMock).toBeCalled();
|
|
233
|
-
});
|
|
234
|
-
});
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { BolusCalculator, UserSettings } from "@hedia/types";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { Platform } from "react-native";
|
|
4
|
-
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
5
|
-
import RecommendedInsulin from "../../components/RecommendedInsulin";
|
|
6
|
-
import { RecommendedInsulinTestIds } from "../../types/enum";
|
|
7
|
-
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
8
|
-
|
|
9
|
-
const SAFETY_INSULIN_LIMIT = BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
10
|
-
const InjectionMethod = UserSettings.Enums.InjectionMethod;
|
|
11
|
-
|
|
12
|
-
const { PenHalf, PenWhole, Pump } = InjectionMethod;
|
|
13
|
-
|
|
14
|
-
describe(`RecommendedInsulin - Component`, (): void => {
|
|
15
|
-
afterEach(cleanup);
|
|
16
|
-
|
|
17
|
-
test(`Component is rendered`, (): void => {
|
|
18
|
-
const updateMock = jest.fn();
|
|
19
|
-
const method: UserSettings.Enums.InjectionMethod = Pump;
|
|
20
|
-
const wrapper = render(
|
|
21
|
-
<RecommendedInsulin
|
|
22
|
-
insulinRecommendation={2.3}
|
|
23
|
-
updateRecommendedInsulin={updateMock}
|
|
24
|
-
injectionMethod={method}
|
|
25
|
-
activityReduction={null}
|
|
26
|
-
enteredInsulin={null}
|
|
27
|
-
/>,
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
31
|
-
expectTextExists(wrapper, `2.3`);
|
|
32
|
-
expectTextExists(wrapper, `Units`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test(`Insulin props defaults to 0`, (): void => {
|
|
36
|
-
const updateMock = jest.fn();
|
|
37
|
-
const method: UserSettings.Enums.InjectionMethod = PenHalf;
|
|
38
|
-
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
const wrapper = render(<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={method} />);
|
|
41
|
-
|
|
42
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
43
|
-
expectTextExists(wrapper, `0`);
|
|
44
|
-
expectTextExists(wrapper, `Units`);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test.each`
|
|
48
|
-
method | amount | result
|
|
49
|
-
${PenWhole} | ${1} | ${1}
|
|
50
|
-
${PenWhole} | ${1.49} | ${1}
|
|
51
|
-
${PenWhole} | ${1.5} | ${2}
|
|
52
|
-
${PenHalf} | ${1.24} | ${1}
|
|
53
|
-
${PenHalf} | ${1.25} | ${1.5}
|
|
54
|
-
${PenHalf} | ${1.74} | ${1.5}
|
|
55
|
-
${Pump} | ${1.14} | ${1.1}
|
|
56
|
-
${Pump} | ${1.15} | ${1.2}
|
|
57
|
-
${Pump} | ${12.35} | ${12.4}
|
|
58
|
-
`(
|
|
59
|
-
`Rounding $amount using $method to $result`,
|
|
60
|
-
({
|
|
61
|
-
amount,
|
|
62
|
-
method,
|
|
63
|
-
result,
|
|
64
|
-
}: {
|
|
65
|
-
method: UserSettings.Enums.InjectionMethod;
|
|
66
|
-
amount: number;
|
|
67
|
-
result: number;
|
|
68
|
-
}): void => {
|
|
69
|
-
const updateMock = jest.fn();
|
|
70
|
-
const wrapper = render(
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={method} />,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
76
|
-
|
|
77
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
78
|
-
|
|
79
|
-
fireEvent(input, `onEnd`, amount);
|
|
80
|
-
expectTextExists(wrapper, `${result}`);
|
|
81
|
-
expect(updateMock).toBeCalledWith(result);
|
|
82
|
-
},
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
test(`Throw error on Unsupported InjectMethod`, (): void => {
|
|
86
|
-
const updateMock = jest.fn();
|
|
87
|
-
|
|
88
|
-
const wrapper = render(
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
<RecommendedInsulin
|
|
91
|
-
updateRecommendedInsulin={updateMock}
|
|
92
|
-
injectionMethod={`Error` as UserSettings.Enums.InjectionMethod}
|
|
93
|
-
/>,
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
97
|
-
|
|
98
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
99
|
-
|
|
100
|
-
expect((): void => fireEvent(input, `onEnd`)).toThrowError(`Unsupported InjectionMethod: Error`);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test.each`
|
|
104
|
-
value | result
|
|
105
|
-
${0.0} | ${0}
|
|
106
|
-
${0.1} | ${0.1}
|
|
107
|
-
`(`Will not remove leading zero from $value`, ({ result, value }: { value: number; result: number }): void => {
|
|
108
|
-
const updateMock = jest.fn();
|
|
109
|
-
const wrapper = render(
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump} />,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
115
|
-
|
|
116
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
117
|
-
fireEvent(input, `onEnd`, value);
|
|
118
|
-
expectTextExists(wrapper, `${result}`);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test.each`
|
|
122
|
-
value | result
|
|
123
|
-
${`09`} | ${9}
|
|
124
|
-
${`09.1`} | ${9.1}
|
|
125
|
-
`(`Will remove leading zero from $value`, ({ result, value }: { value: string; result: number }): void => {
|
|
126
|
-
const updateMock = jest.fn();
|
|
127
|
-
const wrapper = render(
|
|
128
|
-
// @ts-ignore
|
|
129
|
-
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump} />,
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
133
|
-
|
|
134
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
135
|
-
fireEvent(input, `partialInput`, value);
|
|
136
|
-
expectTextExists(wrapper, `${result}`);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test(`Pressing on TouchableOpacity will callback on the invisible text input`, (): void => {
|
|
140
|
-
const updateMock = jest.fn();
|
|
141
|
-
const wrapper = render(
|
|
142
|
-
// @ts-ignore
|
|
143
|
-
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump} />,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
147
|
-
|
|
148
|
-
const button = wrapper.getByTestId(RecommendedInsulinTestIds.EditRecommendedInsulin);
|
|
149
|
-
|
|
150
|
-
fireEvent(button, `onPress`);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test.each`
|
|
154
|
-
value | reduction | isCorrect
|
|
155
|
-
${`50`} | ${0} | ${true}
|
|
156
|
-
${`51`} | ${0} | ${false}
|
|
157
|
-
${`24`} | ${0.5} | ${true}
|
|
158
|
-
${`26`} | ${0.5} | ${false}
|
|
159
|
-
${`10`} | ${0.75} | ${true}
|
|
160
|
-
${`15`} | ${0.75} | ${false}
|
|
161
|
-
`(
|
|
162
|
-
`Throws an error at insulin limits`,
|
|
163
|
-
({ reduction, isCorrect, value }: { value: string; reduction: number; isCorrect: boolean }): void => {
|
|
164
|
-
const updateMock = jest.fn();
|
|
165
|
-
const wrapper = render(
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
<RecommendedInsulin
|
|
168
|
-
activityReduction={reduction}
|
|
169
|
-
updateRecommendedInsulin={updateMock}
|
|
170
|
-
injectionMethod={Pump}
|
|
171
|
-
/>,
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
175
|
-
|
|
176
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
177
|
-
fireEvent(input, `onEnd`, value);
|
|
178
|
-
|
|
179
|
-
if (isCorrect) {
|
|
180
|
-
expectTextExists(wrapper, value);
|
|
181
|
-
} else {
|
|
182
|
-
expectTextNotExists(wrapper, value);
|
|
183
|
-
expectTextNotExists(wrapper, `OK`);
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
test.each`
|
|
189
|
-
reduction | expected | reductionPercent
|
|
190
|
-
${null} | ${SAFETY_INSULIN_LIMIT * (1 - 0)} | ${`${0 * 100}%`}
|
|
191
|
-
${undefined} | ${SAFETY_INSULIN_LIMIT * (1 - 0)} | ${`${0 * 100}%`}
|
|
192
|
-
${0} | ${SAFETY_INSULIN_LIMIT * (1 - 0)} | ${`${0 * 100}%`}
|
|
193
|
-
${0.1} | ${SAFETY_INSULIN_LIMIT * (1 - 0.1)} | ${`${0.1 * 100}%`}
|
|
194
|
-
${0.25} | ${SAFETY_INSULIN_LIMIT * (1 - 0.25)} | ${`${0.25 * 100}%`}
|
|
195
|
-
${0.5} | ${SAFETY_INSULIN_LIMIT * (1 - 0.5)} | ${`${0.5 * 100}%`}
|
|
196
|
-
${0.75} | ${SAFETY_INSULIN_LIMIT * (1 - 0.75)} | ${`${0.75 * 100}%`}
|
|
197
|
-
${0.9} | ${SAFETY_INSULIN_LIMIT * (1 - 0.9)} | ${`${0.9 * 100}%`}
|
|
198
|
-
`(
|
|
199
|
-
`Recommendation is limited when entering over the maximum safety threshold of insulin when activity reduction is $reductionPercent`,
|
|
200
|
-
({ expected, reduction }: { reduction: number; expected: number }): void => {
|
|
201
|
-
const updateMock = jest.fn();
|
|
202
|
-
|
|
203
|
-
const wrapper = render(
|
|
204
|
-
<RecommendedInsulin
|
|
205
|
-
insulinRecommendation={expected}
|
|
206
|
-
updateRecommendedInsulin={updateMock}
|
|
207
|
-
injectionMethod={Pump}
|
|
208
|
-
activityReduction={reduction}
|
|
209
|
-
enteredInsulin={null}
|
|
210
|
-
/>,
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
214
|
-
const INVALID_INSULIN = SAFETY_INSULIN_LIMIT + 1;
|
|
215
|
-
|
|
216
|
-
fireEvent(input, `onEnd`, INVALID_INSULIN);
|
|
217
|
-
|
|
218
|
-
expect(updateMock).toBeCalledWith(expected);
|
|
219
|
-
},
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
interface IPlatformPadding {
|
|
223
|
-
platform: `ios` | `android` | `windows` | `macos` | `web`;
|
|
224
|
-
padding: string;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
test.each`
|
|
228
|
-
platform | padding
|
|
229
|
-
${`ios`} | ${`3%`}
|
|
230
|
-
${`android`} | ${`1%`}
|
|
231
|
-
`(`On $platform the component has $padding paddingBottom`, ({ padding, platform }: IPlatformPadding): void => {
|
|
232
|
-
Platform.OS = platform;
|
|
233
|
-
|
|
234
|
-
const updateMock = jest.fn();
|
|
235
|
-
const wrapper = render(
|
|
236
|
-
// @ts-ignore
|
|
237
|
-
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump} />,
|
|
238
|
-
);
|
|
239
|
-
expect(!!new RegExp(`"paddingBottom":"${padding}"`).exec(JSON.stringify(wrapper.toJSON()))).toBeTruthy();
|
|
240
|
-
});
|
|
241
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Platform } from "react-native";
|
|
3
|
-
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
4
|
-
import Remeasure from "../../components/Remeasure";
|
|
5
|
-
import { RemeasureTestIds } from "../../types/enum";
|
|
6
|
-
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
7
|
-
|
|
8
|
-
describe(`Remeasure Component`, (): void => {
|
|
9
|
-
afterEach(cleanup);
|
|
10
|
-
|
|
11
|
-
test.each`
|
|
12
|
-
value | expected
|
|
13
|
-
${0} | ${`OFF`}
|
|
14
|
-
${1} | ${`1`}
|
|
15
|
-
${1.0} | ${`1`}
|
|
16
|
-
${2.3} | ${`2.3`}
|
|
17
|
-
${3.8} | ${`3.8`}
|
|
18
|
-
`(
|
|
19
|
-
`Setting slider to $value displays $expected`,
|
|
20
|
-
({ value, expected }: { value: number; expected: string }): void => {
|
|
21
|
-
const onChange = jest.fn();
|
|
22
|
-
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange} />);
|
|
23
|
-
expectTextExists(wrapper, `1.5`);
|
|
24
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
25
|
-
|
|
26
|
-
fireEvent(slider, `onValueChange`, value);
|
|
27
|
-
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange} />);
|
|
28
|
-
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
29
|
-
expectTextNotExists(wrapper, `1.5`);
|
|
30
|
-
expectTextExists(wrapper, expected);
|
|
31
|
-
expect(onChange).toBeCalledWith(value);
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
test.each`
|
|
36
|
-
value | expected | callbackValue
|
|
37
|
-
${0} | ${`OFF`} | ${0}
|
|
38
|
-
${-0.1} | ${`OFF`} | ${0}
|
|
39
|
-
${-100} | ${`OFF`} | ${0}
|
|
40
|
-
${4.5} | ${`4.5`} | ${4.5}
|
|
41
|
-
${6.1} | ${`6`} | ${6}
|
|
42
|
-
${6.5} | ${`6`} | ${6}
|
|
43
|
-
${12} | ${`6`} | ${6}
|
|
44
|
-
${55} | ${`6`} | ${6}
|
|
45
|
-
`(
|
|
46
|
-
`Setting slider to edge-case $value displays $expected`,
|
|
47
|
-
({ value, expected, callbackValue }: { value: number; expected: string; callbackValue: number }): void => {
|
|
48
|
-
const onChange = jest.fn();
|
|
49
|
-
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange} />);
|
|
50
|
-
expectTextExists(wrapper, `1.5`);
|
|
51
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
52
|
-
|
|
53
|
-
fireEvent(slider, `onValueChange`, value);
|
|
54
|
-
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange} />);
|
|
55
|
-
expectTextNotExists(wrapper, `1.5`);
|
|
56
|
-
expectTextExists(wrapper, expected);
|
|
57
|
-
if (isNaN(Number(expected))) {
|
|
58
|
-
expectTextNotExists(wrapper, `hours`);
|
|
59
|
-
} else {
|
|
60
|
-
expectTextExists(wrapper, `hours`);
|
|
61
|
-
}
|
|
62
|
-
expect(onChange).toBeCalledWith(callbackValue);
|
|
63
|
-
},
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
test(`Setting it to default 1.5 still calls callback function`, (): void => {
|
|
67
|
-
const value = 1.5;
|
|
68
|
-
const expected = `1.5`;
|
|
69
|
-
const onChange = jest.fn();
|
|
70
|
-
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange} />);
|
|
71
|
-
expectTextExists(wrapper, `1.5`);
|
|
72
|
-
|
|
73
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
74
|
-
|
|
75
|
-
fireEvent(slider, `onValueChange`, value);
|
|
76
|
-
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange} />);
|
|
77
|
-
|
|
78
|
-
expectTextExists(wrapper, expected);
|
|
79
|
-
expect(onChange).toBeCalledWith(value);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test.each`
|
|
83
|
-
platform | margin
|
|
84
|
-
${`ios`} | ${`3%`}
|
|
85
|
-
${`android`} | ${`0%`}
|
|
86
|
-
`(
|
|
87
|
-
`On $platform the slider has $margin marginHorizontal`,
|
|
88
|
-
({ margin, platform }: { platform: `ios` | `android` | `windows` | `macos` | `web`; margin: string }): void => {
|
|
89
|
-
Platform.OS = platform;
|
|
90
|
-
const onChange = jest.fn();
|
|
91
|
-
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange} />);
|
|
92
|
-
expect(
|
|
93
|
-
!!new RegExp(`RNCSlider",.*marginHorizontal":"${margin}"`).exec(JSON.stringify(wrapper.toJSON())),
|
|
94
|
-
).toBeTruthy();
|
|
95
|
-
},
|
|
96
|
-
);
|
|
97
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { fireEvent, render } from "react-native-testing-library";
|
|
3
|
-
import TransferToLogbook from "../../components/TransferToLogbook";
|
|
4
|
-
import { TransferToLogbookTestIds } from "../../types/enum";
|
|
5
|
-
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
6
|
-
|
|
7
|
-
describe(`TransferToLogbook - Component`, (): void => {
|
|
8
|
-
test(`Is null when visible not visible`, (): void => {
|
|
9
|
-
const transferMock = jest.fn();
|
|
10
|
-
const wrapper = render(<TransferToLogbook visible={false} transfer={transferMock} />);
|
|
11
|
-
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
12
|
-
expect(transferMock).not.toBeCalled();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test(`Mounts with "transfer to logbook" text when visible`, (): void => {
|
|
16
|
-
const transferMock = jest.fn();
|
|
17
|
-
const wrapper = render(<TransferToLogbook visible={true} transfer={transferMock} />);
|
|
18
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
19
|
-
expect(transferMock).not.toBeCalled();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test(`Pressing the button will trigger the callback`, (): void => {
|
|
23
|
-
const transferMock = jest.fn();
|
|
24
|
-
const wrapper = render(<TransferToLogbook visible={true} transfer={transferMock} />);
|
|
25
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
26
|
-
|
|
27
|
-
const button = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
28
|
-
|
|
29
|
-
expect(transferMock).not.toBeCalled();
|
|
30
|
-
|
|
31
|
-
fireEvent(button, `onPress`);
|
|
32
|
-
|
|
33
|
-
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
34
|
-
expectTextExists(wrapper, `Transferred to logbook`);
|
|
35
|
-
|
|
36
|
-
expect(transferMock).toBeCalled();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
3
|
-
import TwoOptionModal, { ITwoOptionModalProps } from "../../components/TwoOptionModal";
|
|
4
|
-
import { TwoOptionModalTestIds } from "../../types/enum";
|
|
5
|
-
import { expectTextExists } from "../utils";
|
|
6
|
-
|
|
7
|
-
describe(`TwoOptionModal Component`, (): void => {
|
|
8
|
-
afterEach(cleanup);
|
|
9
|
-
|
|
10
|
-
test(`Can can show text `, (): void => {
|
|
11
|
-
const props: ITwoOptionModalProps = {
|
|
12
|
-
firstOption: jest.fn(),
|
|
13
|
-
secondOption: jest.fn(),
|
|
14
|
-
onClose: jest.fn(),
|
|
15
|
-
rowAsButtonLayout: true,
|
|
16
|
-
textFirstOption: `Gem i logbog`,
|
|
17
|
-
message: `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`,
|
|
18
|
-
textSecondOption: `Luk beregning`,
|
|
19
|
-
title: `Vil du gemme din indtastning?`,
|
|
20
|
-
};
|
|
21
|
-
const wrapper = render(<TwoOptionModal {...props} />);
|
|
22
|
-
expectTextExists(wrapper, `Luk beregning`);
|
|
23
|
-
expectTextExists(wrapper, `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`);
|
|
24
|
-
expectTextExists(wrapper, `Gem i logbog`);
|
|
25
|
-
expectTextExists(wrapper, `Vil du gemme din indtastning?`);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test(`Test that callbacks are called`, (): void => {
|
|
29
|
-
const props: ITwoOptionModalProps = {
|
|
30
|
-
firstOption: jest.fn(),
|
|
31
|
-
secondOption: jest.fn(),
|
|
32
|
-
onClose: jest.fn(),
|
|
33
|
-
rowAsButtonLayout: true,
|
|
34
|
-
isCancelable: true,
|
|
35
|
-
textFirstOption: `Gem i logbog`,
|
|
36
|
-
message: `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`,
|
|
37
|
-
textSecondOption: `Luk beregning`,
|
|
38
|
-
title: `Vil du gemme din indtastning?`,
|
|
39
|
-
};
|
|
40
|
-
const wrapper = render(<TwoOptionModal {...props} />);
|
|
41
|
-
expectTextExists(wrapper, `Luk beregning`);
|
|
42
|
-
|
|
43
|
-
const modalExitIcon = wrapper.getByTestId(TwoOptionModalTestIds.ExitButton);
|
|
44
|
-
fireEvent(modalExitIcon, `onPress`);
|
|
45
|
-
expect(props.onClose).toBeCalled();
|
|
46
|
-
|
|
47
|
-
const closeCalculation = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
48
|
-
fireEvent(closeCalculation, `onPress`);
|
|
49
|
-
expect(props.secondOption).toBeCalled();
|
|
50
|
-
|
|
51
|
-
const firstOptionButton = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
52
|
-
fireEvent(firstOptionButton, `onPress`);
|
|
53
|
-
expect(props.firstOption).toBeCalled();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test(`Test it is not cancelable`, (): void => {
|
|
57
|
-
const props: ITwoOptionModalProps = {
|
|
58
|
-
firstOption: jest.fn(),
|
|
59
|
-
secondOption: jest.fn(),
|
|
60
|
-
rowAsButtonLayout: true,
|
|
61
|
-
textFirstOption: `Gem i logbog`,
|
|
62
|
-
message: `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`,
|
|
63
|
-
textSecondOption: `Luk beregning`,
|
|
64
|
-
title: `Vil du gemme din indtastning?`,
|
|
65
|
-
};
|
|
66
|
-
const wrapper = render(<TwoOptionModal {...props} />);
|
|
67
|
-
expectTextExists(wrapper, `Luk beregning`);
|
|
68
|
-
|
|
69
|
-
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
70
|
-
expect(modalExitIcon).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
});
|