@hedia/recommendation-screen 2.1.3-beta.6 → 2.1.3-beta.7
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/coverage/clover.xml +2 -2
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1 -1
- package/coverage/lcov-report/src/__tests__/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/utils.tsx.html +1 -1
- package/coverage/lcov-report/src/components/Header.tsx.html +1 -1
- package/coverage/lcov-report/src/components/InfoBars.tsx.html +1 -1
- package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +1 -1
- package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +1 -1
- package/coverage/lcov-report/src/components/LineSeparator.tsx.html +1 -1
- package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +1 -1
- package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +1 -1
- package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +1 -1
- package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +1 -1
- package/coverage/lcov-report/src/components/Remeasure.tsx.html +1 -1
- package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +1 -1
- package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +1 -1
- package/coverage/lcov-report/src/components/activity/Activity.tsx.html +1 -1
- package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +1 -1
- package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +1 -1
- package/coverage/lcov-report/src/components/activity/index.html +1 -1
- package/coverage/lcov-report/src/components/index.html +1 -1
- package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +1 -1
- package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +1 -1
- package/coverage/lcov-report/src/components/mood/index.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/locale/i18nUtils.ts.html +1 -1
- package/coverage/lcov-report/src/locale/index.html +1 -1
- package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +1 -1
- package/coverage/lcov-report/src/utils/Constants.ts.html +1 -1
- package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +1 -1
- package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +1 -1
- package/coverage/lcov-report/src/utils/Translations.ts.html +1 -1
- package/coverage/lcov-report/src/utils/Utils.ts.html +1 -1
- package/coverage/lcov-report/src/utils/Validations.ts.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/index.js +5 -31
- package/package.json +2 -1
- package/src/RecommendationScreen.js +76 -101
- package/src/__tests__/RecommendationScreen.test.js +404 -409
- package/src/__tests__/RecommendationUtils.test.js +117 -119
- package/src/__tests__/Translate.test.js +14 -16
- package/src/__tests__/Utils.test.js +16 -18
- package/src/__tests__/Validations.test.js +30 -51
- package/src/__tests__/components/Activity.test.js +51 -56
- package/src/__tests__/components/Emotion.test.js +28 -33
- package/src/__tests__/components/Header.test.js +24 -29
- package/src/__tests__/components/InfoBars.test.js +59 -64
- package/src/__tests__/components/InvisibleNumberInput.test.js +22 -27
- package/src/__tests__/components/LimitationMessage.test.js +28 -33
- package/src/__tests__/components/MoodIcon.test.js +9 -14
- package/src/__tests__/components/RecommendationModal.test.js +56 -61
- package/src/__tests__/components/RecommendedCarbs.test.js +58 -63
- package/src/__tests__/components/RecommendedInsulin.test.js +60 -65
- package/src/__tests__/components/Remeasure.test.js +32 -37
- package/src/__tests__/components/TransferToLogbook.test.js +15 -20
- package/src/__tests__/components/TwoOptionModal.test.js +22 -27
- package/src/__tests__/utils.js +22 -38
- package/src/components/Header.js +34 -41
- package/src/components/Icon.js +2 -8
- package/src/components/InfoBars.js +36 -43
- package/src/components/InvisibleNumberInput.js +5 -11
- package/src/components/LimitationMessage.js +18 -40
- package/src/components/LineSeparator.js +7 -13
- package/src/components/RecentInsulin.js +33 -39
- package/src/components/RecommendationModal.js +59 -85
- package/src/components/RecommendedCarbs.js +93 -99
- package/src/components/RecommendedInsulin.js +46 -52
- package/src/components/Remeasure.js +36 -42
- package/src/components/TransferToLogbook.js +20 -26
- package/src/components/TwoOptionModal.js +39 -65
- package/src/components/activity/Activity.js +42 -48
- package/src/components/activity/ActivityIcon.js +15 -21
- package/src/components/activity/ActivityIntensity.js +19 -25
- package/src/components/mood/Emotion.js +17 -23
- package/src/components/mood/MoodIcon.js +11 -17
- package/src/locale/i18nUtils.js +17 -24
- package/src/types/enum.js +28 -31
- package/src/types/types.js +1 -2
- package/src/utils/AttentionMessages.js +24 -32
- package/src/utils/Constants.js +23 -26
- package/src/utils/RecommendationError.js +28 -54
- package/src/utils/RecommendationUtils.js +60 -72
- package/src/utils/Translations.js +6 -9
- package/src/utils/Utils.js +8 -12
- package/src/utils/Validations.js +77 -107
- package/tsconfig.json +3 -3
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const utils_1 = require("./utils");
|
|
17
|
-
const ActivityIntensity = types_1.Activity.Enums.ActivityIntensity;
|
|
18
|
-
const ActivityEnum = types_1.Activity.Enums.ActivityEnum;
|
|
19
|
-
const InjectionMethod = types_1.UserSettings.Enums.InjectionMethod;
|
|
20
|
-
const MoodEnum = types_1.Logbook.Enums.MoodEnum;
|
|
1
|
+
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, BolusCalculator, Languages, Logbook, Milliseconds, UserSettings, } from "@hedia/types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
4
|
+
import { i18n } from "../locale/i18nUtils";
|
|
5
|
+
import RecommendationScreen from "../RecommendationScreen";
|
|
6
|
+
import { HeaderTestIds, InfoBarTestIds, LimitationMessageTestIds, RecentInsulinTestIds, RecommendationModalTestIds, RecommendationReminders, RecommendedCarbsTestIds, RecommendedInsulinTestIds, RemeasureTestIds, TransferToLogbookTestIds, TwoOptionModalTestIds, } from "../types/enum";
|
|
7
|
+
import { Messages } from "../utils/AttentionMessages";
|
|
8
|
+
import { LanguageError } from "../utils/RecommendationError";
|
|
9
|
+
import { ActivityIntensityTranslations } from "../utils/Translations";
|
|
10
|
+
import { Utils } from "../utils/Utils";
|
|
11
|
+
import { expectTextExists, expectTextNotExists, generateActivityProps, generateDefaultCalculatorParams, getIcon, getRecommendationProps, queryTextFromComponent, } from "./utils";
|
|
12
|
+
const ActivityIntensity = Activity.Enums.ActivityIntensity;
|
|
13
|
+
const ActivityEnum = Activity.Enums.ActivityEnum;
|
|
14
|
+
const InjectionMethod = UserSettings.Enums.InjectionMethod;
|
|
15
|
+
const MoodEnum = Logbook.Enums.MoodEnum;
|
|
21
16
|
const { light, moderate, hard } = ActivityIntensity;
|
|
22
17
|
describe(`RecommendationScreen`, () => {
|
|
23
18
|
jest.useFakeTimers();
|
|
24
19
|
beforeEach(() => {
|
|
25
|
-
|
|
20
|
+
i18n.activate(Languages.en);
|
|
26
21
|
global.Date.now = () => 1;
|
|
27
22
|
});
|
|
28
23
|
afterEach(() => {
|
|
29
|
-
|
|
24
|
+
cleanup();
|
|
30
25
|
global.Date.now = () => new Date().getTime();
|
|
31
26
|
});
|
|
32
27
|
test(`25 recommended carbs - No edit`, () => {
|
|
33
|
-
const props =
|
|
28
|
+
const props = getRecommendationProps({
|
|
34
29
|
calculatorParams: {
|
|
35
30
|
currentBGL: 1.1,
|
|
36
31
|
carbohydrates: 25,
|
|
@@ -42,38 +37,38 @@ describe(`RecommendationScreen`, () => {
|
|
|
42
37
|
},
|
|
43
38
|
userReminder: 5,
|
|
44
39
|
});
|
|
45
|
-
const wrapper =
|
|
46
|
-
const okButton = wrapper.getByTestId(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
41
|
+
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
42
|
+
fireEvent(okButton, `onPress`);
|
|
43
|
+
expectTextExists(wrapper, `Food`);
|
|
44
|
+
expectTextExists(wrapper, `Additional`);
|
|
45
|
+
expectTextExists(wrapper, `1`);
|
|
46
|
+
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
47
|
+
expectTextExists(wrapper, `0.25`);
|
|
53
48
|
});
|
|
54
49
|
test(`25 recommended carbs - editing`, () => {
|
|
55
|
-
const props =
|
|
50
|
+
const props = getRecommendationProps({
|
|
56
51
|
calculatorParams: {
|
|
57
|
-
...
|
|
52
|
+
...getRecommendationProps().calculatorParams,
|
|
58
53
|
currentBGL: 2.2,
|
|
59
54
|
recentBoluses: [],
|
|
60
55
|
},
|
|
61
56
|
});
|
|
62
|
-
const wrapper =
|
|
63
|
-
const okButton = wrapper.getByTestId(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const textInput = wrapper.getByTestId(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
57
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
58
|
+
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
59
|
+
fireEvent(okButton, `onPress`);
|
|
60
|
+
expectTextExists(wrapper, `Food`);
|
|
61
|
+
expectTextExists(wrapper, `Additional`);
|
|
62
|
+
expectTextExists(wrapper, `5`);
|
|
63
|
+
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
64
|
+
expectTextExists(wrapper, `0.25`);
|
|
65
|
+
const textInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
66
|
+
fireEvent(textInput, `onChangeText`, `85`);
|
|
67
|
+
expectTextNotExists(wrapper, `6`);
|
|
68
|
+
expectTextExists(wrapper, `85`);
|
|
74
69
|
});
|
|
75
70
|
test(`No recommended carbs`, () => {
|
|
76
|
-
const props =
|
|
71
|
+
const props = getRecommendationProps({
|
|
77
72
|
calculatorParams: {
|
|
78
73
|
currentBGL: 11,
|
|
79
74
|
carbohydrates: 25,
|
|
@@ -85,16 +80,16 @@ describe(`RecommendationScreen`, () => {
|
|
|
85
80
|
},
|
|
86
81
|
userReminder: 6,
|
|
87
82
|
});
|
|
88
|
-
const wrapper =
|
|
89
|
-
const okayButton = wrapper.getByTestId(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
84
|
+
const okayButton = wrapper.getByTestId(RecommendationModalTestIds.OkButton);
|
|
85
|
+
fireEvent(okayButton, `onPress`);
|
|
86
|
+
expectTextExists(wrapper, `Food`);
|
|
87
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
88
|
+
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
89
|
+
expectTextExists(wrapper, `6`);
|
|
95
90
|
});
|
|
96
91
|
test(`No recommended carbs under 0.5`, () => {
|
|
97
|
-
const props =
|
|
92
|
+
const props = getRecommendationProps({
|
|
98
93
|
calculatorParams: {
|
|
99
94
|
currentBGL: 6.9,
|
|
100
95
|
carbohydrates: 25,
|
|
@@ -105,13 +100,13 @@ describe(`RecommendationScreen`, () => {
|
|
|
105
100
|
activity: null,
|
|
106
101
|
},
|
|
107
102
|
});
|
|
108
|
-
const wrapper =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
104
|
+
expectTextExists(wrapper, `Food`);
|
|
105
|
+
expectTextNotExists(wrapper, `Recommended`);
|
|
106
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
112
107
|
});
|
|
113
108
|
test(`Remove recommended carbs`, () => {
|
|
114
|
-
const props =
|
|
109
|
+
const props = getRecommendationProps({
|
|
115
110
|
calculatorParams: {
|
|
116
111
|
currentBGL: 1.1,
|
|
117
112
|
carbohydrates: 25,
|
|
@@ -122,80 +117,80 @@ describe(`RecommendationScreen`, () => {
|
|
|
122
117
|
activity: null,
|
|
123
118
|
},
|
|
124
119
|
});
|
|
125
|
-
const wrapper =
|
|
126
|
-
const okButton = wrapper.getByTestId(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const removeButton = wrapper.getByTestId(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
120
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
121
|
+
const okButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
122
|
+
fireEvent(okButton, `onPress`);
|
|
123
|
+
expectTextExists(wrapper, `Food`);
|
|
124
|
+
expectTextExists(wrapper, `Additional`);
|
|
125
|
+
expectTextExists(wrapper, `1`);
|
|
126
|
+
const removeButton = wrapper.getByTestId(RecommendedCarbsTestIds.RemoveRecommendation);
|
|
127
|
+
fireEvent(removeButton, `onPress`);
|
|
128
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
129
|
+
expectTextNotExists(wrapper, `1`);
|
|
135
130
|
});
|
|
136
131
|
test(`Update remeasureTime to number > 0`, () => {
|
|
137
|
-
const props =
|
|
138
|
-
const wrapper =
|
|
139
|
-
|
|
140
|
-
const slider = wrapper.getByTestId(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
132
|
+
const props = getRecommendationProps();
|
|
133
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
134
|
+
expectTextExists(wrapper, `hours`);
|
|
135
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
136
|
+
fireEvent(slider, `onValueChange`, 3.2);
|
|
137
|
+
expectTextExists(wrapper, `3.2`);
|
|
138
|
+
expectTextExists(wrapper, `hours`);
|
|
144
139
|
});
|
|
145
140
|
test(`Update remeasureTime to 0`, () => {
|
|
146
|
-
const props =
|
|
147
|
-
const wrapper =
|
|
148
|
-
|
|
149
|
-
const slider = wrapper.getByTestId(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
const props = getRecommendationProps();
|
|
142
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
143
|
+
expectTextExists(wrapper, `hours`);
|
|
144
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
145
|
+
fireEvent(slider, `onValueChange`, 0);
|
|
146
|
+
expectTextExists(wrapper, `OFF`);
|
|
147
|
+
expectTextNotExists(wrapper, `hours`);
|
|
153
148
|
});
|
|
154
149
|
test(`Callback envoked when pressing 'Yes' on 'Recent Insulin'`, () => {
|
|
155
|
-
const props =
|
|
150
|
+
const props = getRecommendationProps({
|
|
156
151
|
calculatorParams: {
|
|
157
|
-
...
|
|
152
|
+
...getRecommendationProps().calculatorParams,
|
|
158
153
|
recentBoluses: [],
|
|
159
154
|
},
|
|
160
155
|
});
|
|
161
|
-
const wrapper =
|
|
156
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
162
157
|
expect(props.onRecentInsulinYes).not.toBeCalled();
|
|
163
|
-
|
|
164
|
-
const button = wrapper.getByTestId(
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
159
|
+
const button = wrapper.getByTestId(RecentInsulinTestIds.Yes);
|
|
160
|
+
fireEvent(button, `onPress`);
|
|
161
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
167
162
|
expect(props.onRecentInsulinYes).toBeCalled();
|
|
168
163
|
});
|
|
169
164
|
test(`Remove 'Recent Insulin' by pressing 'No'`, () => {
|
|
170
|
-
const props =
|
|
165
|
+
const props = getRecommendationProps({
|
|
171
166
|
calculatorParams: {
|
|
172
|
-
...
|
|
167
|
+
...getRecommendationProps().calculatorParams,
|
|
173
168
|
recentBoluses: [],
|
|
174
169
|
},
|
|
175
170
|
});
|
|
176
|
-
const wrapper =
|
|
177
|
-
|
|
178
|
-
const button = wrapper.getByTestId(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
171
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
172
|
+
expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
173
|
+
const button = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
174
|
+
fireEvent(button, `onPress`);
|
|
175
|
+
expectTextNotExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
176
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
177
|
+
expectTextExists(wrapper, `Units`);
|
|
183
178
|
});
|
|
184
179
|
test(`Selecting neutral will set neutral to active`, () => {
|
|
185
|
-
const props =
|
|
186
|
-
const wrapper =
|
|
180
|
+
const props = getRecommendationProps();
|
|
181
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
187
182
|
const neutral = MoodEnum[MoodEnum.Neutral];
|
|
188
|
-
const icon =
|
|
183
|
+
const icon = getIcon(wrapper, neutral, false);
|
|
189
184
|
if (icon === null) {
|
|
190
185
|
return fail(`No icon found for queryByA11yLabel: ${neutral}_${false}`);
|
|
191
186
|
}
|
|
192
|
-
|
|
193
|
-
expect(
|
|
194
|
-
expect(
|
|
187
|
+
fireEvent(icon, `onPress`);
|
|
188
|
+
expect(getIcon(wrapper, neutral, false)).toBeNull();
|
|
189
|
+
expect(getIcon(wrapper, neutral, true)).not.toBeNull();
|
|
195
190
|
});
|
|
196
191
|
test(`Updating carb recommendation & transfer`, () => {
|
|
197
192
|
const result = {};
|
|
198
|
-
const props =
|
|
193
|
+
const props = getRecommendationProps({
|
|
199
194
|
calculatorParams: {
|
|
200
195
|
currentBGL: 1.1,
|
|
201
196
|
carbohydrates: 25,
|
|
@@ -219,35 +214,35 @@ describe(`RecommendationScreen`, () => {
|
|
|
219
214
|
entered: null,
|
|
220
215
|
suggested: 0,
|
|
221
216
|
};
|
|
222
|
-
const wrapper =
|
|
223
|
-
expect(
|
|
224
|
-
expect(
|
|
225
|
-
expect(
|
|
217
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
218
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`25`);
|
|
219
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`1`);
|
|
220
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`26`);
|
|
226
221
|
// Expect text from carbs -> change -> Expect text updated -> Transfer -> Expect callback
|
|
227
|
-
const carbInput = wrapper.getByTestId(
|
|
222
|
+
const carbInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
228
223
|
// Input 3 into the carbs field
|
|
229
|
-
|
|
230
|
-
expect(
|
|
231
|
-
expect(
|
|
232
|
-
expect(
|
|
224
|
+
fireEvent(carbInput, `onEnd`, carbsExpected.entered);
|
|
225
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`25`);
|
|
226
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`3`);
|
|
227
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`28`);
|
|
233
228
|
// To make the transfer button visible we need to press the "no" option
|
|
234
|
-
|
|
235
|
-
const noButton = wrapper.getByTestId(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const transfer = wrapper.getByTestId(
|
|
229
|
+
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
230
|
+
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
231
|
+
fireEvent(noButton, `onPress`);
|
|
232
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
233
|
+
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
239
234
|
// Press transfer
|
|
240
|
-
|
|
235
|
+
fireEvent(transfer, `onPress`);
|
|
241
236
|
expect(props.transferToLogbook).toBeCalled();
|
|
242
237
|
expect(result.carbs?.entered).toBeCloseTo(carbsExpected.entered, 1);
|
|
243
238
|
expect(result.carbs?.suggested).toBeCloseTo(carbsExpected.suggested, 1);
|
|
244
239
|
expect(result.insulin?.entered).toBe(insulinExpected.entered);
|
|
245
240
|
expect(result.insulin?.suggested).toBeCloseTo(insulinExpected.suggested, 1);
|
|
246
|
-
expect(result.reminder).toBe(
|
|
241
|
+
expect(result.reminder).toBe(RecommendationReminders.Reminder15Minutes);
|
|
247
242
|
});
|
|
248
243
|
test(`Removing carb recommendation still returns suggested in transfer`, () => {
|
|
249
244
|
const result = {};
|
|
250
|
-
const props =
|
|
245
|
+
const props = getRecommendationProps({
|
|
251
246
|
calculatorParams: {
|
|
252
247
|
currentBGL: 1.1,
|
|
253
248
|
carbohydrates: 25,
|
|
@@ -271,48 +266,48 @@ describe(`RecommendationScreen`, () => {
|
|
|
271
266
|
entered: null,
|
|
272
267
|
suggested: 0,
|
|
273
268
|
};
|
|
274
|
-
const wrapper =
|
|
269
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
275
270
|
// Expect text from carbs -> change -> Expect text updated -> Transfer -> Expect callback
|
|
276
|
-
|
|
277
|
-
const removeButton = wrapper.getByTestId(
|
|
271
|
+
expectTextExists(wrapper, `1`);
|
|
272
|
+
const removeButton = wrapper.getByTestId(RecommendedCarbsTestIds.RemoveRecommendation);
|
|
278
273
|
// Input 3 into the carbs field
|
|
279
|
-
|
|
274
|
+
fireEvent(removeButton, `onPress`);
|
|
280
275
|
// Expect text updated
|
|
281
|
-
|
|
276
|
+
expectTextNotExists(wrapper, `1`);
|
|
282
277
|
// To make the transfer button visible we need to press the "no" option
|
|
283
|
-
|
|
284
|
-
const noButton = wrapper.getByTestId(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const transfer = wrapper.getByTestId(
|
|
278
|
+
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
279
|
+
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
280
|
+
fireEvent(noButton, `onPress`);
|
|
281
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
282
|
+
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
288
283
|
// Press transfer
|
|
289
|
-
|
|
284
|
+
fireEvent(transfer, `onPress`);
|
|
290
285
|
expect(props.transferToLogbook).toBeCalled();
|
|
291
286
|
expect(result.carbs.entered).toBe(carbsExpected.entered);
|
|
292
287
|
expect(result.carbs.suggested).toBeCloseTo(carbsExpected.suggested, 1);
|
|
293
288
|
expect(result.insulin.entered).toBe(insulinExpected.entered);
|
|
294
289
|
expect(result.insulin.suggested).toBeCloseTo(insulinExpected.suggested, 1);
|
|
295
|
-
expect(result.reminder).toBe(
|
|
290
|
+
expect(result.reminder).toBe(RecommendationReminders.Reminder15Minutes);
|
|
296
291
|
});
|
|
297
292
|
test.each `
|
|
298
293
|
recentBoluses | shown
|
|
299
294
|
${[]} | ${true}
|
|
300
295
|
${[{ insulinDose: 4, secondsPassed: 5500 }]} | ${false}
|
|
301
296
|
`(`Only show recent insulin if recent boluses is empty`, ({ recentBoluses, shown }) => {
|
|
302
|
-
const props =
|
|
297
|
+
const props = getRecommendationProps({
|
|
303
298
|
calculatorParams: {
|
|
304
|
-
...
|
|
299
|
+
...getRecommendationProps().calculatorParams,
|
|
305
300
|
recentBoluses,
|
|
306
301
|
},
|
|
307
302
|
});
|
|
308
|
-
const wrapper =
|
|
303
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
309
304
|
if (shown) {
|
|
310
|
-
return
|
|
305
|
+
return expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
311
306
|
}
|
|
312
|
-
|
|
307
|
+
expectTextNotExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
313
308
|
});
|
|
314
309
|
test(`Updating insulin recommendation & transfer`, () => {
|
|
315
|
-
const props =
|
|
310
|
+
const props = getRecommendationProps({
|
|
316
311
|
calculatorParams: {
|
|
317
312
|
currentBGL: 10.8,
|
|
318
313
|
carbohydrates: 27,
|
|
@@ -333,26 +328,26 @@ describe(`RecommendationScreen`, () => {
|
|
|
333
328
|
entered: 7,
|
|
334
329
|
suggested: 2,
|
|
335
330
|
};
|
|
336
|
-
const wrapper =
|
|
331
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
337
332
|
// Expect text from insulin -> change -> Expect text updated -> Transfer -> Expect callback
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const noButton = wrapper.getByTestId(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const insulinInput = wrapper.getByTestId(
|
|
333
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
334
|
+
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
335
|
+
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
336
|
+
fireEvent(noButton, `onPress`);
|
|
337
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
338
|
+
const insulinInput = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
344
339
|
// Input 7 into the insulin field
|
|
345
|
-
|
|
340
|
+
fireEvent(insulinInput, `onEnd`, insulinExpected.entered);
|
|
346
341
|
// Expect text updated
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const transfer = wrapper.getByTestId(
|
|
342
|
+
expectTextNotExists(wrapper, `${insulinExpected.suggested}`);
|
|
343
|
+
expectTextExists(wrapper, `${insulinExpected.entered}`);
|
|
344
|
+
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
350
345
|
// Press transfer
|
|
351
|
-
|
|
346
|
+
fireEvent(transfer, `onPress`);
|
|
352
347
|
expect(props.transferToLogbook).toBeCalledWith(carbsExpected, insulinExpected, 3, new Date(global.Date.now()), null);
|
|
353
348
|
});
|
|
354
349
|
test(`Typing an invalid value on the insulin recommendation field, resets to Hedia suggestion`, () => {
|
|
355
|
-
const props =
|
|
350
|
+
const props = getRecommendationProps({
|
|
356
351
|
calculatorParams: {
|
|
357
352
|
currentBGL: 10.8,
|
|
358
353
|
carbohydrates: 27,
|
|
@@ -374,27 +369,27 @@ describe(`RecommendationScreen`, () => {
|
|
|
374
369
|
suggested: 2,
|
|
375
370
|
};
|
|
376
371
|
const invalidInsulin = 300;
|
|
377
|
-
const wrapper =
|
|
372
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
378
373
|
// Answer "No" to recent insulin
|
|
379
|
-
const noButton = wrapper.getByTestId(
|
|
380
|
-
|
|
374
|
+
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
375
|
+
fireEvent(noButton, `onPress`);
|
|
381
376
|
// Verify initial insulin suggestion matches expected
|
|
382
|
-
|
|
377
|
+
expectTextExists(wrapper, `${insulinExpected.suggested}`);
|
|
383
378
|
// Type invalid value - 300 - on insulinInput
|
|
384
|
-
const insulinInput = wrapper.getByTestId(
|
|
385
|
-
|
|
379
|
+
const insulinInput = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
380
|
+
fireEvent(insulinInput, `onEnd`, invalidInsulin);
|
|
386
381
|
// After onEnd event, verify the invalid entered value doesn't exist.
|
|
387
|
-
|
|
382
|
+
expectTextNotExists(wrapper, `${invalidInsulin}`);
|
|
388
383
|
// Value has been reset to initial suggestion
|
|
389
|
-
|
|
384
|
+
expectTextExists(wrapper, `${insulinExpected.suggested}`);
|
|
390
385
|
// Press transfer to logbook button
|
|
391
|
-
const transfer = wrapper.getByTestId(
|
|
392
|
-
|
|
386
|
+
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
387
|
+
fireEvent(transfer, `onPress`);
|
|
393
388
|
// Verify the transferred data
|
|
394
389
|
expect(props.transferToLogbook).toBeCalledWith(carbsExpected, insulinExpected, 3, new Date(global.Date.now()), null);
|
|
395
390
|
});
|
|
396
391
|
test(`Updating remeasure reminder`, () => {
|
|
397
|
-
const props =
|
|
392
|
+
const props = getRecommendationProps({
|
|
398
393
|
calculatorParams: {
|
|
399
394
|
currentBGL: 10.85,
|
|
400
395
|
carbohydrates: 27,
|
|
@@ -405,26 +400,26 @@ describe(`RecommendationScreen`, () => {
|
|
|
405
400
|
activity: null,
|
|
406
401
|
},
|
|
407
402
|
});
|
|
408
|
-
const wrapper =
|
|
403
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
409
404
|
// Expect text from insulin -> change -> Expect text updated -> Transfer -> Expect callback
|
|
410
|
-
const noButton = wrapper.getByTestId(
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
const slider = wrapper.getByTestId(
|
|
405
|
+
const noButton = wrapper.getByTestId(RecentInsulinTestIds.No);
|
|
406
|
+
fireEvent(noButton, `onPress`);
|
|
407
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
408
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
414
409
|
// Input 2.5 in remeasure slider
|
|
415
|
-
|
|
410
|
+
fireEvent(slider, `onValueChange`, 2.5);
|
|
416
411
|
// Expect text updated
|
|
417
|
-
|
|
418
|
-
|
|
412
|
+
expectTextNotExists(wrapper, `1.5`);
|
|
413
|
+
expectTextExists(wrapper, `2.5`);
|
|
419
414
|
const sad = MoodEnum[MoodEnum.Sad];
|
|
420
|
-
const icon =
|
|
415
|
+
const icon = getIcon(wrapper, sad, false);
|
|
421
416
|
if (icon === null) {
|
|
422
417
|
return fail(`Could not find icon from queryByA11yLabel: ${sad}_${false}`);
|
|
423
418
|
}
|
|
424
|
-
|
|
425
|
-
const transfer = wrapper.getByTestId(
|
|
419
|
+
fireEvent(icon, `onPress`);
|
|
420
|
+
const transfer = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
426
421
|
// Press transfer
|
|
427
|
-
|
|
422
|
+
fireEvent(transfer, `onPress`);
|
|
428
423
|
const carbsExpected = {
|
|
429
424
|
entered: null,
|
|
430
425
|
suggested: 0,
|
|
@@ -437,147 +432,147 @@ describe(`RecommendationScreen`, () => {
|
|
|
437
432
|
});
|
|
438
433
|
test.each `
|
|
439
434
|
locale | text
|
|
440
|
-
${
|
|
441
|
-
${
|
|
442
|
-
${
|
|
443
|
-
${
|
|
444
|
-
${
|
|
445
|
-
${
|
|
435
|
+
${Languages.da} | ${`INSULIN\nANBEFALING`}
|
|
436
|
+
${Languages.en} | ${`INSULIN\nRECOMMENDATION`}
|
|
437
|
+
${Languages.de} | ${`INSULIN\nEMPFEHLUNG`}
|
|
438
|
+
${Languages.es} | ${`RECOMENDACIÓN\nDE INSULINA`}
|
|
439
|
+
${Languages.it} | ${`PRESCRIZIONE DI\nINSULINA`}
|
|
440
|
+
${Languages.fr} | ${`RECOMMANDATION\nD’INSULINE`}
|
|
446
441
|
`(`Language props determine language shown; $locale`, ({ locale, text }) => {
|
|
447
|
-
const props =
|
|
442
|
+
const props = getRecommendationProps({
|
|
448
443
|
language: locale,
|
|
449
444
|
});
|
|
450
|
-
const wrapper =
|
|
451
|
-
|
|
445
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
446
|
+
expectTextExists(wrapper, text);
|
|
452
447
|
});
|
|
453
448
|
test(`Error is thrown when passing an unsupported language`, () => {
|
|
454
|
-
const props =
|
|
455
|
-
const wrapper =
|
|
456
|
-
|
|
457
|
-
expect(props.onError).toBeCalledWith(
|
|
449
|
+
const props = getRecommendationProps();
|
|
450
|
+
const wrapper = render(<RecommendationScreen {...props} language={`INVALID_LANGUAGE`}/>);
|
|
451
|
+
expectTextNotExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
452
|
+
expect(props.onError).toBeCalledWith(LanguageError());
|
|
458
453
|
});
|
|
459
454
|
test(`Error is thrown when passing an unsupported activity settings`, () => {
|
|
460
|
-
const props =
|
|
455
|
+
const props = getRecommendationProps({
|
|
461
456
|
calculatorParams: {
|
|
462
|
-
...
|
|
463
|
-
activity: { ...
|
|
457
|
+
...generateDefaultCalculatorParams(),
|
|
458
|
+
activity: { ...generateActivityProps(), activityIntensity: hard, activityDuration: 46 },
|
|
464
459
|
},
|
|
465
460
|
});
|
|
466
|
-
|
|
467
|
-
expect(props.onError).toBeCalledWith(new Error(
|
|
461
|
+
render(<RecommendationScreen {...props}/>);
|
|
462
|
+
expect(props.onError).toBeCalledWith(new Error(BolusCalculator.Enums.ActivityErrors.InvalidInterval));
|
|
468
463
|
});
|
|
469
464
|
test.each `
|
|
470
465
|
initialLocale | locale | initialText | text
|
|
471
|
-
${
|
|
472
|
-
${
|
|
473
|
-
${
|
|
474
|
-
${
|
|
475
|
-
${
|
|
476
|
-
${
|
|
466
|
+
${Languages.en} | ${Languages.da} | ${`INSULIN\nRECOMMENDATION`} | ${`INSULIN\nANBEFALING`}
|
|
467
|
+
${Languages.da} | ${Languages.de} | ${`INSULIN\nANBEFALING`} | ${`INSULIN\nEMPFEHLUNG`}
|
|
468
|
+
${Languages.de} | ${Languages.es} | ${`INSULIN\nEMPFEHLUNG`} | ${`RECOMENDACIÓN\nDE INSULINA`}
|
|
469
|
+
${Languages.es} | ${Languages.it} | ${`RECOMENDACIÓN\nDE INSULINA`} | ${`PRESCRIZIONE DI\nINSULINA`}
|
|
470
|
+
${Languages.it} | ${Languages.fr} | ${`PRESCRIZIONE DI\nINSULINA`} | ${`RECOMMANDATION\nD’INSULINE`}
|
|
471
|
+
${Languages.fr} | ${Languages.en} | ${`RECOMMANDATION\nD’INSULINE`} | ${`INSULIN\nRECOMMENDATION`}
|
|
477
472
|
`(`Changing language changes header text; initial-language:$initialLocale to changed-language:$locale`, ({ initialLocale, locale, initialText, text }) => {
|
|
478
|
-
const props =
|
|
479
|
-
const wrapper =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
wrapper.rerender(<
|
|
484
|
-
|
|
485
|
-
|
|
473
|
+
const props = getRecommendationProps({ language: initialLocale });
|
|
474
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
475
|
+
expectTextExists(wrapper, initialText);
|
|
476
|
+
expectTextNotExists(wrapper, text);
|
|
477
|
+
i18n.activate(locale);
|
|
478
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
479
|
+
expectTextNotExists(wrapper, initialText);
|
|
480
|
+
expectTextExists(wrapper, text);
|
|
486
481
|
});
|
|
487
482
|
test(`Timeout callback runs after 15 minutes`, () => {
|
|
488
|
-
const props =
|
|
489
|
-
const wrapper =
|
|
483
|
+
const props = getRecommendationProps();
|
|
484
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
490
485
|
expect(props.onError).not.toBeCalled();
|
|
491
486
|
jest.runAllTimers();
|
|
492
487
|
expect(props.onError).not.toBeCalled();
|
|
493
|
-
|
|
488
|
+
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
494
489
|
});
|
|
495
490
|
test(`Active Insulin defaults to an empty array`, () => {
|
|
496
|
-
const props =
|
|
491
|
+
const props = getRecommendationProps({
|
|
497
492
|
calculatorParams: {
|
|
498
|
-
...
|
|
493
|
+
...getRecommendationProps().calculatorParams,
|
|
499
494
|
currentBGL: 8,
|
|
500
495
|
targetBGL: 8,
|
|
501
496
|
recentBoluses: [],
|
|
502
497
|
},
|
|
503
498
|
});
|
|
504
|
-
const wrapper =
|
|
505
|
-
|
|
506
|
-
|
|
499
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
500
|
+
expectTextExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
501
|
+
expectTextExists(wrapper, `0`);
|
|
507
502
|
});
|
|
508
503
|
test(`InfoBars behave as expected with BGL & Active Insulin`, () => {
|
|
509
|
-
const { BloodGlucose: BGValueTestID, BloodKetone: BKValueTestID, ActiveInsulin: ActiveInsulinValueTestID, } =
|
|
510
|
-
const { ActiveInsulin: ActiveInsulinUnitTestID } =
|
|
504
|
+
const { BloodGlucose: BGValueTestID, BloodKetone: BKValueTestID, ActiveInsulin: ActiveInsulinValueTestID, } = InfoBarTestIds.Value;
|
|
505
|
+
const { ActiveInsulin: ActiveInsulinUnitTestID } = InfoBarTestIds.Unit;
|
|
511
506
|
const props = {
|
|
512
|
-
...
|
|
507
|
+
...getRecommendationProps({
|
|
513
508
|
calculatorParams: {
|
|
514
|
-
...
|
|
509
|
+
...getRecommendationProps().calculatorParams,
|
|
515
510
|
currentBGL: null,
|
|
516
511
|
},
|
|
517
512
|
}),
|
|
518
513
|
currentBKL: null,
|
|
519
514
|
};
|
|
520
|
-
const wrapper =
|
|
521
|
-
const shownKetoneValue =
|
|
522
|
-
const shownGlucoseValue =
|
|
523
|
-
const shownActiveInsulinValue =
|
|
524
|
-
const shownActiveInsulinUnit =
|
|
515
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
516
|
+
const shownKetoneValue = queryTextFromComponent(wrapper, BKValueTestID);
|
|
517
|
+
const shownGlucoseValue = queryTextFromComponent(wrapper, BGValueTestID);
|
|
518
|
+
const shownActiveInsulinValue = queryTextFromComponent(wrapper, ActiveInsulinValueTestID);
|
|
519
|
+
const shownActiveInsulinUnit = queryTextFromComponent(wrapper, ActiveInsulinUnitTestID);
|
|
525
520
|
expect(shownKetoneValue).toBe(`-.-`);
|
|
526
521
|
expect(shownGlucoseValue).toBe(`-.-`);
|
|
527
522
|
expect(shownActiveInsulinValue).not.toBe(`0`);
|
|
528
523
|
expect(shownActiveInsulinUnit).toBe(`units`);
|
|
529
524
|
});
|
|
530
525
|
test(`InfoBars displays bgl and ketones in mg/dL`, () => {
|
|
531
|
-
const { BloodGlucose: BGValueTestID, BloodKetone: BKValueTestID } =
|
|
532
|
-
const { BloodGlucose: BGUnitTestID, BloodKetone: BKUnitTestID } =
|
|
533
|
-
const props =
|
|
534
|
-
bloodGlucoseUnit:
|
|
535
|
-
bloodKetoneUnit:
|
|
526
|
+
const { BloodGlucose: BGValueTestID, BloodKetone: BKValueTestID } = InfoBarTestIds.Value;
|
|
527
|
+
const { BloodGlucose: BGUnitTestID, BloodKetone: BKUnitTestID } = InfoBarTestIds.Unit;
|
|
528
|
+
const props = getRecommendationProps({
|
|
529
|
+
bloodGlucoseUnit: BloodGlucoseUnit.MG_DL,
|
|
530
|
+
bloodKetoneUnit: BloodKetonesUnit.MG_DL,
|
|
536
531
|
});
|
|
537
532
|
const { currentBKL, calculatorParams: { currentBGL }, } = props;
|
|
538
|
-
const wrapper =
|
|
539
|
-
const shownKetoneUnit =
|
|
540
|
-
const shownKetoneValue =
|
|
541
|
-
const bklMGDL =
|
|
533
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
534
|
+
const shownKetoneUnit = queryTextFromComponent(wrapper, BKUnitTestID);
|
|
535
|
+
const shownKetoneValue = queryTextFromComponent(wrapper, BKValueTestID);
|
|
536
|
+
const bklMGDL = Utils.convertBKLToMGDL(currentBKL);
|
|
542
537
|
expect(shownKetoneUnit).toBe(`mg/dL`);
|
|
543
538
|
expect(shownKetoneValue).toBe(`${bklMGDL}`);
|
|
544
|
-
const shownGlucoseUnit =
|
|
545
|
-
const shownGlucoseValue =
|
|
546
|
-
const bglMGDL =
|
|
539
|
+
const shownGlucoseUnit = queryTextFromComponent(wrapper, BGUnitTestID);
|
|
540
|
+
const shownGlucoseValue = queryTextFromComponent(wrapper, BGValueTestID);
|
|
541
|
+
const bglMGDL = Utils.convertBGLToMGDL(currentBGL);
|
|
547
542
|
expect(shownGlucoseUnit).toBe(`mg/dL`);
|
|
548
543
|
expect(shownGlucoseValue).toBe(`${bglMGDL}`);
|
|
549
544
|
});
|
|
550
545
|
test(`InfoBars displays negative level currentBKL as 0`, () => {
|
|
551
|
-
const { BloodKetone: BKValueTestID } =
|
|
552
|
-
const { BloodKetone: BKUnitTestID } =
|
|
553
|
-
const props =
|
|
546
|
+
const { BloodKetone: BKValueTestID } = InfoBarTestIds.Value;
|
|
547
|
+
const { BloodKetone: BKUnitTestID } = InfoBarTestIds.Unit;
|
|
548
|
+
const props = getRecommendationProps({
|
|
554
549
|
currentBKL: 0,
|
|
555
|
-
bloodKetoneUnit:
|
|
550
|
+
bloodKetoneUnit: BloodKetonesUnit.MG_DL,
|
|
556
551
|
});
|
|
557
|
-
const wrapper =
|
|
558
|
-
const shownKetoneUnit =
|
|
559
|
-
const shownKetoneValue =
|
|
552
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
553
|
+
const shownKetoneUnit = queryTextFromComponent(wrapper, BKUnitTestID);
|
|
554
|
+
const shownKetoneValue = queryTextFromComponent(wrapper, BKValueTestID);
|
|
560
555
|
expect(shownKetoneValue).toBe(`0`);
|
|
561
556
|
expect(shownKetoneUnit).toBe(`mg/dL`);
|
|
562
557
|
});
|
|
563
558
|
test(`InfoBars displays null curentBKL and null BloodKetoneUnit as -`, () => {
|
|
564
|
-
const { BloodKetone: BKValueTestID } =
|
|
565
|
-
const { BloodKetone: BKUnitTestID } =
|
|
566
|
-
const props = { ...
|
|
567
|
-
const wrapper =
|
|
568
|
-
const shownKetoneUnit =
|
|
569
|
-
const shownKetoneValue =
|
|
559
|
+
const { BloodKetone: BKValueTestID } = InfoBarTestIds.Value;
|
|
560
|
+
const { BloodKetone: BKUnitTestID } = InfoBarTestIds.Unit;
|
|
561
|
+
const props = { ...getRecommendationProps(), currentBKL: null, bloodKetoneUnit: null };
|
|
562
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
563
|
+
const shownKetoneUnit = queryTextFromComponent(wrapper, BKUnitTestID);
|
|
564
|
+
const shownKetoneValue = queryTextFromComponent(wrapper, BKValueTestID);
|
|
570
565
|
expect(shownKetoneUnit).toBe(``);
|
|
571
566
|
expect(shownKetoneValue).toBe(`-`);
|
|
572
567
|
});
|
|
573
568
|
test(`Can display with null activityDisplayProps`, () => {
|
|
574
|
-
const props =
|
|
575
|
-
calculatorParams:
|
|
569
|
+
const props = getRecommendationProps({
|
|
570
|
+
calculatorParams: getRecommendationProps().calculatorParams,
|
|
576
571
|
activityDisplayProps: null,
|
|
577
572
|
});
|
|
578
|
-
const wrapper =
|
|
579
|
-
|
|
580
|
-
const shownInsulin =
|
|
573
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
574
|
+
expectTextExists(wrapper, `INSULIN\nRECOMMENDATION`);
|
|
575
|
+
const shownInsulin = queryTextFromComponent(wrapper, RecommendedInsulinTestIds.ShownInsulinText);
|
|
581
576
|
expect(shownInsulin).toBe(`0`);
|
|
582
577
|
});
|
|
583
578
|
test.each `
|
|
@@ -586,28 +581,28 @@ describe(`RecommendationScreen`, () => {
|
|
|
586
581
|
${moderate} | ${`Moderat`}
|
|
587
582
|
${hard} | ${`Hård`}
|
|
588
583
|
`(`Activity screen is displayed and intensity: $intensity can be translated`, ({ intensity, translation }) => {
|
|
589
|
-
const props =
|
|
584
|
+
const props = getRecommendationProps({
|
|
590
585
|
activityDisplayProps: { activityType: ActivityEnum.Run, activityTitle: null },
|
|
591
586
|
calculatorParams: {
|
|
592
|
-
...
|
|
587
|
+
...getRecommendationProps().calculatorParams,
|
|
593
588
|
activity: {
|
|
594
|
-
...
|
|
589
|
+
...generateActivityProps(),
|
|
595
590
|
activityIntensity: intensity,
|
|
596
591
|
},
|
|
597
592
|
},
|
|
598
593
|
});
|
|
599
|
-
const wrapper =
|
|
600
|
-
const englishText =
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
wrapper.rerender(<
|
|
605
|
-
|
|
606
|
-
|
|
594
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
595
|
+
const englishText = ActivityIntensityTranslations[intensity]();
|
|
596
|
+
expectTextExists(wrapper, englishText);
|
|
597
|
+
expectTextNotExists(wrapper, translation);
|
|
598
|
+
i18n.activate(Languages.da);
|
|
599
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
600
|
+
expectTextExists(wrapper, translation);
|
|
601
|
+
expectTextNotExists(wrapper, englishText);
|
|
607
602
|
});
|
|
608
603
|
test(`Show limitation page at recalculation`, () => {
|
|
609
604
|
const carbRecommendationAnswer = jest.fn();
|
|
610
|
-
const props =
|
|
605
|
+
const props = getRecommendationProps({
|
|
611
606
|
calculatorParams: {
|
|
612
607
|
currentBGL: 7,
|
|
613
608
|
carbohydrates: 1,
|
|
@@ -621,34 +616,34 @@ describe(`RecommendationScreen`, () => {
|
|
|
621
616
|
carbRecommendationAnswer,
|
|
622
617
|
});
|
|
623
618
|
// Render the screen, expecting a carb recommendation modal.
|
|
624
|
-
const wrapper =
|
|
625
|
-
|
|
619
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
620
|
+
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
626
621
|
// Get the yes button from the modal
|
|
627
|
-
const yesButton = wrapper.getByTestId(
|
|
628
|
-
|
|
622
|
+
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
623
|
+
fireEvent(yesButton, `onPress`);
|
|
629
624
|
expect(carbRecommendationAnswer).toBeCalledWith(true);
|
|
630
|
-
|
|
631
|
-
expect(
|
|
632
|
-
expect(
|
|
633
|
-
expect(
|
|
634
|
-
const carbInput = wrapper.getByTestId(
|
|
625
|
+
expectTextExists(wrapper, `Additional`);
|
|
626
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`1`);
|
|
627
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`3`);
|
|
628
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`4`);
|
|
629
|
+
const carbInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
635
630
|
const manualCarbInput = 299;
|
|
636
631
|
// Input 299 into the carbs field
|
|
637
|
-
|
|
638
|
-
expect(
|
|
639
|
-
expect(
|
|
640
|
-
expect(
|
|
632
|
+
fireEvent(carbInput, `onEnd`, manualCarbInput);
|
|
633
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.EnteredCarbs)).toBe(`1`);
|
|
634
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.RecommendedCarbs)).toBe(`299`);
|
|
635
|
+
expect(queryTextFromComponent(wrapper, RecommendedCarbsTestIds.TotalCarbs)).toBe(`300`);
|
|
641
636
|
// Expect text from limitation message after recalculation
|
|
642
|
-
|
|
643
|
-
const nextButton = wrapper.getByTestId(
|
|
644
|
-
|
|
645
|
-
|
|
637
|
+
expectTextExists(wrapper, `${Messages.RecommendationWasLimited()}`);
|
|
638
|
+
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
639
|
+
fireEvent(nextButton, `onPress`);
|
|
640
|
+
expectTextNotExists(wrapper, `${Messages.RecommendationWasLimited()}`);
|
|
646
641
|
});
|
|
647
642
|
});
|
|
648
643
|
describe(`Recommendation Screen - RecommendationModal related tests`, () => {
|
|
649
644
|
test(`Test decline carbs suggestion`, () => {
|
|
650
645
|
const carbRecommendationAnswer = jest.fn();
|
|
651
|
-
const props =
|
|
646
|
+
const props = getRecommendationProps({
|
|
652
647
|
calculatorParams: {
|
|
653
648
|
currentBGL: 1.1,
|
|
654
649
|
carbohydrates: 25,
|
|
@@ -661,16 +656,16 @@ describe(`Recommendation Screen - RecommendationModal related tests`, () => {
|
|
|
661
656
|
userReminder: 5,
|
|
662
657
|
carbRecommendationAnswer,
|
|
663
658
|
});
|
|
664
|
-
const wrapper =
|
|
665
|
-
const noButton = wrapper.getByTestId(
|
|
666
|
-
|
|
659
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
660
|
+
const noButton = wrapper.getByTestId(RecommendationModalTestIds.DeclineCarbs);
|
|
661
|
+
fireEvent(noButton, `onPress`);
|
|
667
662
|
expect(carbRecommendationAnswer).toBeCalledWith(false);
|
|
668
|
-
|
|
669
|
-
|
|
663
|
+
expectTextExists(wrapper, `Food`);
|
|
664
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
670
665
|
});
|
|
671
666
|
test(`Test accept carbs suggestion`, () => {
|
|
672
667
|
const carbRecommendationAnswer = jest.fn();
|
|
673
|
-
const props =
|
|
668
|
+
const props = getRecommendationProps({
|
|
674
669
|
calculatorParams: {
|
|
675
670
|
currentBGL: 1.1,
|
|
676
671
|
carbohydrates: 25,
|
|
@@ -683,17 +678,17 @@ describe(`Recommendation Screen - RecommendationModal related tests`, () => {
|
|
|
683
678
|
userReminder: 5,
|
|
684
679
|
carbRecommendationAnswer,
|
|
685
680
|
});
|
|
686
|
-
const wrapper =
|
|
687
|
-
|
|
688
|
-
const yesButton = wrapper.getByTestId(
|
|
689
|
-
|
|
681
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
682
|
+
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
683
|
+
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
684
|
+
fireEvent(yesButton, `onPress`);
|
|
690
685
|
expect(carbRecommendationAnswer).toBeCalledWith(true);
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
686
|
+
expectTextExists(wrapper, `Food`);
|
|
687
|
+
expectTextExists(wrapper, `Additional`);
|
|
688
|
+
expectTextExists(wrapper, `1`);
|
|
694
689
|
});
|
|
695
690
|
test(`Test dismiss react-native 2 "page" modal no carbs recommended`, () => {
|
|
696
|
-
const props =
|
|
691
|
+
const props = getRecommendationProps({
|
|
697
692
|
calculatorParams: {
|
|
698
693
|
currentBGL: 27,
|
|
699
694
|
carbohydrates: 25,
|
|
@@ -701,166 +696,166 @@ describe(`Recommendation Screen - RecommendationModal related tests`, () => {
|
|
|
701
696
|
insulinSensitivity: 0.3,
|
|
702
697
|
targetBGL: 7,
|
|
703
698
|
recentBoluses: [],
|
|
704
|
-
activity:
|
|
699
|
+
activity: generateActivityProps(),
|
|
705
700
|
},
|
|
706
701
|
userReminder: 5,
|
|
707
702
|
});
|
|
708
|
-
const wrapper =
|
|
709
|
-
const nextButton = wrapper.getByTestId(
|
|
710
|
-
|
|
711
|
-
const yesButton = wrapper.getByTestId(
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
703
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
704
|
+
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
705
|
+
fireEvent(nextButton, `onPress`);
|
|
706
|
+
const yesButton = wrapper.getByTestId(RecommendationModalTestIds.OkButton);
|
|
707
|
+
fireEvent(yesButton, `onPress`);
|
|
708
|
+
expectTextExists(wrapper, `Food`);
|
|
709
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
710
|
+
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
711
|
+
expectTextExists(wrapper, `${RecommendationReminders.Reminder15Minutes}`);
|
|
717
712
|
});
|
|
718
713
|
});
|
|
719
714
|
describe(`Recommendation Screen - TwoOptionModal related tests`, () => {
|
|
720
715
|
test(`Save to logbook from ExitModal option`, () => {
|
|
721
|
-
const props =
|
|
722
|
-
const wrapper =
|
|
716
|
+
const props = getRecommendationProps();
|
|
717
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
723
718
|
//press exit button
|
|
724
|
-
const exitButton = wrapper.getByTestId(
|
|
725
|
-
|
|
719
|
+
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
720
|
+
fireEvent(exitButton, `onPress`);
|
|
726
721
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
727
|
-
const saveToLogbookModalButton = wrapper.getByTestId(
|
|
728
|
-
|
|
722
|
+
const saveToLogbookModalButton = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
723
|
+
fireEvent(saveToLogbookModalButton, `onPress`);
|
|
729
724
|
expect(props.transferToLogbook).toBeCalled();
|
|
730
|
-
|
|
731
|
-
|
|
725
|
+
expectTextNotExists(wrapper, `Save to logbook`);
|
|
726
|
+
expectTextNotExists(wrapper, `Close calculation`);
|
|
732
727
|
});
|
|
733
728
|
test(`Close calculation callback from ExitModal option`, () => {
|
|
734
|
-
const props =
|
|
735
|
-
const wrapper =
|
|
729
|
+
const props = getRecommendationProps();
|
|
730
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
736
731
|
//press exit button
|
|
737
|
-
const exitButton = wrapper.getByTestId(
|
|
738
|
-
|
|
732
|
+
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
733
|
+
fireEvent(exitButton, `onPress`);
|
|
739
734
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
740
|
-
const closeCalculation = wrapper.getByTestId(
|
|
741
|
-
|
|
735
|
+
const closeCalculation = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
736
|
+
fireEvent(closeCalculation, `onPress`);
|
|
742
737
|
expect(props.closeCalculationCallback).toBeCalled();
|
|
743
|
-
|
|
744
|
-
|
|
738
|
+
expectTextNotExists(wrapper, `Save to logbook`);
|
|
739
|
+
expectTextNotExists(wrapper, `Close calculation`);
|
|
745
740
|
});
|
|
746
741
|
test(`Test exitCallback callback when recentInsulin component is visible`, () => {
|
|
747
|
-
const props =
|
|
748
|
-
calculatorParams: { ...
|
|
742
|
+
const props = getRecommendationProps({
|
|
743
|
+
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
749
744
|
});
|
|
750
|
-
const wrapper =
|
|
751
|
-
const exitButton = wrapper.getByTestId(
|
|
752
|
-
|
|
753
|
-
|
|
745
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
746
|
+
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
747
|
+
fireEvent(exitButton, `onPress`);
|
|
748
|
+
expectTextExists(wrapper, `Have you taken insulin within the last 4 hours?`);
|
|
754
749
|
expect(props.showBolusBar).not.toBeCalled();
|
|
755
750
|
expect(props.exitCallback).toBeCalled();
|
|
756
751
|
});
|
|
757
752
|
test(`Test triggering on/off the ExitModal`, async () => {
|
|
758
|
-
const props =
|
|
759
|
-
const wrapper =
|
|
760
|
-
const exitButton = wrapper.getByTestId(
|
|
761
|
-
|
|
753
|
+
const props = getRecommendationProps();
|
|
754
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
755
|
+
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
756
|
+
fireEvent(exitButton, `onPress`);
|
|
762
757
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
const modalExitIcon = wrapper.getByTestId(
|
|
766
|
-
|
|
758
|
+
expectTextExists(wrapper, `Save to logbook`);
|
|
759
|
+
expectTextExists(wrapper, `Close calculation`);
|
|
760
|
+
const modalExitIcon = wrapper.getByTestId(TwoOptionModalTestIds.ExitButton);
|
|
761
|
+
fireEvent(modalExitIcon, `onPress`);
|
|
767
762
|
expect(props.showBolusBar).toBeCalledWith(true);
|
|
768
|
-
|
|
769
|
-
|
|
763
|
+
expectTextNotExists(wrapper, `Save to logbook`);
|
|
764
|
+
expectTextNotExists(wrapper, `Close calculation`);
|
|
770
765
|
});
|
|
771
766
|
test(`Can translate ExitModal option`, () => {
|
|
772
|
-
const props =
|
|
773
|
-
const wrapper =
|
|
767
|
+
const props = getRecommendationProps({ language: Languages.da });
|
|
768
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
774
769
|
//press exit button
|
|
775
|
-
const exitButton = wrapper.getByTestId(
|
|
776
|
-
|
|
770
|
+
const exitButton = wrapper.getByTestId(HeaderTestIds.ExitCalculation);
|
|
771
|
+
fireEvent(exitButton, `onPress`);
|
|
777
772
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
773
|
+
expectTextExists(wrapper, `Luk beregning`);
|
|
774
|
+
expectTextExists(wrapper, `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`);
|
|
775
|
+
expectTextExists(wrapper, `Gem i logbog`);
|
|
776
|
+
expectTextExists(wrapper, `Vil du gemme din indtastning?`);
|
|
782
777
|
});
|
|
783
778
|
test(`Test TimeoutModal first option WITH recommendation visible`, () => {
|
|
784
|
-
const props =
|
|
785
|
-
const wrapper =
|
|
779
|
+
const props = getRecommendationProps();
|
|
780
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
786
781
|
expect(props.onError).not.toBeCalled();
|
|
787
782
|
jest.runAllTimers();
|
|
788
783
|
expect(props.onError).not.toBeCalled();
|
|
789
|
-
const modalExitIcon = wrapper.queryByTestId(
|
|
784
|
+
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
790
785
|
expect(modalExitIcon).toBeNull();
|
|
791
786
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
wrapper.rerender(<
|
|
787
|
+
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
788
|
+
expectTextExists(wrapper, `Yes, save to logbook`);
|
|
789
|
+
expectTextExists(wrapper, `No, return to dashboard`);
|
|
790
|
+
i18n.activate(Languages.da);
|
|
791
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
797
792
|
jest.runAllTimers();
|
|
798
|
-
|
|
799
|
-
const saveToLogbook = wrapper.getByTestId(
|
|
800
|
-
|
|
793
|
+
expectTextExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
794
|
+
const saveToLogbook = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
795
|
+
fireEvent(saveToLogbook, `onPress`);
|
|
801
796
|
expect(props.transferToLogbook).toBeCalled();
|
|
802
797
|
});
|
|
803
798
|
test(`Test TimeoutModal second option WITH recommendation visible`, () => {
|
|
804
|
-
const props =
|
|
805
|
-
const wrapper =
|
|
799
|
+
const props = getRecommendationProps();
|
|
800
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
806
801
|
expect(props.onError).not.toBeCalled();
|
|
807
802
|
jest.runAllTimers();
|
|
808
803
|
expect(props.onError).not.toBeCalled();
|
|
809
|
-
const modalExitIcon = wrapper.queryByTestId(
|
|
804
|
+
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
810
805
|
expect(modalExitIcon).toBeNull();
|
|
811
806
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const returnToDashboard = wrapper.getByTestId(
|
|
816
|
-
|
|
807
|
+
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
808
|
+
expectTextExists(wrapper, `Yes, save to logbook`);
|
|
809
|
+
expectTextExists(wrapper, `No, return to dashboard`);
|
|
810
|
+
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
811
|
+
fireEvent(returnToDashboard, `onPress`);
|
|
817
812
|
expect(props.closeCalculationCallback).toBeCalled();
|
|
818
813
|
});
|
|
819
814
|
test(`Test TimeoutModal second option WITH recommendation NOT visible`, () => {
|
|
820
|
-
const props =
|
|
821
|
-
calculatorParams: { ...
|
|
815
|
+
const props = getRecommendationProps({
|
|
816
|
+
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
822
817
|
});
|
|
823
|
-
const wrapper =
|
|
818
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
824
819
|
expect(props.onError).not.toBeCalled();
|
|
825
820
|
jest.runAllTimers();
|
|
826
821
|
expect(props.onError).not.toBeCalled();
|
|
827
|
-
const modalExitIcon = wrapper.queryByTestId(
|
|
822
|
+
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
828
823
|
expect(modalExitIcon).toBeNull();
|
|
829
824
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
const returnToDashboard = wrapper.getByTestId(
|
|
834
|
-
|
|
825
|
+
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
826
|
+
expectTextExists(wrapper, `Start new calculation`);
|
|
827
|
+
expectTextExists(wrapper, `Return to dashboard`);
|
|
828
|
+
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
829
|
+
fireEvent(returnToDashboard, `onPress`);
|
|
835
830
|
expect(props.closeCalculationCallback).toBeCalled();
|
|
836
|
-
|
|
837
|
-
|
|
831
|
+
expectTextNotExists(wrapper, `Start new calculation`);
|
|
832
|
+
expectTextNotExists(wrapper, `Return to dashboard`);
|
|
838
833
|
});
|
|
839
834
|
test(`Test TimeoutModal first option WITH recommendation NOT visible`, () => {
|
|
840
|
-
const props =
|
|
841
|
-
calculatorParams: { ...
|
|
835
|
+
const props = getRecommendationProps({
|
|
836
|
+
calculatorParams: { ...generateDefaultCalculatorParams(), recentBoluses: [] },
|
|
842
837
|
});
|
|
843
|
-
const wrapper =
|
|
838
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
844
839
|
expect(props.onError).not.toBeCalled();
|
|
845
840
|
jest.runAllTimers();
|
|
846
841
|
expect(props.onError).not.toBeCalled();
|
|
847
|
-
const modalExitIcon = wrapper.queryByTestId(
|
|
842
|
+
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
848
843
|
expect(modalExitIcon).toBeNull();
|
|
849
844
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
wrapper.rerender(<
|
|
845
|
+
expectTextExists(wrapper, `More than 15 minutes has passed since this calculation was started.`);
|
|
846
|
+
expectTextExists(wrapper, `Start new calculation`);
|
|
847
|
+
expectTextExists(wrapper, `Return to dashboard`);
|
|
848
|
+
i18n.activate(Languages.da);
|
|
849
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
855
850
|
jest.runAllTimers();
|
|
856
|
-
|
|
857
|
-
const returnToDashboard = wrapper.getByTestId(
|
|
858
|
-
|
|
851
|
+
expectTextExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
852
|
+
const returnToDashboard = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
853
|
+
fireEvent(returnToDashboard, `onPress`);
|
|
859
854
|
expect(props.restartCalculation).toBeCalled();
|
|
860
|
-
|
|
855
|
+
expectTextNotExists(wrapper, `Der er gået mere end 15 minutter siden udregningen blev startet.`);
|
|
861
856
|
});
|
|
862
857
|
test(`Opening the app with a old calculation will show the timeout modal`, () => {
|
|
863
|
-
const props =
|
|
858
|
+
const props = getRecommendationProps();
|
|
864
859
|
let appStateListener;
|
|
865
860
|
const getMockAppStateListener = jest.fn((event, callback) => {
|
|
866
861
|
if (event === `change`) {
|
|
@@ -872,30 +867,30 @@ describe(`Recommendation Screen - TwoOptionModal related tests`, () => {
|
|
|
872
867
|
addEventListener: getMockAppStateListener,
|
|
873
868
|
removeEventListener: jest.fn(),
|
|
874
869
|
}));
|
|
875
|
-
const wrapper =
|
|
870
|
+
const wrapper = render(<RecommendationScreen {...props}/>);
|
|
876
871
|
// @ts-ignore
|
|
877
872
|
appStateListener?.(`active`);
|
|
878
873
|
// Run twice to test else path
|
|
879
|
-
global.Date.now = () => new Date().getTime() +
|
|
874
|
+
global.Date.now = () => new Date().getTime() + Milliseconds.Minute * 14;
|
|
880
875
|
// @ts-ignore
|
|
881
876
|
appStateListener?.(`active`);
|
|
882
|
-
wrapper.rerender(<
|
|
877
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
883
878
|
expect(props.showBolusBar).not.toBeCalledWith(false);
|
|
884
|
-
|
|
885
|
-
global.Date.now = () => new Date().getTime() +
|
|
879
|
+
expectTextNotExists(wrapper, `No, return to dashboard`);
|
|
880
|
+
global.Date.now = () => new Date().getTime() + Milliseconds.Minute * 15;
|
|
886
881
|
// @ts-ignore
|
|
887
882
|
appStateListener(`active`);
|
|
888
|
-
wrapper.rerender(<
|
|
883
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
889
884
|
expect(props.showBolusBar).toBeCalledWith(false);
|
|
890
|
-
|
|
891
|
-
const closeModalButton = wrapper.getByTestId(
|
|
892
|
-
|
|
893
|
-
wrapper.rerender(<
|
|
894
|
-
|
|
885
|
+
expectTextExists(wrapper, `No, return to dashboard`);
|
|
886
|
+
const closeModalButton = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
887
|
+
fireEvent(closeModalButton, `secondOption`);
|
|
888
|
+
wrapper.rerender(<RecommendationScreen {...props}/>);
|
|
889
|
+
expectTextNotExists(wrapper, `No, return to dashboard`);
|
|
895
890
|
expect(props.showBolusBar).toBeCalledWith(true);
|
|
896
891
|
});
|
|
897
892
|
test(`Opening the app with a old calculation will show the timeout modal else path`, () => {
|
|
898
|
-
const props =
|
|
893
|
+
const props = getRecommendationProps();
|
|
899
894
|
let appStateListener;
|
|
900
895
|
const getMockAppStateListener = jest.fn((event, callback) => {
|
|
901
896
|
if (event === `change`) {
|
|
@@ -907,11 +902,11 @@ describe(`Recommendation Screen - TwoOptionModal related tests`, () => {
|
|
|
907
902
|
addEventListener: getMockAppStateListener,
|
|
908
903
|
removeEventListener: jest.fn(),
|
|
909
904
|
}));
|
|
910
|
-
const rendered =
|
|
905
|
+
const rendered = render(<RecommendationScreen {...props}/>);
|
|
911
906
|
// @ts-ignore
|
|
912
907
|
appStateListener(`NotAnAppStateStatus`);
|
|
913
|
-
rendered.rerender(<
|
|
908
|
+
rendered.rerender(<RecommendationScreen {...props}/>);
|
|
914
909
|
expect(props.showBolusBar).not.toBeCalled();
|
|
915
|
-
|
|
910
|
+
expectTextNotExists(rendered, `No, return to dashboard`);
|
|
916
911
|
});
|
|
917
912
|
});
|