@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,1231 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Activity,
|
|
3
|
-
BloodGlucoseUnit,
|
|
4
|
-
BloodKetonesUnit,
|
|
5
|
-
BolusCalculator,
|
|
6
|
-
Languages,
|
|
7
|
-
Logbook,
|
|
8
|
-
Milliseconds,
|
|
9
|
-
UserSettings,
|
|
10
|
-
} from "@hedia/types";
|
|
11
|
-
import React from "react";
|
|
12
|
-
import { AppStateEvent, AppStateStatus } from "react-native";
|
|
13
|
-
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
14
|
-
import { i18n } from "../locale/i18nUtils";
|
|
15
|
-
import RecommendationScreen, { IRecommendationProps } from "../RecommendationScreen";
|
|
16
|
-
import {
|
|
17
|
-
HeaderTestIds,
|
|
18
|
-
LimitationMessageTestIds,
|
|
19
|
-
RecentInsulinTestIds,
|
|
20
|
-
RecommendationModalTestIds,
|
|
21
|
-
RecommendationReminders,
|
|
22
|
-
RecommendedCarbsTestIds,
|
|
23
|
-
RecommendedInsulinTestIds,
|
|
24
|
-
RemeasureTestIds,
|
|
25
|
-
TransferToLogbookTestIds,
|
|
26
|
-
TwoOptionModalTestIds,
|
|
27
|
-
} from "../types/enum";
|
|
28
|
-
import { IRecommendationParams } from "../types/types";
|
|
29
|
-
import { Messages } from "../utils/AttentionMessages";
|
|
30
|
-
import { LanguageError } from "../utils/RecommendationError";
|
|
31
|
-
import { ActivityIntensityTranslations } from "../utils/Translations";
|
|
32
|
-
import { Utils } from "../utils/Utils";
|
|
33
|
-
import {
|
|
34
|
-
expectTextExists,
|
|
35
|
-
expectTextNotExists,
|
|
36
|
-
generateActivityProps,
|
|
37
|
-
generateDefaultCalculatorParams,
|
|
38
|
-
getIcon,
|
|
39
|
-
getRecommendationProps,
|
|
40
|
-
queryTextFromComponent,
|
|
41
|
-
} from "./utils";
|
|
42
|
-
|
|
43
|
-
const ActivityIntensity = Activity.Enums.ActivityIntensity;
|
|
44
|
-
const ActivityEnum = Activity.Enums.ActivityEnum;
|
|
45
|
-
const InjectionMethod = UserSettings.Enums.InjectionMethod;
|
|
46
|
-
const MoodEnum = Logbook.Enums.MoodEnum;
|
|
47
|
-
|
|
48
|
-
const { light, moderate, hard } = ActivityIntensity;
|
|
49
|
-
|
|
50
|
-
interface IMockAppState {
|
|
51
|
-
addEventListener: jest.Mock;
|
|
52
|
-
removeEventListener(): void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
describe(`RecommendationScreen`, (): void => {
|
|
56
|
-
jest.useFakeTimers();
|
|
57
|
-
|
|
58
|
-
beforeEach((): void => {
|
|
59
|
-
i18n.activate(Languages.en);
|
|
60
|
-
global.Date.now = (): number => 1;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
afterEach((): void => {
|
|
64
|
-
cleanup();
|
|
65
|
-
global.Date.now = (): number => new Date().getTime();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test(`25 recommended carbs - No edit`, (): void => {
|
|
69
|
-
const props = getRecommendationProps({
|
|
70
|
-
calculatorParams: {
|
|
71
|
-
currentBGL: 1.1,
|
|
72
|
-
carbohydrates: 25,
|
|
73
|
-
carbohydrateRatio: 22,
|
|
74
|
-
insulinSensitivity: 5,
|
|
75
|
-
targetBGL: 7,
|
|
76
|
-
recentBoluses: [],
|
|
77
|
-
activity: null,
|
|
78
|
-
},
|
|
79
|
-
userReminder: 5,
|
|
80
|
-
});
|
|
81
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
82
|
-
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
83
|
-
|
|
84
|
-
fireEvent(okButton, `onPress`);
|
|
85
|
-
|
|
86
|
-
expectTextExists(wrapper, `Food`);
|
|
87
|
-
expectTextExists(wrapper, `Additional`);
|
|
88
|
-
expectTextExists(wrapper, `1`);
|
|
89
|
-
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
90
|
-
expectTextExists(wrapper, `0.25`);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test(`25 recommended carbs - editing`, (): void => {
|
|
94
|
-
const props = getRecommendationProps({
|
|
95
|
-
calculatorParams: {
|
|
96
|
-
...getRecommendationProps().calculatorParams,
|
|
97
|
-
currentBGL: 2.2,
|
|
98
|
-
recentBoluses: [],
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
102
|
-
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
103
|
-
|
|
104
|
-
fireEvent(okButton, `onPress`);
|
|
105
|
-
|
|
106
|
-
expectTextExists(wrapper, `Food`);
|
|
107
|
-
expectTextExists(wrapper, `Additional`);
|
|
108
|
-
expectTextExists(wrapper, `5`);
|
|
109
|
-
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
110
|
-
expectTextExists(wrapper, `0.25`);
|
|
111
|
-
|
|
112
|
-
const textInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
113
|
-
|
|
114
|
-
fireEvent(textInput, `onChangeText`, `85`);
|
|
115
|
-
|
|
116
|
-
expectTextNotExists(wrapper, `6`);
|
|
117
|
-
expectTextExists(wrapper, `85`);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test(`No recommended carbs`, (): void => {
|
|
121
|
-
const props = getRecommendationProps({
|
|
122
|
-
calculatorParams: {
|
|
123
|
-
currentBGL: 11,
|
|
124
|
-
carbohydrates: 25,
|
|
125
|
-
carbohydrateRatio: 22,
|
|
126
|
-
insulinSensitivity: 5,
|
|
127
|
-
targetBGL: 7,
|
|
128
|
-
recentBoluses: [],
|
|
129
|
-
activity: null,
|
|
130
|
-
},
|
|
131
|
-
userReminder: 6,
|
|
132
|
-
});
|
|
133
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
134
|
-
const okayButton = wrapper.getByTestId(RecommendationModalTestIds.OkButton);
|
|
135
|
-
|
|
136
|
-
fireEvent(okayButton, `onPress`);
|
|
137
|
-
|
|
138
|
-
expectTextExists(wrapper, `Food`);
|
|
139
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
140
|
-
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
141
|
-
expectTextExists(wrapper, `6`);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
test(`No recommended carbs under 0.5`, (): void => {
|
|
145
|
-
const props = getRecommendationProps({
|
|
146
|
-
calculatorParams: {
|
|
147
|
-
currentBGL: 6.9,
|
|
148
|
-
carbohydrates: 25,
|
|
149
|
-
carbohydrateRatio: 1,
|
|
150
|
-
insulinSensitivity: 5,
|
|
151
|
-
targetBGL: 7,
|
|
152
|
-
recentBoluses: [],
|
|
153
|
-
activity: null,
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
157
|
-
|
|
158
|
-
expectTextExists(wrapper, `Food`);
|
|
159
|
-
expectTextNotExists(wrapper, `Recommended`);
|
|
160
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test(`Remove recommended carbs`, (): void => {
|
|
164
|
-
const props = getRecommendationProps({
|
|
165
|
-
calculatorParams: {
|
|
166
|
-
currentBGL: 1.1,
|
|
167
|
-
carbohydrates: 25,
|
|
168
|
-
carbohydrateRatio: 22,
|
|
169
|
-
insulinSensitivity: 5,
|
|
170
|
-
targetBGL: 7,
|
|
171
|
-
recentBoluses: [],
|
|
172
|
-
activity: null,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
176
|
-
|
|
177
|
-
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
178
|
-
|
|
179
|
-
fireEvent(okButton, `onPress`);
|
|
180
|
-
|
|
181
|
-
expectTextExists(wrapper, `Food`);
|
|
182
|
-
expectTextExists(wrapper, `Additional`);
|
|
183
|
-
expectTextExists(wrapper, `1`);
|
|
184
|
-
|
|
185
|
-
const removeButton = wrapper.getByTestId(RecommendedCarbsTestIds.RemoveRecommendation);
|
|
186
|
-
|
|
187
|
-
fireEvent(removeButton, `onPress`);
|
|
188
|
-
|
|
189
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
190
|
-
expectTextNotExists(wrapper, `1`);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test(`Update remeasureTime to number > 0`, (): void => {
|
|
194
|
-
const props = getRecommendationProps();
|
|
195
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
196
|
-
|
|
197
|
-
expectTextExists(wrapper, `hours`);
|
|
198
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
199
|
-
|
|
200
|
-
fireEvent(slider, `onValueChange`, 3.2);
|
|
201
|
-
expectTextExists(wrapper, `3.2`);
|
|
202
|
-
expectTextExists(wrapper, `hours`);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test(`Update remeasureTime to 0`, (): void => {
|
|
206
|
-
const props = getRecommendationProps();
|
|
207
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
208
|
-
|
|
209
|
-
expectTextExists(wrapper, `hours`);
|
|
210
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
211
|
-
|
|
212
|
-
fireEvent(slider, `onValueChange`, 0);
|
|
213
|
-
expectTextExists(wrapper, `OFF`);
|
|
214
|
-
expectTextNotExists(wrapper, `hours`);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
test(`Callback envoked when pressing 'Yes' on 'Recent Insulin'`, (): void => {
|
|
218
|
-
const props = getRecommendationProps({
|
|
219
|
-
calculatorParams: {
|
|
220
|
-
...getRecommendationProps().calculatorParams,
|
|
221
|
-
recentBoluses: [],
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
225
|
-
|
|
226
|
-
expect(props.onRecentInsulinYes).not.toBeCalled();
|
|
227
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
228
|
-
const button = wrapper.getByTestId(RecentInsulinTestIds.Yes);
|
|
229
|
-
|
|
230
|
-
fireEvent(button, `onPress`);
|
|
231
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
232
|
-
expect(props.onRecentInsulinYes).toBeCalled();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
test(`Remove 'Recent Insulin' by pressing 'No'`, (): void => {
|
|
236
|
-
const props = getRecommendationProps({
|
|
237
|
-
calculatorParams: {
|
|
238
|
-
...getRecommendationProps().calculatorParams,
|
|
239
|
-
recentBoluses: [],
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
243
|
-
|
|
244
|
-
expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
245
|
-
const button = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
246
|
-
|
|
247
|
-
fireEvent(button, `onPress`);
|
|
248
|
-
|
|
249
|
-
expectTextNotExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
250
|
-
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
251
|
-
expectTextExists(wrapper, `Units`);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
test(`Selecting neutral will set neutral to active`, (): void => {
|
|
255
|
-
const props = getRecommendationProps();
|
|
256
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
257
|
-
|
|
258
|
-
const neutral = MoodEnum[MoodEnum.Neutral];
|
|
259
|
-
|
|
260
|
-
const icon = getIcon(wrapper, neutral, false);
|
|
261
|
-
|
|
262
|
-
if (icon === null) {
|
|
263
|
-
return fail(`No icon found for queryByA11yLabel: ${neutral}_${false}`);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
fireEvent(icon, `onPress`);
|
|
267
|
-
|
|
268
|
-
expect(getIcon(wrapper, neutral, false)).toBeNull();
|
|
269
|
-
expect(getIcon(wrapper, neutral, true)).not.toBeNull();
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test(`Updating carb recommendation & transfer`, (): void => {
|
|
273
|
-
const result: {
|
|
274
|
-
carbs?: {
|
|
275
|
-
entered: number | null;
|
|
276
|
-
suggested: number;
|
|
277
|
-
};
|
|
278
|
-
insulin?: {
|
|
279
|
-
entered?: number | null;
|
|
280
|
-
suggested: number;
|
|
281
|
-
};
|
|
282
|
-
reminder?: number;
|
|
283
|
-
} = {};
|
|
284
|
-
|
|
285
|
-
const props = getRecommendationProps({
|
|
286
|
-
calculatorParams: {
|
|
287
|
-
currentBGL: 1.1,
|
|
288
|
-
carbohydrates: 25,
|
|
289
|
-
carbohydrateRatio: 22,
|
|
290
|
-
insulinSensitivity: 5,
|
|
291
|
-
targetBGL: 7,
|
|
292
|
-
recentBoluses: [],
|
|
293
|
-
activity: null,
|
|
294
|
-
},
|
|
295
|
-
transferToLogbook: jest.fn((carbs, insulin, reminder): void => {
|
|
296
|
-
result.carbs = carbs;
|
|
297
|
-
result.insulin = insulin;
|
|
298
|
-
result.reminder = reminder;
|
|
299
|
-
}),
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
const carbsExpected = {
|
|
303
|
-
entered: 3,
|
|
304
|
-
suggested: 1,
|
|
305
|
-
};
|
|
306
|
-
const insulinExpected = {
|
|
307
|
-
entered: null,
|
|
308
|
-
suggested: 0,
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
312
|
-
|
|
313
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`25`);
|
|
314
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`1`);
|
|
315
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`26`);
|
|
316
|
-
// Expect text from carbs -> change -> Expect text updated -> Transfer -> Expect callback
|
|
317
|
-
|
|
318
|
-
const carbInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
319
|
-
|
|
320
|
-
// Input 3 into the carbs field
|
|
321
|
-
fireEvent(carbInput, `onEnd`, carbsExpected.entered);
|
|
322
|
-
|
|
323
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`25`);
|
|
324
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`3`);
|
|
325
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`28`);
|
|
326
|
-
|
|
327
|
-
// To make the transfer button visible we need to press the "no" option
|
|
328
|
-
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
329
|
-
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
330
|
-
|
|
331
|
-
fireEvent(noButton, `onPress`);
|
|
332
|
-
|
|
333
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
334
|
-
|
|
335
|
-
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
336
|
-
|
|
337
|
-
// Press transfer
|
|
338
|
-
fireEvent(transfer, `onPress`);
|
|
339
|
-
|
|
340
|
-
expect(props.transferToLogbook).toBeCalled();
|
|
341
|
-
expect(result.carbs?.entered).toBeCloseTo(carbsExpected.entered, 1);
|
|
342
|
-
expect(result.carbs?.suggested).toBeCloseTo(carbsExpected.suggested, 1);
|
|
343
|
-
expect(result.insulin?.entered).toBe(insulinExpected.entered);
|
|
344
|
-
expect(result.insulin?.suggested).toBeCloseTo(insulinExpected.suggested, 1);
|
|
345
|
-
expect(result.reminder).toBe(RecommendationReminders.Reminder15Minutes);
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
test(`Removing carb recommendation still returns suggested in transfer`, (): void => {
|
|
349
|
-
const result: {
|
|
350
|
-
carbs?: {
|
|
351
|
-
entered: number | null;
|
|
352
|
-
suggested: number;
|
|
353
|
-
};
|
|
354
|
-
insulin?: {
|
|
355
|
-
entered: number | null;
|
|
356
|
-
suggested: number;
|
|
357
|
-
};
|
|
358
|
-
reminder?: number;
|
|
359
|
-
} = {};
|
|
360
|
-
|
|
361
|
-
const props = getRecommendationProps({
|
|
362
|
-
calculatorParams: {
|
|
363
|
-
currentBGL: 1.1,
|
|
364
|
-
carbohydrates: 25,
|
|
365
|
-
carbohydrateRatio: 22,
|
|
366
|
-
insulinSensitivity: 5,
|
|
367
|
-
targetBGL: 7,
|
|
368
|
-
recentBoluses: [],
|
|
369
|
-
activity: null,
|
|
370
|
-
},
|
|
371
|
-
transferToLogbook: jest.fn((carbs, insulin, reminder): void => {
|
|
372
|
-
result.carbs = carbs;
|
|
373
|
-
result.insulin = insulin;
|
|
374
|
-
result.reminder = reminder;
|
|
375
|
-
}),
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
const carbsExpected = {
|
|
379
|
-
entered: null,
|
|
380
|
-
suggested: 1,
|
|
381
|
-
};
|
|
382
|
-
const insulinExpected = {
|
|
383
|
-
entered: null,
|
|
384
|
-
suggested: 0,
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
388
|
-
|
|
389
|
-
// Expect text from carbs -> change -> Expect text updated -> Transfer -> Expect callback
|
|
390
|
-
expectTextExists(wrapper, `1`);
|
|
391
|
-
|
|
392
|
-
const removeButton = wrapper.getByTestId(RecommendedCarbsTestIds.RemoveRecommendation);
|
|
393
|
-
|
|
394
|
-
// Input 3 into the carbs field
|
|
395
|
-
fireEvent(removeButton, `onPress`);
|
|
396
|
-
|
|
397
|
-
// Expect text updated
|
|
398
|
-
expectTextNotExists(wrapper, `1`);
|
|
399
|
-
|
|
400
|
-
// To make the transfer button visible we need to press the "no" option
|
|
401
|
-
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
402
|
-
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
403
|
-
|
|
404
|
-
fireEvent(noButton, `onPress`);
|
|
405
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
406
|
-
|
|
407
|
-
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
408
|
-
|
|
409
|
-
// Press transfer
|
|
410
|
-
fireEvent(transfer, `onPress`);
|
|
411
|
-
|
|
412
|
-
expect(props.transferToLogbook).toBeCalled();
|
|
413
|
-
expect(result.carbs!.entered).toBe(carbsExpected.entered);
|
|
414
|
-
expect(result.carbs!.suggested).toBeCloseTo(carbsExpected.suggested, 1);
|
|
415
|
-
expect(result.insulin!.entered).toBe(insulinExpected.entered);
|
|
416
|
-
expect(result.insulin!.suggested).toBeCloseTo(insulinExpected.suggested, 1);
|
|
417
|
-
expect(result.reminder).toBe(RecommendationReminders.Reminder15Minutes);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
test.each`
|
|
421
|
-
recentBoluses | shown
|
|
422
|
-
${[]} | ${true}
|
|
423
|
-
${[{ insulinDose: 4, secondsPassed: 5500 }]} | ${false}
|
|
424
|
-
`(
|
|
425
|
-
`Only show recent insulin if recent boluses is empty`,
|
|
426
|
-
({ recentBoluses, shown }: { recentBoluses: IRecommendationParams["recentBoluses"]; shown: boolean }): void => {
|
|
427
|
-
const props = getRecommendationProps({
|
|
428
|
-
calculatorParams: {
|
|
429
|
-
...getRecommendationProps().calculatorParams,
|
|
430
|
-
recentBoluses,
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
434
|
-
|
|
435
|
-
if (shown) {
|
|
436
|
-
return expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
437
|
-
}
|
|
438
|
-
expectTextNotExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
439
|
-
},
|
|
440
|
-
);
|
|
441
|
-
|
|
442
|
-
test(`Updating insulin recommendation & transfer`, (): void => {
|
|
443
|
-
const props = getRecommendationProps({
|
|
444
|
-
calculatorParams: {
|
|
445
|
-
currentBGL: 10.8,
|
|
446
|
-
carbohydrates: 27,
|
|
447
|
-
carbohydrateRatio: 22,
|
|
448
|
-
insulinSensitivity: 5,
|
|
449
|
-
targetBGL: 7,
|
|
450
|
-
recentBoluses: [],
|
|
451
|
-
activity: null,
|
|
452
|
-
},
|
|
453
|
-
userReminder: 3,
|
|
454
|
-
injectionMethod: InjectionMethod.Pump,
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
const carbsExpected = {
|
|
458
|
-
entered: null,
|
|
459
|
-
suggested: 0,
|
|
460
|
-
};
|
|
461
|
-
const insulinExpected = {
|
|
462
|
-
entered: 7,
|
|
463
|
-
suggested: 2,
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
467
|
-
|
|
468
|
-
// Expect text from insulin -> change -> Expect text updated -> Transfer -> Expect callback
|
|
469
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
470
|
-
|
|
471
|
-
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
472
|
-
|
|
473
|
-
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
474
|
-
|
|
475
|
-
fireEvent(noButton, `onPress`);
|
|
476
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
477
|
-
|
|
478
|
-
const insulinInput = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
479
|
-
|
|
480
|
-
// Input 7 into the insulin field
|
|
481
|
-
fireEvent(insulinInput, `onEnd`, insulinExpected.entered);
|
|
482
|
-
|
|
483
|
-
// Expect text updated
|
|
484
|
-
expectTextNotExists(wrapper, `${insulinExpected.suggested}`);
|
|
485
|
-
|
|
486
|
-
expectTextExists(wrapper, `${insulinExpected.entered}`);
|
|
487
|
-
|
|
488
|
-
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
489
|
-
|
|
490
|
-
// Press transfer
|
|
491
|
-
fireEvent(transfer, `onPress`);
|
|
492
|
-
|
|
493
|
-
expect(props.transferToLogbook).toBeCalledWith(
|
|
494
|
-
carbsExpected,
|
|
495
|
-
insulinExpected,
|
|
496
|
-
3,
|
|
497
|
-
new Date(global.Date.now()),
|
|
498
|
-
null,
|
|
499
|
-
);
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
test(`Typing an invalid value on the insulin recommendation field, resets to Hedia suggestion`, (): void => {
|
|
503
|
-
const props = getRecommendationProps({
|
|
504
|
-
calculatorParams: {
|
|
505
|
-
currentBGL: 10.8,
|
|
506
|
-
carbohydrates: 27,
|
|
507
|
-
carbohydrateRatio: 22,
|
|
508
|
-
insulinSensitivity: 5,
|
|
509
|
-
targetBGL: 7,
|
|
510
|
-
recentBoluses: [],
|
|
511
|
-
activity: null,
|
|
512
|
-
},
|
|
513
|
-
userReminder: 3,
|
|
514
|
-
injectionMethod: InjectionMethod.Pump,
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
const carbsExpected = {
|
|
518
|
-
entered: null,
|
|
519
|
-
suggested: 0,
|
|
520
|
-
};
|
|
521
|
-
const insulinExpected = {
|
|
522
|
-
entered: 2,
|
|
523
|
-
suggested: 2,
|
|
524
|
-
};
|
|
525
|
-
const invalidInsulin: number = 300;
|
|
526
|
-
|
|
527
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
528
|
-
|
|
529
|
-
// Answer "No" to recent insulin
|
|
530
|
-
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
531
|
-
|
|
532
|
-
fireEvent(noButton, `onPress`);
|
|
533
|
-
|
|
534
|
-
// Verify initial insulin suggestion matches expected
|
|
535
|
-
expectTextExists(wrapper, `${insulinExpected.suggested}`);
|
|
536
|
-
|
|
537
|
-
// Type invalid value - 300 - on insulinInput
|
|
538
|
-
|
|
539
|
-
const insulinInput = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
540
|
-
|
|
541
|
-
fireEvent(insulinInput, `onEnd`, invalidInsulin);
|
|
542
|
-
|
|
543
|
-
// After onEnd event, verify the invalid entered value doesn't exist.
|
|
544
|
-
expectTextNotExists(wrapper, `${invalidInsulin}`);
|
|
545
|
-
|
|
546
|
-
// Value has been reset to initial suggestion
|
|
547
|
-
expectTextExists(wrapper, `${insulinExpected.suggested}`);
|
|
548
|
-
|
|
549
|
-
// Press transfer to logbook button
|
|
550
|
-
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
551
|
-
|
|
552
|
-
fireEvent(transfer, `onPress`);
|
|
553
|
-
|
|
554
|
-
// Verify the transferred data
|
|
555
|
-
expect(props.transferToLogbook).toBeCalledWith(
|
|
556
|
-
carbsExpected,
|
|
557
|
-
insulinExpected,
|
|
558
|
-
3,
|
|
559
|
-
new Date(global.Date.now()),
|
|
560
|
-
null,
|
|
561
|
-
);
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
test(`Updating remeasure reminder`, (): void => {
|
|
565
|
-
const props = getRecommendationProps({
|
|
566
|
-
calculatorParams: {
|
|
567
|
-
currentBGL: 10.85,
|
|
568
|
-
carbohydrates: 27,
|
|
569
|
-
carbohydrateRatio: 22,
|
|
570
|
-
insulinSensitivity: 5,
|
|
571
|
-
targetBGL: 7,
|
|
572
|
-
recentBoluses: [],
|
|
573
|
-
activity: null,
|
|
574
|
-
},
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
578
|
-
|
|
579
|
-
// Expect text from insulin -> change -> Expect text updated -> Transfer -> Expect callback
|
|
580
|
-
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
581
|
-
|
|
582
|
-
fireEvent(noButton, `onPress`);
|
|
583
|
-
expectTextExists(wrapper, `Transfer to logbook`);
|
|
584
|
-
|
|
585
|
-
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
586
|
-
|
|
587
|
-
// Input 2.5 in remeasure slider
|
|
588
|
-
fireEvent(slider, `onValueChange`, 2.5);
|
|
589
|
-
|
|
590
|
-
// Expect text updated
|
|
591
|
-
expectTextNotExists(wrapper, `1.5`);
|
|
592
|
-
expectTextExists(wrapper, `2.5`);
|
|
593
|
-
|
|
594
|
-
const sad = MoodEnum[MoodEnum.Sad];
|
|
595
|
-
|
|
596
|
-
const icon = getIcon(wrapper, sad, false);
|
|
597
|
-
|
|
598
|
-
if (icon === null) {
|
|
599
|
-
return fail(`Could not find icon from queryByA11yLabel: ${sad}_${false}`);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
fireEvent(icon, `onPress`);
|
|
603
|
-
|
|
604
|
-
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
605
|
-
|
|
606
|
-
// Press transfer
|
|
607
|
-
fireEvent(transfer, `onPress`);
|
|
608
|
-
|
|
609
|
-
const carbsExpected = {
|
|
610
|
-
entered: null,
|
|
611
|
-
suggested: 0,
|
|
612
|
-
};
|
|
613
|
-
const insulinExpected = {
|
|
614
|
-
entered: null,
|
|
615
|
-
suggested: 2,
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
expect(props.transferToLogbook).toBeCalledWith(
|
|
619
|
-
carbsExpected,
|
|
620
|
-
insulinExpected,
|
|
621
|
-
2.5,
|
|
622
|
-
new Date(global.Date.now()),
|
|
623
|
-
MoodEnum.Sad,
|
|
624
|
-
);
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
test.each`
|
|
628
|
-
locale | text
|
|
629
|
-
${Languages.da} | ${`INSULIN\nANBEFALING`}
|
|
630
|
-
${Languages.en} | ${`INSULIN\nRECOMMENDATION`}
|
|
631
|
-
${Languages.de} | ${`INSULIN\nEMPFEHLUNG`}
|
|
632
|
-
${Languages.es} | ${`RECOMENDACIÓN\nDE INSULINA`}
|
|
633
|
-
${Languages.it} | ${`PRESCRIZIONE DI\nINSULINA`}
|
|
634
|
-
${Languages.fr} | ${`RECOMMANDATION\nD’INSULINE`}
|
|
635
|
-
`(
|
|
636
|
-
`Language props determine language shown; $locale`,
|
|
637
|
-
({ locale, text }: { locale: Languages; text: string }): void => {
|
|
638
|
-
const props = getRecommendationProps({
|
|
639
|
-
language: locale,
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
643
|
-
|
|
644
|
-
expectTextExists(wrapper, text);
|
|
645
|
-
},
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
test(`Error is thrown when passing an unsupported language`, (): void => {
|
|
649
|
-
const props = getRecommendationProps();
|
|
650
|
-
|
|
651
|
-
const wrapper = render(<RecommendationScreen {...props} language={`INVALID_LANGUAGE` as Languages} />);
|
|
652
|
-
expectTextNotExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
653
|
-
expect(props.onError).toBeCalledWith(LanguageError());
|
|
654
|
-
});
|
|
655
|
-
test(`Error is thrown when passing an unsupported activity settings`, (): void => {
|
|
656
|
-
const props: IRecommendationProps = getRecommendationProps({
|
|
657
|
-
calculatorParams: {
|
|
658
|
-
...generateDefaultCalculatorParams(),
|
|
659
|
-
activity: { ...generateActivityProps(), activityIntensity: hard, activityDuration: 46 },
|
|
660
|
-
},
|
|
661
|
-
});
|
|
662
|
-
|
|
663
|
-
render(<RecommendationScreen {...props} />);
|
|
664
|
-
expect(props.onError).toBeCalledWith(new Error(BolusCalculator.Enums.ActivityErrors.InvalidInterval));
|
|
665
|
-
});
|
|
666
|
-
|
|
667
|
-
interface IChangeLanguageProps {
|
|
668
|
-
initialLocale: Languages;
|
|
669
|
-
locale: Languages;
|
|
670
|
-
initialText: string;
|
|
671
|
-
text: string;
|
|
672
|
-
}
|
|
673
|
-
test.each`
|
|
674
|
-
initialLocale | locale | initialText | text
|
|
675
|
-
${Languages.en} | ${Languages.da} | ${`INSULIN\nRECOMMENDATION`} | ${`INSULIN\nANBEFALING`}
|
|
676
|
-
${Languages.da} | ${Languages.de} | ${`INSULIN\nANBEFALING`} | ${`INSULIN\nEMPFEHLUNG`}
|
|
677
|
-
${Languages.de} | ${Languages.es} | ${`INSULIN\nEMPFEHLUNG`} | ${`RECOMENDACIÓN\nDE INSULINA`}
|
|
678
|
-
${Languages.es} | ${Languages.it} | ${`RECOMENDACIÓN\nDE INSULINA`} | ${`PRESCRIZIONE DI\nINSULINA`}
|
|
679
|
-
${Languages.it} | ${Languages.fr} | ${`PRESCRIZIONE DI\nINSULINA`} | ${`RECOMMANDATION\nD’INSULINE`}
|
|
680
|
-
${Languages.fr} | ${Languages.en} | ${`RECOMMANDATION\nD’INSULINE`} | ${`INSULIN\nRECOMMENDATION`}
|
|
681
|
-
`(
|
|
682
|
-
`Changing language changes header text; initial-language:$initialLocale to changed-language:$locale`,
|
|
683
|
-
({ initialLocale, locale, initialText, text }: IChangeLanguageProps): void => {
|
|
684
|
-
const props = getRecommendationProps({ language: initialLocale });
|
|
685
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
686
|
-
|
|
687
|
-
expectTextExists(wrapper, initialText);
|
|
688
|
-
expectTextNotExists(wrapper, text);
|
|
689
|
-
|
|
690
|
-
i18n.activate(locale);
|
|
691
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
692
|
-
|
|
693
|
-
expectTextNotExists(wrapper, initialText);
|
|
694
|
-
expectTextExists(wrapper, text);
|
|
695
|
-
},
|
|
696
|
-
);
|
|
697
|
-
|
|
698
|
-
test(`Timeout callback runs after 15 minutes`, (): void => {
|
|
699
|
-
const props = getRecommendationProps();
|
|
700
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
701
|
-
|
|
702
|
-
expect(props.onError).not.toBeCalled();
|
|
703
|
-
|
|
704
|
-
jest.runAllTimers();
|
|
705
|
-
expect(props.onError).not.toBeCalled();
|
|
706
|
-
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
test(`Active Insulin defaults to an empty array`, (): void => {
|
|
710
|
-
const props = getRecommendationProps({
|
|
711
|
-
calculatorParams: {
|
|
712
|
-
...getRecommendationProps().calculatorParams,
|
|
713
|
-
currentBGL: 8,
|
|
714
|
-
targetBGL: 8,
|
|
715
|
-
recentBoluses: [],
|
|
716
|
-
},
|
|
717
|
-
});
|
|
718
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
719
|
-
expectTextExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
720
|
-
expectTextExists(wrapper, `0`);
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
test(`InfoBars behave as expected with BGL & Active Insulin`, (): void => {
|
|
724
|
-
const props = {
|
|
725
|
-
...getRecommendationProps({
|
|
726
|
-
calculatorParams: {
|
|
727
|
-
...getRecommendationProps().calculatorParams,
|
|
728
|
-
// @ts-ignore
|
|
729
|
-
currentBGL: null,
|
|
730
|
-
},
|
|
731
|
-
}),
|
|
732
|
-
currentBKL: null,
|
|
733
|
-
};
|
|
734
|
-
// @ts-ignore
|
|
735
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
736
|
-
|
|
737
|
-
expectTextExists(wrapper, /2\./);
|
|
738
|
-
expect(wrapper.queryAllByText(`-.-`)).toHaveLength(2);
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
test(`InfoBars displays bgl and ketones in mg/dL`, (): void => {
|
|
742
|
-
const props = getRecommendationProps({
|
|
743
|
-
calculatorParams: {
|
|
744
|
-
...getRecommendationProps().calculatorParams,
|
|
745
|
-
currentBGL: 1.1,
|
|
746
|
-
},
|
|
747
|
-
bloodGlucoseUnit: BloodGlucoseUnit.MG_DL,
|
|
748
|
-
bloodKetoneUnit: BloodKetonesUnit.MG_DL,
|
|
749
|
-
});
|
|
750
|
-
const bklMGDL = Utils.convertBKLToMGDL(props.currentBKL);
|
|
751
|
-
const bglMGDL = Utils.convertBGLToMGDL(props.calculatorParams.currentBGL);
|
|
752
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
753
|
-
|
|
754
|
-
expectTextExists(wrapper, /2\./);
|
|
755
|
-
expectTextExists(wrapper, `${bglMGDL}`);
|
|
756
|
-
expectTextExists(wrapper, `${bklMGDL}`);
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
test(`InfoBars displays negative level currentBKL as 0`, (): void => {
|
|
760
|
-
const props = getRecommendationProps({
|
|
761
|
-
calculatorParams: {
|
|
762
|
-
...getRecommendationProps().calculatorParams, // active insulin is not 0
|
|
763
|
-
currentBGL: 33, // in order to recommend insulin
|
|
764
|
-
carbohydrates: 1, // in order not to have entered carbs = 0
|
|
765
|
-
},
|
|
766
|
-
currentBKL: 0,
|
|
767
|
-
bloodKetoneUnit: BloodKetonesUnit.MG_DL, // mg/dL placeholder is `-`
|
|
768
|
-
});
|
|
769
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
770
|
-
expectTextExists(wrapper, `0`);
|
|
771
|
-
expectTextNotExists(wrapper, `-`);
|
|
772
|
-
});
|
|
773
|
-
|
|
774
|
-
test(`Can display with undefined activityDisplayProps`, (): void => {
|
|
775
|
-
const props = getRecommendationProps({
|
|
776
|
-
calculatorParams: getRecommendationProps().calculatorParams,
|
|
777
|
-
activityDisplayProps: undefined,
|
|
778
|
-
});
|
|
779
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
780
|
-
|
|
781
|
-
expectTextExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
782
|
-
const shownInsulin = queryTextFromComponent(wrapper, RecommendedInsulinTestIds.ShownInsulinText);
|
|
783
|
-
expect(shownInsulin).toBe(`0`);
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
test.each`
|
|
787
|
-
intensity | translation
|
|
788
|
-
${light} | ${`Let`}
|
|
789
|
-
${moderate} | ${`Moderat`}
|
|
790
|
-
${hard} | ${`Hård`}
|
|
791
|
-
`(
|
|
792
|
-
`Activity screen is displayed and intensity: $intensity can be translated`,
|
|
793
|
-
({ intensity, translation }: { intensity: Activity.Enums.ActivityIntensity; translation: string }): void => {
|
|
794
|
-
const props = getRecommendationProps({
|
|
795
|
-
activityDisplayProps: { activityType: ActivityEnum.Run, activityTitle: null },
|
|
796
|
-
calculatorParams: {
|
|
797
|
-
...getRecommendationProps().calculatorParams,
|
|
798
|
-
activity: {
|
|
799
|
-
...generateActivityProps(),
|
|
800
|
-
activityIntensity: intensity,
|
|
801
|
-
},
|
|
802
|
-
},
|
|
803
|
-
});
|
|
804
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
805
|
-
|
|
806
|
-
const englishText = ActivityIntensityTranslations[intensity]();
|
|
807
|
-
|
|
808
|
-
expectTextExists(wrapper, englishText);
|
|
809
|
-
expectTextNotExists(wrapper, translation);
|
|
810
|
-
|
|
811
|
-
i18n.activate(Languages.da);
|
|
812
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
813
|
-
|
|
814
|
-
expectTextExists(wrapper, translation);
|
|
815
|
-
expectTextNotExists(wrapper, englishText);
|
|
816
|
-
},
|
|
817
|
-
);
|
|
818
|
-
|
|
819
|
-
test(`Show limitation page at recalculation`, (): void => {
|
|
820
|
-
const carbRecommendationAnswer = jest.fn();
|
|
821
|
-
const props = getRecommendationProps({
|
|
822
|
-
calculatorParams: {
|
|
823
|
-
currentBGL: 7,
|
|
824
|
-
carbohydrates: 1,
|
|
825
|
-
carbohydrateRatio: 1,
|
|
826
|
-
insulinSensitivity: 0.3,
|
|
827
|
-
targetBGL: 8.3,
|
|
828
|
-
recentBoluses: [],
|
|
829
|
-
activity: null,
|
|
830
|
-
},
|
|
831
|
-
userReminder: 5,
|
|
832
|
-
carbRecommendationAnswer,
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
// Render the screen, expecting a carb recommendation modal.
|
|
836
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
837
|
-
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
838
|
-
|
|
839
|
-
// Get the yes button from the modal
|
|
840
|
-
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
841
|
-
|
|
842
|
-
fireEvent(yesButton, `onPress`);
|
|
843
|
-
expect(carbRecommendationAnswer).toBeCalledWith(true);
|
|
844
|
-
expectTextExists(wrapper, `Additional`);
|
|
845
|
-
|
|
846
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`1`);
|
|
847
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`3`);
|
|
848
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`4`);
|
|
849
|
-
|
|
850
|
-
const carbInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
851
|
-
|
|
852
|
-
const manualCarbInput = 299;
|
|
853
|
-
|
|
854
|
-
// Input 299 into the carbs field
|
|
855
|
-
fireEvent(carbInput, `onEnd`, manualCarbInput);
|
|
856
|
-
|
|
857
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`1`);
|
|
858
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`299`);
|
|
859
|
-
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`300`);
|
|
860
|
-
|
|
861
|
-
// Expect text from limitation message after recalculation
|
|
862
|
-
expectTextExists(wrapper, `${Messages.RecommendationWasLimited()}`);
|
|
863
|
-
|
|
864
|
-
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
865
|
-
|
|
866
|
-
fireEvent(nextButton, `onPress`);
|
|
867
|
-
expectTextNotExists(wrapper, `${Messages.RecommendationWasLimited()}`);
|
|
868
|
-
});
|
|
869
|
-
});
|
|
870
|
-
|
|
871
|
-
describe(`Recommendation Screen - RecommendationModal related tests`, (): void => {
|
|
872
|
-
test(`Test decline carbs suggestion`, (): void => {
|
|
873
|
-
const carbRecommendationAnswer = jest.fn();
|
|
874
|
-
const props = getRecommendationProps({
|
|
875
|
-
calculatorParams: {
|
|
876
|
-
currentBGL: 1.1,
|
|
877
|
-
carbohydrates: 25,
|
|
878
|
-
carbohydrateRatio: 22,
|
|
879
|
-
insulinSensitivity: 5,
|
|
880
|
-
targetBGL: 7,
|
|
881
|
-
recentBoluses: [],
|
|
882
|
-
activity: null,
|
|
883
|
-
},
|
|
884
|
-
userReminder: 5,
|
|
885
|
-
carbRecommendationAnswer,
|
|
886
|
-
});
|
|
887
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
888
|
-
|
|
889
|
-
const noButton = wrapper.getByTestId(RecommendationModalTestIds.DeclineCarbs);
|
|
890
|
-
|
|
891
|
-
fireEvent(noButton, `onPress`);
|
|
892
|
-
|
|
893
|
-
expect(carbRecommendationAnswer).toBeCalledWith(false);
|
|
894
|
-
expectTextExists(wrapper, `Food`);
|
|
895
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
896
|
-
});
|
|
897
|
-
|
|
898
|
-
test(`Test accept carbs suggestion`, (): void => {
|
|
899
|
-
const carbRecommendationAnswer = jest.fn();
|
|
900
|
-
const props = getRecommendationProps({
|
|
901
|
-
calculatorParams: {
|
|
902
|
-
currentBGL: 1.1,
|
|
903
|
-
carbohydrates: 25,
|
|
904
|
-
carbohydrateRatio: 22,
|
|
905
|
-
insulinSensitivity: 5,
|
|
906
|
-
targetBGL: 7,
|
|
907
|
-
recentBoluses: [],
|
|
908
|
-
activity: null,
|
|
909
|
-
},
|
|
910
|
-
userReminder: 5,
|
|
911
|
-
carbRecommendationAnswer,
|
|
912
|
-
});
|
|
913
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
914
|
-
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
915
|
-
|
|
916
|
-
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
917
|
-
|
|
918
|
-
fireEvent(yesButton, `onPress`);
|
|
919
|
-
expect(carbRecommendationAnswer).toBeCalledWith(true);
|
|
920
|
-
expectTextExists(wrapper, `Food`);
|
|
921
|
-
expectTextExists(wrapper, `Additional`);
|
|
922
|
-
expectTextExists(wrapper, `1`);
|
|
923
|
-
});
|
|
924
|
-
|
|
925
|
-
test(`Test dismiss react-native 2 "page" modal no carbs recommended`, (): void => {
|
|
926
|
-
const props = getRecommendationProps({
|
|
927
|
-
calculatorParams: {
|
|
928
|
-
currentBGL: 27,
|
|
929
|
-
carbohydrates: 25,
|
|
930
|
-
carbohydrateRatio: 22,
|
|
931
|
-
insulinSensitivity: 0.3,
|
|
932
|
-
targetBGL: 7,
|
|
933
|
-
recentBoluses: [],
|
|
934
|
-
activity: generateActivityProps(),
|
|
935
|
-
},
|
|
936
|
-
userReminder: 5,
|
|
937
|
-
});
|
|
938
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
939
|
-
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
940
|
-
|
|
941
|
-
fireEvent(nextButton, `onPress`);
|
|
942
|
-
|
|
943
|
-
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.OkButton);
|
|
944
|
-
|
|
945
|
-
fireEvent(yesButton, `onPress`);
|
|
946
|
-
expectTextExists(wrapper, `Food`);
|
|
947
|
-
expectTextNotExists(wrapper, `Additional`);
|
|
948
|
-
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
949
|
-
expectTextExists(wrapper, `${RecommendationReminders.Reminder15Minutes}`);
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
|
|
953
|
-
describe(`Recommendation Screen - TwoOptionModal related tests`, (): void => {
|
|
954
|
-
test(`Save to logbook from ExitModal option`, (): void => {
|
|
955
|
-
const props = getRecommendationProps();
|
|
956
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
957
|
-
|
|
958
|
-
//press exit button
|
|
959
|
-
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
960
|
-
|
|
961
|
-
fireEvent(exitButton, `onPress`);
|
|
962
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
963
|
-
|
|
964
|
-
const saveToLogbookModalButton = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
965
|
-
|
|
966
|
-
fireEvent(saveToLogbookModalButton, `onPress`);
|
|
967
|
-
expect(props.transferToLogbook).toBeCalled();
|
|
968
|
-
|
|
969
|
-
expectTextNotExists(wrapper, `Save to logbook`);
|
|
970
|
-
expectTextNotExists(wrapper, `Close calculation`);
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
test(`Close calculation callback from ExitModal option`, (): void => {
|
|
974
|
-
const props = getRecommendationProps();
|
|
975
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
976
|
-
|
|
977
|
-
//press exit button
|
|
978
|
-
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
979
|
-
|
|
980
|
-
fireEvent(exitButton, `onPress`);
|
|
981
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
982
|
-
|
|
983
|
-
const closeCalculation = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
984
|
-
|
|
985
|
-
fireEvent(closeCalculation, `onPress`);
|
|
986
|
-
expect(props.closeCalculationCallback).toBeCalled();
|
|
987
|
-
|
|
988
|
-
expectTextNotExists(wrapper, `Save to logbook`);
|
|
989
|
-
expectTextNotExists(wrapper, `Close calculation`);
|
|
990
|
-
});
|
|
991
|
-
|
|
992
|
-
test(`Test exitCallback callback when recentInsulin component is visible`, (): void => {
|
|
993
|
-
const props = getRecommendationProps({
|
|
994
|
-
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
995
|
-
});
|
|
996
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
997
|
-
|
|
998
|
-
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
999
|
-
|
|
1000
|
-
fireEvent(exitButton, `onPress`);
|
|
1001
|
-
expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
1002
|
-
expect(props.showBolusBar).not.toBeCalled();
|
|
1003
|
-
expect(props.exitCallback).toBeCalled();
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
test(`Test triggering on/off the ExitModal`, async (): Promise<void> => {
|
|
1007
|
-
const props = getRecommendationProps();
|
|
1008
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1009
|
-
|
|
1010
|
-
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
1011
|
-
|
|
1012
|
-
fireEvent(exitButton, `onPress`);
|
|
1013
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1014
|
-
expectTextExists(wrapper, `Save to logbook`);
|
|
1015
|
-
expectTextExists(wrapper, `Close calculation`);
|
|
1016
|
-
|
|
1017
|
-
const modalExitIcon = wrapper.getByTestId(TwoOptionModalTestIds.ExitButton);
|
|
1018
|
-
|
|
1019
|
-
fireEvent(modalExitIcon, `onPress`);
|
|
1020
|
-
expect(props.showBolusBar).toBeCalledWith(true);
|
|
1021
|
-
expectTextNotExists(wrapper, `Save to logbook`);
|
|
1022
|
-
expectTextNotExists(wrapper, `Close calculation`);
|
|
1023
|
-
});
|
|
1024
|
-
|
|
1025
|
-
test(`Can translate ExitModal option`, (): void => {
|
|
1026
|
-
const props = getRecommendationProps({ language: Languages.da });
|
|
1027
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1028
|
-
|
|
1029
|
-
//press exit button
|
|
1030
|
-
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
1031
|
-
|
|
1032
|
-
fireEvent(exitButton, `onPress`);
|
|
1033
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1034
|
-
|
|
1035
|
-
expectTextExists(wrapper, `Luk beregning`);
|
|
1036
|
-
expectTextExists(wrapper, `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`);
|
|
1037
|
-
expectTextExists(wrapper, `Gem i logbog`);
|
|
1038
|
-
expectTextExists(wrapper, `Vil du gemme din indtastning?`);
|
|
1039
|
-
});
|
|
1040
|
-
|
|
1041
|
-
test(`Test TimeoutModal first option WITH recommendation visible`, (): void => {
|
|
1042
|
-
const props = getRecommendationProps();
|
|
1043
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1044
|
-
|
|
1045
|
-
expect(props.onError).not.toBeCalled();
|
|
1046
|
-
|
|
1047
|
-
jest.runAllTimers();
|
|
1048
|
-
expect(props.onError).not.toBeCalled();
|
|
1049
|
-
|
|
1050
|
-
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
1051
|
-
expect(modalExitIcon).toBeNull();
|
|
1052
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1053
|
-
|
|
1054
|
-
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
1055
|
-
expectTextExists(wrapper, `Yes, save to logbook`);
|
|
1056
|
-
expectTextExists(wrapper, `No, return to dashboard`);
|
|
1057
|
-
|
|
1058
|
-
i18n.activate(Languages.da);
|
|
1059
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
1060
|
-
jest.runAllTimers();
|
|
1061
|
-
expectTextExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
1062
|
-
|
|
1063
|
-
const saveToLogbook = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
1064
|
-
|
|
1065
|
-
fireEvent(saveToLogbook, `onPress`);
|
|
1066
|
-
expect(props.transferToLogbook).toBeCalled();
|
|
1067
|
-
});
|
|
1068
|
-
|
|
1069
|
-
test(`Test TimeoutModal second option WITH recommendation visible`, (): void => {
|
|
1070
|
-
const props = getRecommendationProps();
|
|
1071
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1072
|
-
|
|
1073
|
-
expect(props.onError).not.toBeCalled();
|
|
1074
|
-
|
|
1075
|
-
jest.runAllTimers();
|
|
1076
|
-
expect(props.onError).not.toBeCalled();
|
|
1077
|
-
|
|
1078
|
-
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
1079
|
-
expect(modalExitIcon).toBeNull();
|
|
1080
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1081
|
-
|
|
1082
|
-
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
1083
|
-
expectTextExists(wrapper, `Yes, save to logbook`);
|
|
1084
|
-
expectTextExists(wrapper, `No, return to dashboard`);
|
|
1085
|
-
|
|
1086
|
-
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
1087
|
-
|
|
1088
|
-
fireEvent(returnToDashboard, `onPress`);
|
|
1089
|
-
expect(props.closeCalculationCallback).toBeCalled();
|
|
1090
|
-
});
|
|
1091
|
-
|
|
1092
|
-
test(`Test TimeoutModal second option WITH recommendation NOT visible`, (): void => {
|
|
1093
|
-
const props = getRecommendationProps({
|
|
1094
|
-
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
1095
|
-
});
|
|
1096
|
-
|
|
1097
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1098
|
-
|
|
1099
|
-
expect(props.onError).not.toBeCalled();
|
|
1100
|
-
|
|
1101
|
-
jest.runAllTimers();
|
|
1102
|
-
expect(props.onError).not.toBeCalled();
|
|
1103
|
-
|
|
1104
|
-
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
1105
|
-
expect(modalExitIcon).toBeNull();
|
|
1106
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1107
|
-
|
|
1108
|
-
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
1109
|
-
expectTextExists(wrapper, `Start new calculation`);
|
|
1110
|
-
expectTextExists(wrapper, `Return to dashboard`);
|
|
1111
|
-
|
|
1112
|
-
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
1113
|
-
|
|
1114
|
-
fireEvent(returnToDashboard, `onPress`);
|
|
1115
|
-
expect(props.closeCalculationCallback).toBeCalled();
|
|
1116
|
-
|
|
1117
|
-
expectTextNotExists(wrapper, `Start new calculation`);
|
|
1118
|
-
expectTextNotExists(wrapper, `Return to dashboard`);
|
|
1119
|
-
});
|
|
1120
|
-
|
|
1121
|
-
test(`Test TimeoutModal first option WITH recommendation NOT visible`, (): void => {
|
|
1122
|
-
const props = getRecommendationProps({
|
|
1123
|
-
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
1124
|
-
});
|
|
1125
|
-
|
|
1126
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1127
|
-
|
|
1128
|
-
expect(props.onError).not.toBeCalled();
|
|
1129
|
-
|
|
1130
|
-
jest.runAllTimers();
|
|
1131
|
-
expect(props.onError).not.toBeCalled();
|
|
1132
|
-
|
|
1133
|
-
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
1134
|
-
expect(modalExitIcon).toBeNull();
|
|
1135
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1136
|
-
|
|
1137
|
-
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
1138
|
-
expectTextExists(wrapper, `Start new calculation`);
|
|
1139
|
-
expectTextExists(wrapper, `Return to dashboard`);
|
|
1140
|
-
|
|
1141
|
-
i18n.activate(Languages.da);
|
|
1142
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
1143
|
-
jest.runAllTimers();
|
|
1144
|
-
expectTextExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
1145
|
-
|
|
1146
|
-
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
1147
|
-
|
|
1148
|
-
fireEvent(returnToDashboard, `onPress`);
|
|
1149
|
-
expect(props.restartCalculation).toBeCalled();
|
|
1150
|
-
|
|
1151
|
-
expectTextNotExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
1152
|
-
});
|
|
1153
|
-
|
|
1154
|
-
test(`Opening the app with a old calculation will show the timeout modal`, (): void => {
|
|
1155
|
-
const props = getRecommendationProps();
|
|
1156
|
-
|
|
1157
|
-
let appStateListener: (state: AppStateStatus) => void;
|
|
1158
|
-
const getMockAppStateListener = jest.fn(
|
|
1159
|
-
(event: AppStateEvent, callback: (state: AppStateStatus) => void): void => {
|
|
1160
|
-
if (event === `change`) {
|
|
1161
|
-
appStateListener = callback;
|
|
1162
|
-
}
|
|
1163
|
-
},
|
|
1164
|
-
);
|
|
1165
|
-
jest.resetModules();
|
|
1166
|
-
jest.doMock(
|
|
1167
|
-
`react-native/Libraries/AppState/AppState`,
|
|
1168
|
-
(): IMockAppState => ({
|
|
1169
|
-
addEventListener: getMockAppStateListener,
|
|
1170
|
-
removeEventListener: jest.fn(),
|
|
1171
|
-
}),
|
|
1172
|
-
);
|
|
1173
|
-
|
|
1174
|
-
const wrapper = render(<RecommendationScreen {...props} />);
|
|
1175
|
-
// @ts-ignore
|
|
1176
|
-
appStateListener?.(`active`);
|
|
1177
|
-
// Run twice to test else path
|
|
1178
|
-
global.Date.now = (): number => new Date().getTime() + Milliseconds.Minute * 14;
|
|
1179
|
-
// @ts-ignore
|
|
1180
|
-
appStateListener?.(`active`);
|
|
1181
|
-
|
|
1182
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
1183
|
-
expect(props.showBolusBar).not.toBeCalledWith(false);
|
|
1184
|
-
expectTextNotExists(wrapper, `No, return to dashboard`);
|
|
1185
|
-
|
|
1186
|
-
global.Date.now = (): number => new Date().getTime() + Milliseconds.Minute * 15;
|
|
1187
|
-
// @ts-ignore
|
|
1188
|
-
appStateListener(`active`);
|
|
1189
|
-
|
|
1190
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
1191
|
-
expect(props.showBolusBar).toBeCalledWith(false);
|
|
1192
|
-
expectTextExists(wrapper, `No, return to dashboard`);
|
|
1193
|
-
|
|
1194
|
-
const closeModalButton = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
1195
|
-
|
|
1196
|
-
fireEvent(closeModalButton, `secondOption`);
|
|
1197
|
-
|
|
1198
|
-
wrapper.rerender(<RecommendationScreen {...props} />);
|
|
1199
|
-
expectTextNotExists(wrapper, `No, return to dashboard`);
|
|
1200
|
-
expect(props.showBolusBar).toBeCalledWith(true);
|
|
1201
|
-
});
|
|
1202
|
-
|
|
1203
|
-
test(`Opening the app with a old calculation will show the timeout modal else path`, (): void => {
|
|
1204
|
-
const props = getRecommendationProps();
|
|
1205
|
-
|
|
1206
|
-
let appStateListener: (state: AppStateStatus) => void;
|
|
1207
|
-
const getMockAppStateListener = jest.fn(
|
|
1208
|
-
(event: AppStateEvent, callback: (state: AppStateStatus) => void): void => {
|
|
1209
|
-
if (event === `change`) {
|
|
1210
|
-
appStateListener = callback;
|
|
1211
|
-
}
|
|
1212
|
-
},
|
|
1213
|
-
);
|
|
1214
|
-
|
|
1215
|
-
jest.resetModules();
|
|
1216
|
-
jest.doMock(
|
|
1217
|
-
`react-native/Libraries/AppState/AppState`,
|
|
1218
|
-
(): IMockAppState => ({
|
|
1219
|
-
addEventListener: getMockAppStateListener,
|
|
1220
|
-
removeEventListener: jest.fn(),
|
|
1221
|
-
}),
|
|
1222
|
-
);
|
|
1223
|
-
|
|
1224
|
-
const rendered = render(<RecommendationScreen {...props} />);
|
|
1225
|
-
// @ts-ignore
|
|
1226
|
-
appStateListener(`NotAnAppStateStatus` as AppStateStatus);
|
|
1227
|
-
rendered.rerender(<RecommendationScreen {...props} />);
|
|
1228
|
-
expect(props.showBolusBar).not.toBeCalled();
|
|
1229
|
-
expectTextNotExists(rendered, `No, return to dashboard`);
|
|
1230
|
-
});
|
|
1231
|
-
});
|