@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
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const RecommendedInsulin_1 = __importDefault(require("../../components/RecommendedInsulin"));
|
|
11
|
-
const enum_1 = require("../../types/enum");
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
const SAFETY_INSULIN_LIMIT = types_1.BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
14
|
-
const InjectionMethod = types_1.UserSettings.Enums.InjectionMethod;
|
|
1
|
+
import { BolusCalculator, UserSettings } from "@hedia/types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Platform } from "react-native";
|
|
4
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
5
|
+
import RecommendedInsulin from "../../components/RecommendedInsulin";
|
|
6
|
+
import { RecommendedInsulinTestIds } from "../../types/enum";
|
|
7
|
+
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
8
|
+
const SAFETY_INSULIN_LIMIT = BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
9
|
+
const InjectionMethod = UserSettings.Enums.InjectionMethod;
|
|
15
10
|
const { PenHalf, PenWhole, Pump } = InjectionMethod;
|
|
16
11
|
describe(`RecommendedInsulin - Component`, () => {
|
|
17
|
-
afterEach(
|
|
12
|
+
afterEach(cleanup);
|
|
18
13
|
test(`Component is rendered`, () => {
|
|
19
14
|
const updateMock = jest.fn();
|
|
20
15
|
const method = Pump;
|
|
21
|
-
const wrapper =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const wrapper = render(<RecommendedInsulin insulinRecommendation={2.3} updateRecommendedInsulin={updateMock} injectionMethod={method} activityReduction={null} enteredInsulin={null}/>);
|
|
17
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
18
|
+
expectTextExists(wrapper, `2.3`);
|
|
19
|
+
expectTextExists(wrapper, `Units`);
|
|
25
20
|
});
|
|
26
21
|
test(`Insulin props defaults to 0`, () => {
|
|
27
22
|
const updateMock = jest.fn();
|
|
28
23
|
const method = PenHalf;
|
|
29
24
|
// @ts-ignore
|
|
30
|
-
const wrapper =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
const wrapper = render(<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={method}/>);
|
|
26
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
27
|
+
expectTextExists(wrapper, `0`);
|
|
28
|
+
expectTextExists(wrapper, `Units`);
|
|
34
29
|
});
|
|
35
30
|
test.each `
|
|
36
31
|
method | amount | result
|
|
@@ -45,23 +40,23 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
45
40
|
${Pump} | ${12.35} | ${12.4}
|
|
46
41
|
`(`Rounding $amount using $method to $result`, ({ amount, method, result, }) => {
|
|
47
42
|
const updateMock = jest.fn();
|
|
48
|
-
const wrapper =
|
|
43
|
+
const wrapper = render(
|
|
49
44
|
// @ts-ignore
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
const input = wrapper.getByTestId(
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={method}/>);
|
|
46
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
47
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
48
|
+
fireEvent(input, `onEnd`, amount);
|
|
49
|
+
expectTextExists(wrapper, `${result}`);
|
|
55
50
|
expect(updateMock).toBeCalledWith(result);
|
|
56
51
|
});
|
|
57
52
|
test(`Throw error on Unsupported InjectMethod`, () => {
|
|
58
53
|
const updateMock = jest.fn();
|
|
59
|
-
const wrapper =
|
|
54
|
+
const wrapper = render(
|
|
60
55
|
// @ts-ignore
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
const input = wrapper.getByTestId(
|
|
64
|
-
expect(() =>
|
|
56
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={`Error`}/>);
|
|
57
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
58
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
59
|
+
expect(() => fireEvent(input, `onEnd`)).toThrowError(`Unsupported InjectionMethod: Error`);
|
|
65
60
|
});
|
|
66
61
|
test.each `
|
|
67
62
|
value | result
|
|
@@ -69,13 +64,13 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
69
64
|
${0.1} | ${0.1}
|
|
70
65
|
`(`Will not remove leading zero from $value`, ({ result, value }) => {
|
|
71
66
|
const updateMock = jest.fn();
|
|
72
|
-
const wrapper =
|
|
67
|
+
const wrapper = render(
|
|
73
68
|
// @ts-ignore
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
const input = wrapper.getByTestId(
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump}/>);
|
|
70
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
71
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
72
|
+
fireEvent(input, `onEnd`, value);
|
|
73
|
+
expectTextExists(wrapper, `${result}`);
|
|
79
74
|
});
|
|
80
75
|
test.each `
|
|
81
76
|
value | result
|
|
@@ -83,22 +78,22 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
83
78
|
${`09.1`} | ${9.1}
|
|
84
79
|
`(`Will remove leading zero from $value`, ({ result, value }) => {
|
|
85
80
|
const updateMock = jest.fn();
|
|
86
|
-
const wrapper =
|
|
81
|
+
const wrapper = render(
|
|
87
82
|
// @ts-ignore
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
const input = wrapper.getByTestId(
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump}/>);
|
|
84
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
85
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
86
|
+
fireEvent(input, `partialInput`, value);
|
|
87
|
+
expectTextExists(wrapper, `${result}`);
|
|
93
88
|
});
|
|
94
89
|
test(`Pressing on TouchableOpacity will callback on the invisible text input`, () => {
|
|
95
90
|
const updateMock = jest.fn();
|
|
96
|
-
const wrapper =
|
|
91
|
+
const wrapper = render(
|
|
97
92
|
// @ts-ignore
|
|
98
|
-
<
|
|
99
|
-
|
|
100
|
-
const button = wrapper.getByTestId(
|
|
101
|
-
|
|
93
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump}/>);
|
|
94
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
95
|
+
const button = wrapper.getByTestId(RecommendedInsulinTestIds.EditRecommendedInsulin);
|
|
96
|
+
fireEvent(button, `onPress`);
|
|
102
97
|
});
|
|
103
98
|
test.each `
|
|
104
99
|
value | reduction | isCorrect
|
|
@@ -110,18 +105,18 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
110
105
|
${`15`} | ${0.75} | ${false}
|
|
111
106
|
`(`Throws an error at insulin limits`, ({ reduction, isCorrect, value }) => {
|
|
112
107
|
const updateMock = jest.fn();
|
|
113
|
-
const wrapper =
|
|
108
|
+
const wrapper = render(
|
|
114
109
|
// @ts-ignore
|
|
115
|
-
<
|
|
116
|
-
|
|
117
|
-
const input = wrapper.getByTestId(
|
|
118
|
-
|
|
110
|
+
<RecommendedInsulin activityReduction={reduction} updateRecommendedInsulin={updateMock} injectionMethod={Pump}/>);
|
|
111
|
+
expectTextExists(wrapper, `Recommended amount of insulin`);
|
|
112
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
113
|
+
fireEvent(input, `onEnd`, value);
|
|
119
114
|
if (isCorrect) {
|
|
120
|
-
|
|
115
|
+
expectTextExists(wrapper, value);
|
|
121
116
|
}
|
|
122
117
|
else {
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
expectTextNotExists(wrapper, value);
|
|
119
|
+
expectTextNotExists(wrapper, `OK`);
|
|
125
120
|
}
|
|
126
121
|
});
|
|
127
122
|
test.each `
|
|
@@ -136,10 +131,10 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
136
131
|
${0.9} | ${SAFETY_INSULIN_LIMIT * (1 - 0.9)} | ${`${0.9 * 100}%`}
|
|
137
132
|
`(`Recommendation is limited when entering over the maximum safety threshold of insulin when activity reduction is $reductionPercent`, ({ expected, reduction }) => {
|
|
138
133
|
const updateMock = jest.fn();
|
|
139
|
-
const wrapper =
|
|
140
|
-
const input = wrapper.getByTestId(
|
|
134
|
+
const wrapper = render(<RecommendedInsulin insulinRecommendation={expected} updateRecommendedInsulin={updateMock} injectionMethod={Pump} activityReduction={reduction} enteredInsulin={null}/>);
|
|
135
|
+
const input = wrapper.getByTestId(RecommendedInsulinTestIds.InvisibleInsulinInput);
|
|
141
136
|
const INVALID_INSULIN = SAFETY_INSULIN_LIMIT + 1;
|
|
142
|
-
|
|
137
|
+
fireEvent(input, `onEnd`, INVALID_INSULIN);
|
|
143
138
|
expect(updateMock).toBeCalledWith(expected);
|
|
144
139
|
});
|
|
145
140
|
test.each `
|
|
@@ -147,11 +142,11 @@ describe(`RecommendedInsulin - Component`, () => {
|
|
|
147
142
|
${`ios`} | ${`3%`}
|
|
148
143
|
${`android`} | ${`1%`}
|
|
149
144
|
`(`On $platform the component has $padding paddingBottom`, ({ padding, platform }) => {
|
|
150
|
-
|
|
145
|
+
Platform.OS = platform;
|
|
151
146
|
const updateMock = jest.fn();
|
|
152
|
-
const wrapper =
|
|
147
|
+
const wrapper = render(
|
|
153
148
|
// @ts-ignore
|
|
154
|
-
<
|
|
149
|
+
<RecommendedInsulin updateRecommendedInsulin={updateMock} injectionMethod={Pump}/>);
|
|
155
150
|
expect(!!new RegExp(`"paddingBottom":"${padding}"`).exec(JSON.stringify(wrapper.toJSON()))).toBeTruthy();
|
|
156
151
|
});
|
|
157
152
|
});
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const react_native_1 = require("react-native");
|
|
8
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
9
|
-
const Remeasure_1 = __importDefault(require("../../components/Remeasure"));
|
|
10
|
-
const enum_1 = require("../../types/enum");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
4
|
+
import Remeasure from "../../components/Remeasure";
|
|
5
|
+
import { RemeasureTestIds } from "../../types/enum";
|
|
6
|
+
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
12
7
|
describe(`Remeasure Component`, () => {
|
|
13
|
-
afterEach(
|
|
8
|
+
afterEach(cleanup);
|
|
14
9
|
test.each `
|
|
15
10
|
value | expected
|
|
16
11
|
${0} | ${`OFF`}
|
|
@@ -20,14 +15,14 @@ describe(`Remeasure Component`, () => {
|
|
|
20
15
|
${3.8} | ${`3.8`}
|
|
21
16
|
`(`Setting slider to $value displays $expected`, ({ value, expected }) => {
|
|
22
17
|
const onChange = jest.fn();
|
|
23
|
-
const wrapper =
|
|
24
|
-
|
|
25
|
-
const slider = wrapper.getByTestId(
|
|
26
|
-
|
|
27
|
-
wrapper.rerender(<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange}/>);
|
|
19
|
+
expectTextExists(wrapper, `1.5`);
|
|
20
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
21
|
+
fireEvent(slider, `onValueChange`, value);
|
|
22
|
+
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange}/>);
|
|
23
|
+
expectTextExists(wrapper, `Remind me to remeasure in`);
|
|
24
|
+
expectTextNotExists(wrapper, `1.5`);
|
|
25
|
+
expectTextExists(wrapper, expected);
|
|
31
26
|
expect(onChange).toBeCalledWith(value);
|
|
32
27
|
});
|
|
33
28
|
test.each `
|
|
@@ -42,18 +37,18 @@ describe(`Remeasure Component`, () => {
|
|
|
42
37
|
${55} | ${`6`} | ${6}
|
|
43
38
|
`(`Setting slider to edge-case $value displays $expected`, ({ value, expected, callbackValue }) => {
|
|
44
39
|
const onChange = jest.fn();
|
|
45
|
-
const wrapper =
|
|
46
|
-
|
|
47
|
-
const slider = wrapper.getByTestId(
|
|
48
|
-
|
|
49
|
-
wrapper.rerender(<
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange}/>);
|
|
41
|
+
expectTextExists(wrapper, `1.5`);
|
|
42
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
43
|
+
fireEvent(slider, `onValueChange`, value);
|
|
44
|
+
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange}/>);
|
|
45
|
+
expectTextNotExists(wrapper, `1.5`);
|
|
46
|
+
expectTextExists(wrapper, expected);
|
|
52
47
|
if (isNaN(Number(expected))) {
|
|
53
|
-
|
|
48
|
+
expectTextNotExists(wrapper, `hours`);
|
|
54
49
|
}
|
|
55
50
|
else {
|
|
56
|
-
|
|
51
|
+
expectTextExists(wrapper, `hours`);
|
|
57
52
|
}
|
|
58
53
|
expect(onChange).toBeCalledWith(callbackValue);
|
|
59
54
|
});
|
|
@@ -61,12 +56,12 @@ describe(`Remeasure Component`, () => {
|
|
|
61
56
|
const value = 1.5;
|
|
62
57
|
const expected = `1.5`;
|
|
63
58
|
const onChange = jest.fn();
|
|
64
|
-
const wrapper =
|
|
65
|
-
|
|
66
|
-
const slider = wrapper.getByTestId(
|
|
67
|
-
|
|
68
|
-
wrapper.rerender(<
|
|
69
|
-
|
|
59
|
+
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange}/>);
|
|
60
|
+
expectTextExists(wrapper, `1.5`);
|
|
61
|
+
const slider = wrapper.getByTestId(RemeasureTestIds.RemeasureSlider);
|
|
62
|
+
fireEvent(slider, `onValueChange`, value);
|
|
63
|
+
wrapper.rerender(<Remeasure remeasureTime={value} onSliderChange={onChange}/>);
|
|
64
|
+
expectTextExists(wrapper, expected);
|
|
70
65
|
expect(onChange).toBeCalledWith(value);
|
|
71
66
|
});
|
|
72
67
|
test.each `
|
|
@@ -74,9 +69,9 @@ describe(`Remeasure Component`, () => {
|
|
|
74
69
|
${`ios`} | ${`3%`}
|
|
75
70
|
${`android`} | ${`0%`}
|
|
76
71
|
`(`On $platform the slider has $margin marginHorizontal`, ({ margin, platform }) => {
|
|
77
|
-
|
|
72
|
+
Platform.OS = platform;
|
|
78
73
|
const onChange = jest.fn();
|
|
79
|
-
const wrapper =
|
|
74
|
+
const wrapper = render(<Remeasure remeasureTime={1.5} onSliderChange={onChange}/>);
|
|
80
75
|
expect(!!new RegExp(`RNCSlider",.*marginHorizontal":"${margin}"`).exec(JSON.stringify(wrapper.toJSON()))).toBeTruthy();
|
|
81
76
|
});
|
|
82
77
|
});
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
8
|
-
const TransferToLogbook_1 = __importDefault(require("../../components/TransferToLogbook"));
|
|
9
|
-
const enum_1 = require("../../types/enum");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "react-native-testing-library";
|
|
3
|
+
import TransferToLogbook from "../../components/TransferToLogbook";
|
|
4
|
+
import { TransferToLogbookTestIds } from "../../types/enum";
|
|
5
|
+
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
11
6
|
describe(`TransferToLogbook - Component`, () => {
|
|
12
7
|
test(`Is null when visible not visible`, () => {
|
|
13
8
|
const transferMock = jest.fn();
|
|
14
|
-
const wrapper =
|
|
15
|
-
|
|
9
|
+
const wrapper = render(<TransferToLogbook visible={false} transfer={transferMock}/>);
|
|
10
|
+
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
16
11
|
expect(transferMock).not.toBeCalled();
|
|
17
12
|
});
|
|
18
13
|
test(`Mounts with "transfer to logbook" text when visible`, () => {
|
|
19
14
|
const transferMock = jest.fn();
|
|
20
|
-
const wrapper =
|
|
21
|
-
|
|
15
|
+
const wrapper = render(<TransferToLogbook visible={true} transfer={transferMock}/>);
|
|
16
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
22
17
|
expect(transferMock).not.toBeCalled();
|
|
23
18
|
});
|
|
24
19
|
test(`Pressing the button will trigger the callback`, () => {
|
|
25
20
|
const transferMock = jest.fn();
|
|
26
|
-
const wrapper =
|
|
27
|
-
|
|
28
|
-
const button = wrapper.getByTestId(
|
|
21
|
+
const wrapper = render(<TransferToLogbook visible={true} transfer={transferMock}/>);
|
|
22
|
+
expectTextExists(wrapper, `Transfer to logbook`);
|
|
23
|
+
const button = wrapper.getByTestId(TransferToLogbookTestIds.TransferButton);
|
|
29
24
|
expect(transferMock).not.toBeCalled();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
fireEvent(button, `onPress`);
|
|
26
|
+
expectTextNotExists(wrapper, `Transfer to logbook`);
|
|
27
|
+
expectTextExists(wrapper, `Transferred to logbook`);
|
|
33
28
|
expect(transferMock).toBeCalled();
|
|
34
29
|
});
|
|
35
30
|
});
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
8
|
-
const TwoOptionModal_1 = __importDefault(require("../../components/TwoOptionModal"));
|
|
9
|
-
const enum_1 = require("../../types/enum");
|
|
10
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
3
|
+
import TwoOptionModal from "../../components/TwoOptionModal";
|
|
4
|
+
import { TwoOptionModalTestIds } from "../../types/enum";
|
|
5
|
+
import { expectTextExists } from "../utils";
|
|
11
6
|
describe(`TwoOptionModal Component`, () => {
|
|
12
|
-
afterEach(
|
|
7
|
+
afterEach(cleanup);
|
|
13
8
|
test(`Can can show text `, () => {
|
|
14
9
|
const props = {
|
|
15
10
|
firstOption: jest.fn(),
|
|
@@ -21,11 +16,11 @@ describe(`TwoOptionModal Component`, () => {
|
|
|
21
16
|
textSecondOption: `Luk beregning`,
|
|
22
17
|
title: `Vil du gemme din indtastning?`,
|
|
23
18
|
};
|
|
24
|
-
const wrapper =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const wrapper = render(<TwoOptionModal {...props}/>);
|
|
20
|
+
expectTextExists(wrapper, `Luk beregning`);
|
|
21
|
+
expectTextExists(wrapper, `Dine gemte indtastninger vil blive brugt til fremtidige beregninger.`);
|
|
22
|
+
expectTextExists(wrapper, `Gem i logbog`);
|
|
23
|
+
expectTextExists(wrapper, `Vil du gemme din indtastning?`);
|
|
29
24
|
});
|
|
30
25
|
test(`Test that callbacks are called`, () => {
|
|
31
26
|
const props = {
|
|
@@ -39,16 +34,16 @@ describe(`TwoOptionModal Component`, () => {
|
|
|
39
34
|
textSecondOption: `Luk beregning`,
|
|
40
35
|
title: `Vil du gemme din indtastning?`,
|
|
41
36
|
};
|
|
42
|
-
const wrapper =
|
|
43
|
-
|
|
44
|
-
const modalExitIcon = wrapper.getByTestId(
|
|
45
|
-
|
|
37
|
+
const wrapper = render(<TwoOptionModal {...props}/>);
|
|
38
|
+
expectTextExists(wrapper, `Luk beregning`);
|
|
39
|
+
const modalExitIcon = wrapper.getByTestId(TwoOptionModalTestIds.ExitButton);
|
|
40
|
+
fireEvent(modalExitIcon, `onPress`);
|
|
46
41
|
expect(props.onClose).toBeCalled();
|
|
47
|
-
const closeCalculation = wrapper.getByTestId(
|
|
48
|
-
|
|
42
|
+
const closeCalculation = wrapper.getByTestId(TwoOptionModalTestIds.SecondOption);
|
|
43
|
+
fireEvent(closeCalculation, `onPress`);
|
|
49
44
|
expect(props.secondOption).toBeCalled();
|
|
50
|
-
const firstOptionButton = wrapper.getByTestId(
|
|
51
|
-
|
|
45
|
+
const firstOptionButton = wrapper.getByTestId(TwoOptionModalTestIds.FirstOption);
|
|
46
|
+
fireEvent(firstOptionButton, `onPress`);
|
|
52
47
|
expect(props.firstOption).toBeCalled();
|
|
53
48
|
});
|
|
54
49
|
test(`Test it is not cancelable`, () => {
|
|
@@ -61,9 +56,9 @@ describe(`TwoOptionModal Component`, () => {
|
|
|
61
56
|
textSecondOption: `Luk beregning`,
|
|
62
57
|
title: `Vil du gemme din indtastning?`,
|
|
63
58
|
};
|
|
64
|
-
const wrapper =
|
|
65
|
-
|
|
66
|
-
const modalExitIcon = wrapper.queryByTestId(
|
|
59
|
+
const wrapper = render(<TwoOptionModal {...props}/>);
|
|
60
|
+
expectTextExists(wrapper, `Luk beregning`);
|
|
61
|
+
const modalExitIcon = wrapper.queryByTestId(TwoOptionModalTestIds.ExitButton);
|
|
67
62
|
expect(modalExitIcon).toBeNull();
|
|
68
63
|
});
|
|
69
64
|
});
|
package/src/__tests__/utils.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const react_1 = require("@lingui/react");
|
|
9
|
-
const react_2 = __importDefault(require("react"));
|
|
10
|
-
const i18nUtils_1 = require("../locale/i18nUtils");
|
|
11
|
-
const ActivityEnum = types_1.Activity.Enums.ActivityEnum;
|
|
12
|
-
const ActivityIntensity = types_1.Activity.Enums.ActivityIntensity;
|
|
13
|
-
const InjectionMethod = types_1.UserSettings.Enums.InjectionMethod;
|
|
1
|
+
import { Activity, BloodGlucoseUnit, BloodKetonesUnit, Languages, UserSettings } from "@hedia/types";
|
|
2
|
+
import { I18nProvider } from "@lingui/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { i18n } from "../locale/i18nUtils";
|
|
5
|
+
const ActivityEnum = Activity.Enums.ActivityEnum;
|
|
6
|
+
const ActivityIntensity = Activity.Enums.ActivityIntensity;
|
|
7
|
+
const InjectionMethod = UserSettings.Enums.InjectionMethod;
|
|
14
8
|
const { Run } = ActivityEnum;
|
|
15
9
|
const { moderate } = ActivityIntensity;
|
|
16
10
|
const { PenHalf } = InjectionMethod;
|
|
17
|
-
function getRecommendationProps(partials) {
|
|
11
|
+
export function getRecommendationProps(partials) {
|
|
18
12
|
return {
|
|
19
13
|
currentBKL: partials?.currentBKL ?? 0.1,
|
|
20
|
-
bloodKetoneUnit: partials?.bloodKetoneUnit ??
|
|
21
|
-
bloodGlucoseUnit: partials?.bloodGlucoseUnit ??
|
|
22
|
-
language: partials?.language ??
|
|
14
|
+
bloodKetoneUnit: partials?.bloodKetoneUnit ?? BloodKetonesUnit.MMOL_L,
|
|
15
|
+
bloodGlucoseUnit: partials?.bloodGlucoseUnit ?? BloodGlucoseUnit.MMOL_L,
|
|
16
|
+
language: partials?.language ?? Languages.en,
|
|
23
17
|
userReminder: partials?.userReminder ?? 1.5,
|
|
24
18
|
latestLogbookFrom6Hours: partials?.latestLogbookFrom6Hours ?? generateDefaultLogbook(),
|
|
25
19
|
calculatorParams: partials?.calculatorParams ?? generateDefaultCalculatorParams(),
|
|
@@ -38,8 +32,7 @@ function getRecommendationProps(partials) {
|
|
|
38
32
|
},
|
|
39
33
|
};
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
function generateDefaultCalculatorParams() {
|
|
35
|
+
export function generateDefaultCalculatorParams() {
|
|
43
36
|
return {
|
|
44
37
|
carbohydrateRatio: 10,
|
|
45
38
|
carbohydrates: 4,
|
|
@@ -59,8 +52,7 @@ function generateDefaultCalculatorParams() {
|
|
|
59
52
|
activity: null,
|
|
60
53
|
};
|
|
61
54
|
}
|
|
62
|
-
|
|
63
|
-
function generateActivityProps() {
|
|
55
|
+
export function generateActivityProps() {
|
|
64
56
|
return {
|
|
65
57
|
activityDate: new Date(),
|
|
66
58
|
activityDuration: 30,
|
|
@@ -68,8 +60,7 @@ function generateActivityProps() {
|
|
|
68
60
|
activitySettings: generateDefaultActivitySettings(),
|
|
69
61
|
};
|
|
70
62
|
}
|
|
71
|
-
|
|
72
|
-
function generateDefaultActivitySettings() {
|
|
63
|
+
export function generateDefaultActivitySettings() {
|
|
73
64
|
return {
|
|
74
65
|
hard: { fromFortysix: null, fromThirty: 0.25, fromZero: 1 },
|
|
75
66
|
light: { fromFortysix: 0.5, fromThirty: 0.75, fromZero: 1 },
|
|
@@ -78,8 +69,7 @@ function generateDefaultActivitySettings() {
|
|
|
78
69
|
target: 9,
|
|
79
70
|
};
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
function generateDefaultLogbook() {
|
|
72
|
+
export function generateDefaultLogbook() {
|
|
83
73
|
return {
|
|
84
74
|
blood_glucose_millimolar: 6,
|
|
85
75
|
carbohydrates_entered_grams: 25,
|
|
@@ -103,8 +93,7 @@ function generateDefaultLogbook() {
|
|
|
103
93
|
carbohydrates_modified_suggested_grams: null,
|
|
104
94
|
};
|
|
105
95
|
}
|
|
106
|
-
|
|
107
|
-
function expectTextExists(component, text) {
|
|
96
|
+
export function expectTextExists(component, text) {
|
|
108
97
|
const element = component.queryByText(text);
|
|
109
98
|
/*
|
|
110
99
|
if (!element) {
|
|
@@ -113,14 +102,12 @@ function expectTextExists(component, text) {
|
|
|
113
102
|
*/
|
|
114
103
|
return expect(element).not.toBeNull();
|
|
115
104
|
}
|
|
116
|
-
|
|
117
|
-
function queryTextFromComponent(wrapper, testID) {
|
|
105
|
+
export function queryTextFromComponent(wrapper, testID) {
|
|
118
106
|
const component = wrapper.getByTestId(testID);
|
|
119
107
|
const values = component.children;
|
|
120
108
|
return values.join(``);
|
|
121
109
|
}
|
|
122
|
-
|
|
123
|
-
function expectTextNotExists(component, text) {
|
|
110
|
+
export function expectTextNotExists(component, text) {
|
|
124
111
|
const element = component.queryByText(text);
|
|
125
112
|
/*
|
|
126
113
|
if (element) {
|
|
@@ -129,14 +116,11 @@ function expectTextNotExists(component, text) {
|
|
|
129
116
|
*/
|
|
130
117
|
return expect(element).toBeNull();
|
|
131
118
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return (<react_1.I18nProvider language={i18nUtils_1.i18n.language} i18n={i18nUtils_1.i18n}>
|
|
119
|
+
export function i18nProvided(element) {
|
|
120
|
+
return (<I18nProvider language={i18n.language} i18n={i18n}>
|
|
135
121
|
{element}
|
|
136
|
-
</
|
|
122
|
+
</I18nProvider>);
|
|
137
123
|
}
|
|
138
|
-
|
|
139
|
-
function getIcon(wrapper, name, active) {
|
|
124
|
+
export function getIcon(wrapper, name, active) {
|
|
140
125
|
return wrapper.queryByA11yLabel(`${name}_${active}`);
|
|
141
126
|
}
|
|
142
|
-
exports.getIcon = getIcon;
|