@hedia/recommendation-screen 2.1.3-beta.6 → 2.1.3
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 +29 -29
- package/coverage/coverage-final.json +27 -27
- 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 +1 -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,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
8
|
-
const InvisibleNumberInput_1 = __importDefault(require("../../components/InvisibleNumberInput"));
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
3
|
+
import InvisibleNumberInput from "../../components/InvisibleNumberInput";
|
|
9
4
|
describe(`InvisibleNumberInput Component`, () => {
|
|
10
|
-
afterEach(
|
|
5
|
+
afterEach(cleanup);
|
|
11
6
|
test(`Can take value from props`, () => {
|
|
12
7
|
const onEndMock = jest.fn();
|
|
13
8
|
const partialInputMock = jest.fn();
|
|
14
9
|
let callbackInput;
|
|
15
10
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
16
11
|
const startValue = `24`;
|
|
17
|
-
const NumberInput =
|
|
12
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={0} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} startValue={startValue} testID={TEST_ID}/>);
|
|
18
13
|
// @ts-ignore
|
|
19
14
|
callbackInput?.();
|
|
20
15
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
21
|
-
|
|
16
|
+
fireEvent(textInput, `onEndEditing`);
|
|
22
17
|
expect(partialInputMock).not.toBeCalled();
|
|
23
18
|
expect(onEndMock).toBeCalledWith(Number(startValue));
|
|
24
19
|
});
|
|
@@ -27,11 +22,11 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
27
22
|
const partialInputMock = jest.fn();
|
|
28
23
|
let callbackInput;
|
|
29
24
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
30
|
-
const NumberInput =
|
|
25
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={0} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} testID={TEST_ID}/>);
|
|
31
26
|
// @ts-ignore
|
|
32
27
|
callbackInput?.();
|
|
33
28
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
34
|
-
|
|
29
|
+
fireEvent(textInput, `onEndEditing`);
|
|
35
30
|
expect(partialInputMock).not.toBeCalled();
|
|
36
31
|
expect(onEndMock).toBeCalledWith(0);
|
|
37
32
|
});
|
|
@@ -48,14 +43,14 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
48
43
|
const partialInputMock = jest.fn();
|
|
49
44
|
let callbackInput;
|
|
50
45
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
51
|
-
const NumberInput =
|
|
46
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={0} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} testID={TEST_ID}/>);
|
|
52
47
|
// @ts-ignore
|
|
53
48
|
callbackInput?.();
|
|
54
49
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
55
|
-
|
|
50
|
+
fireEvent(textInput, `onChangeText`, input);
|
|
56
51
|
expect(partialInputMock).toBeCalledWith(`${result}`);
|
|
57
52
|
expect(onEndMock).not.toBeCalled();
|
|
58
|
-
|
|
53
|
+
fireEvent(textInput, `onEndEditing`);
|
|
59
54
|
expect(onEndMock).toBeCalledWith(result);
|
|
60
55
|
});
|
|
61
56
|
test(`Will send events when typing`, () => {
|
|
@@ -63,11 +58,11 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
63
58
|
const partialInputMock = jest.fn();
|
|
64
59
|
let callbackInput;
|
|
65
60
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
66
|
-
const NumberInput =
|
|
61
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={0} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} testID={TEST_ID}/>);
|
|
67
62
|
// @ts-ignore
|
|
68
63
|
callbackInput?.();
|
|
69
64
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
70
|
-
|
|
65
|
+
fireEvent.changeText(textInput, `22`);
|
|
71
66
|
expect(partialInputMock).toBeCalledWith(`22`);
|
|
72
67
|
expect(onEndMock).not.toBeCalled();
|
|
73
68
|
});
|
|
@@ -88,11 +83,11 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
88
83
|
const partialInputMock = jest.fn();
|
|
89
84
|
let callbackInput;
|
|
90
85
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
91
|
-
const NumberInput =
|
|
86
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={decimals} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} startValue={startValue} testID={TEST_ID}/>);
|
|
92
87
|
// @ts-ignore
|
|
93
88
|
callbackInput?.();
|
|
94
89
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
95
|
-
|
|
90
|
+
fireEvent(textInput, `onChangeText`, startValue);
|
|
96
91
|
expect(partialInputMock).toBeCalledWith(`${expected}`);
|
|
97
92
|
});
|
|
98
93
|
test.each `
|
|
@@ -115,11 +110,11 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
115
110
|
const partialInputMock = jest.fn();
|
|
116
111
|
let callbackInput;
|
|
117
112
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
118
|
-
const NumberInput =
|
|
113
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={true} decimalPlaces={decimals} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} startValue={startValue} testID={TEST_ID}/>);
|
|
119
114
|
// @ts-ignore
|
|
120
115
|
callbackInput?.();
|
|
121
116
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
122
|
-
|
|
117
|
+
fireEvent(textInput, `onChangeText`, startValue);
|
|
123
118
|
expect(partialInputMock).toBeCalledWith(`${expected}`);
|
|
124
119
|
});
|
|
125
120
|
test.each `
|
|
@@ -134,11 +129,11 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
134
129
|
const partialInputMock = jest.fn();
|
|
135
130
|
let callbackInput;
|
|
136
131
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
137
|
-
const NumberInput =
|
|
132
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={false} cleanPartialInput={false} decimalPlaces={decimals} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} startValue={startValue} testID={TEST_ID}/>);
|
|
138
133
|
// @ts-ignore
|
|
139
134
|
callbackInput?.();
|
|
140
135
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
141
|
-
|
|
136
|
+
fireEvent(textInput, `onChangeText`, startValue);
|
|
142
137
|
expect(partialInputMock).toBeCalledWith(expected);
|
|
143
138
|
});
|
|
144
139
|
test.each `
|
|
@@ -153,13 +148,13 @@ describe(`InvisibleNumberInput Component`, () => {
|
|
|
153
148
|
const partialInputMock = jest.fn();
|
|
154
149
|
let callbackInput;
|
|
155
150
|
const TEST_ID = `invisible-number-input-test-id`;
|
|
156
|
-
const NumberInput =
|
|
151
|
+
const NumberInput = render(<InvisibleNumberInput negativeAllowed={true} cleanPartialInput={false} decimalPlaces={decimals} onEnd={onEndMock} partialInput={partialInputMock} visible={(e) => (callbackInput = e)} startValue={startValue} testID={TEST_ID}/>);
|
|
157
152
|
// @ts-ignore
|
|
158
153
|
callbackInput?.();
|
|
159
154
|
const textInput = NumberInput.getByTestId(TEST_ID);
|
|
160
|
-
|
|
155
|
+
fireEvent(textInput, `onChangeText`, startValue);
|
|
161
156
|
expect(partialInputMock).toBeCalledWith(startValue);
|
|
162
|
-
|
|
157
|
+
fireEvent(textInput, `onEndEditing`, startValue);
|
|
163
158
|
expect(onEndMock).toBeCalledWith(expected);
|
|
164
159
|
});
|
|
165
160
|
});
|
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const i18nUtils_1 = require("../../locale/i18nUtils");
|
|
12
|
-
const enum_1 = require("../../types/enum");
|
|
13
|
-
const AttentionMessages_1 = require("../../utils/AttentionMessages");
|
|
14
|
-
const utils_1 = require("../utils");
|
|
15
|
-
const SAFETY_INSULIN_LIMIT = types_1.BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
1
|
+
import { BolusCalculator, Languages } from "@hedia/types";
|
|
2
|
+
import { I18nProvider } from "@lingui/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
5
|
+
import LimitationMessage from "../../components/LimitationMessage";
|
|
6
|
+
import { i18n } from "../../locale/i18nUtils";
|
|
7
|
+
import { LimitationMessageTestIds } from "../../types/enum";
|
|
8
|
+
import { Messages } from "../../utils/AttentionMessages";
|
|
9
|
+
import { expectTextExists } from "../utils";
|
|
10
|
+
const SAFETY_INSULIN_LIMIT = BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
16
11
|
describe(`Info Bars Component`, () => {
|
|
17
|
-
afterEach(
|
|
12
|
+
afterEach(cleanup);
|
|
18
13
|
beforeEach(() => {
|
|
19
|
-
|
|
14
|
+
i18n.activate(Languages.en);
|
|
20
15
|
});
|
|
21
16
|
test(`Can call the callback`, () => {
|
|
22
17
|
const onPressNextButton = jest.fn();
|
|
23
18
|
const props = {
|
|
24
|
-
limitationMessage:
|
|
19
|
+
limitationMessage: Messages.RecommendationWasLimited(),
|
|
25
20
|
onPressNextButton,
|
|
26
21
|
};
|
|
27
|
-
const limitationMessage =
|
|
28
|
-
const nextButton = limitationMessage.getByTestId(
|
|
29
|
-
|
|
22
|
+
const limitationMessage = render(<LimitationMessage {...props}/>);
|
|
23
|
+
const nextButton = limitationMessage.getByTestId(LimitationMessageTestIds.OkButton);
|
|
24
|
+
fireEvent(nextButton, `onPress`);
|
|
30
25
|
expect(onPressNextButton).toBeCalled();
|
|
31
26
|
});
|
|
32
27
|
test.each `
|
|
33
28
|
language | locale | message
|
|
34
|
-
${`English`} | ${
|
|
35
|
-
${`Danish`} | ${
|
|
36
|
-
${`German`} | ${
|
|
37
|
-
${`Spanish`} | ${
|
|
38
|
-
${`Italian`} | ${
|
|
39
|
-
${`French`} | ${
|
|
29
|
+
${`English`} | ${Languages.en} | ${`Your recommendation would have been higher than ${SAFETY_INSULIN_LIMIT} units of insulin, but it has been limited for safety reasons. Hedia never recommends more than ${SAFETY_INSULIN_LIMIT} units of insulin per calculation.`}
|
|
30
|
+
${`Danish`} | ${Languages.da} | ${`Din anbefaling ville have været højere end ${SAFETY_INSULIN_LIMIT} units af insulin, men den er blevet begrænset af sikkerhedshensyn. Hedia anbefaler aldrig mere end ${SAFETY_INSULIN_LIMIT} units af insulin per beregning.`}
|
|
31
|
+
${`German`} | ${Languages.de} | ${`Ihre Empfehlung wäre höher als ${SAFETY_INSULIN_LIMIT} Einheiten Insulin gewesen, aber sie wurde aus Sicherheitsgründen begrenzt. Hedia empfiehlt nie mehr als ${SAFETY_INSULIN_LIMIT} Einheiten Insulin pro Berechnung.`}
|
|
32
|
+
${`Spanish`} | ${Languages.es} | ${`Su recomendación habría sido superior a ${SAFETY_INSULIN_LIMIT} unidades de insulina, pero se ha limitado por razones de seguridad. Hedia nunca recomienda más de ${SAFETY_INSULIN_LIMIT} unidades de insulina por calculación.`}
|
|
33
|
+
${`Italian`} | ${Languages.it} | ${`La tua prescrizione sarebbe stata superiore a ${SAFETY_INSULIN_LIMIT} unità di insulina, ma è stata limitata per motivi di sicurezza. Hedia non prescrive mai più di ${SAFETY_INSULIN_LIMIT} unità di insulina per calcolo.`}
|
|
34
|
+
${`French`} | ${Languages.fr} | ${`Votre recommandation aurait été supérieure à ${SAFETY_INSULIN_LIMIT} unités d’insuline, mais elle a été limitée pour des raisons de sécurité. Hedia ne recommande jamais plus de ${SAFETY_INSULIN_LIMIT} unités d’insuline par calcul.`}
|
|
40
35
|
`(`Can display limitation message in $language`, ({ message, locale }) => {
|
|
41
|
-
|
|
36
|
+
i18n.activate(locale);
|
|
42
37
|
const onPressNextButton = jest.fn();
|
|
43
38
|
const props = {
|
|
44
|
-
limitationMessage:
|
|
39
|
+
limitationMessage: Messages.RecommendationWasLimited(),
|
|
45
40
|
onPressNextButton,
|
|
46
41
|
};
|
|
47
|
-
const limitationMessage =
|
|
48
|
-
<
|
|
49
|
-
</
|
|
50
|
-
|
|
42
|
+
const limitationMessage = render(<I18nProvider language={locale} i18n={i18n}>
|
|
43
|
+
<LimitationMessage {...props}/>,
|
|
44
|
+
</I18nProvider>);
|
|
45
|
+
expectTextExists(limitationMessage, message);
|
|
51
46
|
});
|
|
52
47
|
});
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const types_1 = require("@hedia/types");
|
|
7
|
-
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
9
|
-
const MoodIcon_1 = __importDefault(require("../../components/mood/MoodIcon"));
|
|
10
|
-
const MoodEnum = types_1.Logbook.Enums.MoodEnum;
|
|
1
|
+
import { Logbook } from "@hedia/types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
4
|
+
import MoodIcon from "../../components/mood/MoodIcon";
|
|
5
|
+
const MoodEnum = Logbook.Enums.MoodEnum;
|
|
11
6
|
describe(`MoodIcon - Component`, () => {
|
|
12
|
-
afterEach(
|
|
7
|
+
afterEach(cleanup);
|
|
13
8
|
test.each `
|
|
14
9
|
mood | moodName
|
|
15
10
|
${MoodEnum.Happy} | ${MoodEnum[MoodEnum.Happy]}
|
|
@@ -20,16 +15,16 @@ describe(`MoodIcon - Component`, () => {
|
|
|
20
15
|
`(`Mounting $moodName smiley is mounted inactive and can be toggled on`, ({ mood, moodName }) => {
|
|
21
16
|
let active = false;
|
|
22
17
|
const onPressMock = jest.fn((toggle) => (active = toggle));
|
|
23
|
-
const wrapper =
|
|
18
|
+
const wrapper = render(<MoodIcon active={active} mood={mood} onPress={onPressMock}/>);
|
|
24
19
|
const getButton = (isActive) => wrapper.getByA11yLabel(`${moodName}_${isActive}`);
|
|
25
20
|
const button = getButton(false);
|
|
26
21
|
if (button === null) {
|
|
27
22
|
return fail(`No button found for getByA11yLabel: ${moodName}_${false}`);
|
|
28
23
|
}
|
|
29
|
-
|
|
24
|
+
fireEvent(button, `onPress`);
|
|
30
25
|
expect(onPressMock).toBeCalledWith(true);
|
|
31
26
|
expect(active).toBe(true);
|
|
32
|
-
wrapper.rerender(<
|
|
27
|
+
wrapper.rerender(<MoodIcon active={active} mood={mood} onPress={onPressMock}/>);
|
|
33
28
|
expect(getButton(true)).not.toBeNull();
|
|
34
29
|
});
|
|
35
30
|
});
|
|
@@ -1,102 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const RecommendationModal_1 = __importDefault(require("../../components/RecommendationModal"));
|
|
11
|
-
const i18nUtils_1 = require("../../locale/i18nUtils");
|
|
12
|
-
const enum_1 = require("../../types/enum");
|
|
13
|
-
const AttentionMessages_1 = require("../../utils/AttentionMessages");
|
|
14
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { Languages } from "@hedia/types";
|
|
2
|
+
import { I18nProvider } from "@lingui/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
5
|
+
import RecommendationModal from "../../components/RecommendationModal";
|
|
6
|
+
import { i18n } from "../../locale/i18nUtils";
|
|
7
|
+
import { LimitationMessageTestIds, RecommendationModalTestIds } from "../../types/enum";
|
|
8
|
+
import { Messages } from "../../utils/AttentionMessages";
|
|
9
|
+
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
15
10
|
describe(`RecommendationModal Component`, () => {
|
|
16
|
-
afterEach(
|
|
11
|
+
afterEach(cleanup);
|
|
17
12
|
beforeEach(() => {
|
|
18
|
-
|
|
13
|
+
i18n.activate(Languages.en);
|
|
19
14
|
});
|
|
20
15
|
test(`start display with the second page`, () => {
|
|
21
16
|
const acceptMock = jest.fn();
|
|
22
17
|
const declineMock = jest.fn();
|
|
23
18
|
const onClickOkMock = jest.fn();
|
|
24
|
-
const wrapper =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const wrapper = render(<RecommendationModal isVisible={true} attentionMessage={null} limitationMessage={null} suggestedCarbohydrates={2} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>);
|
|
20
|
+
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
21
|
+
expectTextExists(wrapper, `2 `);
|
|
22
|
+
expectTextExists(wrapper, `grams of carbohydrates`);
|
|
23
|
+
expectTextExists(wrapper, `Instead of taking insulin`);
|
|
29
24
|
});
|
|
30
25
|
test(`accept carbs from second page`, () => {
|
|
31
26
|
const acceptMock = jest.fn();
|
|
32
27
|
const declineMock = jest.fn();
|
|
33
28
|
const onClickOkMock = jest.fn();
|
|
34
|
-
const wrapper =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const yesButtonModal = wrapper.getByTestId(
|
|
39
|
-
|
|
29
|
+
const wrapper = render(<RecommendationModal isVisible={true} attentionMessage={null} limitationMessage={null} suggestedCarbohydrates={5} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>);
|
|
30
|
+
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
31
|
+
expectTextExists(wrapper, `5 `);
|
|
32
|
+
expectTextExists(wrapper, `grams of carbohydrates`);
|
|
33
|
+
const yesButtonModal = wrapper.getByTestId(RecommendationModalTestIds.AcceptCarbs);
|
|
34
|
+
fireEvent(yesButtonModal, `onPress`);
|
|
40
35
|
expect(acceptMock).toBeCalled();
|
|
41
36
|
});
|
|
42
37
|
test(`decline carbs from second page`, () => {
|
|
43
38
|
const acceptMock = jest.fn();
|
|
44
39
|
const declineMock = jest.fn();
|
|
45
40
|
const onClickOkMock = jest.fn();
|
|
46
|
-
const wrapper =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const noButtonModal = wrapper.getByTestId(
|
|
50
|
-
|
|
41
|
+
const wrapper = render(<RecommendationModal isVisible={true} attentionMessage={null} limitationMessage={null} suggestedCarbohydrates={5} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>);
|
|
42
|
+
expectTextExists(wrapper, `We recommend eating an additional:`);
|
|
43
|
+
expectTextExists(wrapper, `grams of carbohydrates`);
|
|
44
|
+
const noButtonModal = wrapper.getByTestId(RecommendationModalTestIds.DeclineCarbs);
|
|
45
|
+
fireEvent(noButtonModal, `onPress`);
|
|
51
46
|
expect(declineMock).toBeCalled();
|
|
52
47
|
});
|
|
53
48
|
test(`test opens with first page and navigate to second`, () => {
|
|
54
49
|
const acceptMock = jest.fn();
|
|
55
50
|
const declineMock = jest.fn();
|
|
56
51
|
const onClickOkMock = jest.fn();
|
|
57
|
-
const limitation =
|
|
58
|
-
const attention =
|
|
59
|
-
const wrapper =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const nextButton = wrapper.getByTestId(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const okayButton = wrapper.getByTestId(
|
|
68
|
-
|
|
52
|
+
const limitation = Messages.RecommendationWasLimited();
|
|
53
|
+
const attention = Messages.VeryLowBGL();
|
|
54
|
+
const wrapper = render(<RecommendationModal isVisible={true} attentionMessage={attention} limitationMessage={limitation} suggestedCarbohydrates={0} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>);
|
|
55
|
+
expectTextExists(wrapper, limitation);
|
|
56
|
+
expectTextExists(wrapper, `OK`);
|
|
57
|
+
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
58
|
+
fireEvent(nextButton, `onPress`);
|
|
59
|
+
expectTextExists(wrapper, attention);
|
|
60
|
+
expectTextExists(wrapper, `OK`);
|
|
61
|
+
expectTextNotExists(wrapper, `We recommend eating an additional:`);
|
|
62
|
+
const okayButton = wrapper.getByTestId(RecommendationModalTestIds.OkButton);
|
|
63
|
+
fireEvent(okayButton, `onPress`);
|
|
69
64
|
expect(onClickOkMock).toBeCalled();
|
|
70
65
|
});
|
|
71
66
|
test(`close modal from first page if ther are no carbs or attention messages on second page`, () => {
|
|
72
67
|
const acceptMock = jest.fn();
|
|
73
68
|
const declineMock = jest.fn();
|
|
74
69
|
const onClickOkMock = jest.fn();
|
|
75
|
-
const limitation =
|
|
76
|
-
const wrapper =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const nextButton = wrapper.getByTestId(
|
|
80
|
-
|
|
70
|
+
const limitation = Messages.RecommendationWasLimited();
|
|
71
|
+
const wrapper = render(<RecommendationModal isVisible={true} attentionMessage={null} limitationMessage={limitation} suggestedCarbohydrates={0} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>);
|
|
72
|
+
expectTextExists(wrapper, limitation);
|
|
73
|
+
expectTextExists(wrapper, `OK`);
|
|
74
|
+
const nextButton = wrapper.getByTestId(LimitationMessageTestIds.OkButton);
|
|
75
|
+
fireEvent(nextButton, `onPress`);
|
|
81
76
|
expect(onClickOkMock).toBeCalled();
|
|
82
77
|
});
|
|
83
78
|
test.each `
|
|
84
79
|
language | locale | message
|
|
85
|
-
${`English`} | ${
|
|
86
|
-
${`Danish`} | ${
|
|
87
|
-
${`German`} | ${
|
|
88
|
-
${`Spanish`} | ${
|
|
89
|
-
${`Italian`} | ${
|
|
90
|
-
${`French`} | ${
|
|
80
|
+
${`English`} | ${Languages.en} | ${`We recommend eating an additional:`}
|
|
81
|
+
${`Danish`} | ${Languages.da} | ${`Vi anbefaler at spise yderligere:`}
|
|
82
|
+
${`German`} | ${Languages.de} | ${`Wir empfehlen Ihnen, zusätzlich Folgendes zu essen:`}
|
|
83
|
+
${`Spanish`} | ${Languages.es} | ${`Recomendamos comer adicionalmente:`}
|
|
84
|
+
${`Italian`} | ${Languages.it} | ${`Consigliamo di ingerire una quantità supplementare:`}
|
|
85
|
+
${`French`} | ${Languages.fr} | ${`Nous vous recommandons de manger en plus :`}
|
|
91
86
|
`(`Modal renders attention messages in $language`, ({ message, locale }) => {
|
|
92
|
-
|
|
87
|
+
i18n.activate(locale);
|
|
93
88
|
const acceptMock = jest.fn();
|
|
94
89
|
const declineMock = jest.fn();
|
|
95
90
|
const onClickOkMock = jest.fn();
|
|
96
|
-
const wrapper =
|
|
97
|
-
<
|
|
91
|
+
const wrapper = render(<I18nProvider language={locale} i18n={i18n}>
|
|
92
|
+
<RecommendationModal isVisible={true} attentionMessage={null} limitationMessage={null} suggestedCarbohydrates={2} onClickOkButton={onClickOkMock} onAcceptCarbohydrates={acceptMock} onDeclineCarbohydrates={declineMock}/>
|
|
98
93
|
,
|
|
99
|
-
</
|
|
100
|
-
|
|
94
|
+
</I18nProvider>);
|
|
95
|
+
expectTextExists(wrapper, message);
|
|
101
96
|
});
|
|
102
97
|
});
|
|
@@ -1,124 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const react_native_testing_library_1 = require("react-native-testing-library");
|
|
8
|
-
const InvisibleNumberInput_1 = __importDefault(require("../../components/InvisibleNumberInput"));
|
|
9
|
-
const RecommendedCarbs_1 = __importDefault(require("../../components/RecommendedCarbs"));
|
|
10
|
-
const enum_1 = require("../../types/enum");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { cleanup, fireEvent, render } from "react-native-testing-library";
|
|
3
|
+
import InvisibleNumberInput from "../../components/InvisibleNumberInput";
|
|
4
|
+
import RecommendedCarbs from "../../components/RecommendedCarbs";
|
|
5
|
+
import { RecommendedCarbsTestIds } from "../../types/enum";
|
|
6
|
+
import { expectTextExists, expectTextNotExists } from "../utils";
|
|
12
7
|
describe(`Calculation Component`, () => {
|
|
13
|
-
afterEach(
|
|
8
|
+
afterEach(cleanup);
|
|
14
9
|
test(`calculate total carbs`, () => {
|
|
15
10
|
const removeMock = jest.fn();
|
|
16
11
|
const changeMock = jest.fn();
|
|
17
12
|
const newValue = 40;
|
|
18
|
-
const wrapper =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const invisInput = wrapper.getByTestId(
|
|
25
|
-
|
|
13
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`10`} recommendedCarbs={`25`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
14
|
+
expectTextExists(wrapper, `Food`);
|
|
15
|
+
expectTextExists(wrapper, `Additional`);
|
|
16
|
+
expectTextExists(wrapper, `10`);
|
|
17
|
+
expectTextExists(wrapper, `25`);
|
|
18
|
+
expectTextExists(wrapper, `35`);
|
|
19
|
+
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
20
|
+
fireEvent(invisInput, `onEnd`, newValue);
|
|
26
21
|
expect(changeMock).toBeCalledWith(newValue);
|
|
27
|
-
wrapper.rerender(<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
wrapper.rerender(<RecommendedCarbs enteredCarbs={`10`} recommendedCarbs={`${newValue}`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
23
|
+
expectTextExists(wrapper, `10`);
|
|
24
|
+
expectTextExists(wrapper, `${newValue}`);
|
|
25
|
+
expectTextExists(wrapper, `50`);
|
|
26
|
+
expectTextNotExists(wrapper, `35`);
|
|
32
27
|
});
|
|
33
28
|
test(`25 recommended carbs`, () => {
|
|
34
29
|
const removeMock = jest.fn();
|
|
35
30
|
const changeMock = jest.fn();
|
|
36
|
-
const wrapper =
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} recommendedCarbs={`25`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
32
|
+
expectTextExists(wrapper, `Food`);
|
|
33
|
+
expectTextExists(wrapper, `Additional`);
|
|
39
34
|
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
40
35
|
});
|
|
41
36
|
test(`25.5 recommended carbs get rounded to 26`, () => {
|
|
42
37
|
const removeMock = jest.fn();
|
|
43
38
|
const changeMock = jest.fn();
|
|
44
|
-
const wrapper =
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} recommendedCarbs={`25.5`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
40
|
+
expectTextExists(wrapper, `Food`);
|
|
41
|
+
expectTextExists(wrapper, `Additional`);
|
|
47
42
|
expect(wrapper.getAllByText(`26`).length).toBe(2);
|
|
48
43
|
});
|
|
49
44
|
test(`Negative recommended carbs does not render 'recommended additional g carbs'`, () => {
|
|
50
45
|
const removeMock = jest.fn();
|
|
51
46
|
const changeMock = jest.fn();
|
|
52
|
-
const wrapper =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} recommendedCarbs={`-25`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
48
|
+
expectTextExists(wrapper, `Food`);
|
|
49
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
50
|
+
expectTextNotExists(wrapper, `-25`);
|
|
56
51
|
});
|
|
57
52
|
test(`No recommended carbs does not render 'recommended additional g carbs'`, () => {
|
|
58
53
|
const removeMock = jest.fn();
|
|
59
54
|
const changeMock = jest.fn();
|
|
60
|
-
const wrapper =
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
56
|
+
expectTextExists(wrapper, `Food`);
|
|
57
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
63
58
|
});
|
|
64
59
|
test(`Editing recommended carbs`, () => {
|
|
65
60
|
const removeMock = jest.fn();
|
|
66
61
|
const changeMock = jest.fn();
|
|
67
|
-
const wrapper =
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock} recommendedCarbs={`12`}/>);
|
|
63
|
+
expectTextExists(wrapper, `Food`);
|
|
64
|
+
expectTextExists(wrapper, `Additional`);
|
|
70
65
|
expect(wrapper.getAllByText(`12`).length).toBe(2);
|
|
71
|
-
const carbButton = wrapper.getByTestId(
|
|
72
|
-
|
|
66
|
+
const carbButton = wrapper.getByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
67
|
+
fireEvent(carbButton, `onPress`);
|
|
73
68
|
expect(wrapper.getAllByText(`12`).length).toBe(2);
|
|
74
69
|
});
|
|
75
70
|
test(`Finished editing recommended carbs with carbs >= 0`, () => {
|
|
76
71
|
const removeMock = jest.fn();
|
|
77
72
|
const changeMock = jest.fn();
|
|
78
|
-
const wrapper =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const carbButton = wrapper.getByTestId(
|
|
82
|
-
|
|
83
|
-
const invisInput = wrapper.getByTestId(
|
|
84
|
-
|
|
73
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock} recommendedCarbs={`12`}/>);
|
|
74
|
+
expectTextExists(wrapper, `Food`);
|
|
75
|
+
expectTextExists(wrapper, `Additional`);
|
|
76
|
+
const carbButton = wrapper.getByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
77
|
+
fireEvent(carbButton, `onPress`);
|
|
78
|
+
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
79
|
+
fireEvent(invisInput, `onEndEditing`);
|
|
85
80
|
expect(changeMock).toBeCalledWith(Number(`12`));
|
|
86
81
|
});
|
|
87
82
|
test(`Negative recommendedCarbs removes recommendedCarbs render`, () => {
|
|
88
83
|
const removeMock = jest.fn();
|
|
89
84
|
const changeMock = jest.fn();
|
|
90
|
-
const wrapper =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const carbButton = wrapper.queryByTestId(
|
|
85
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock} recommendedCarbs={`-12`}/>);
|
|
86
|
+
expectTextExists(wrapper, `Food`);
|
|
87
|
+
expectTextNotExists(wrapper, `Additional`);
|
|
88
|
+
const carbButton = wrapper.queryByTestId(RecommendedCarbsTestIds.EditRecommendedCarbs);
|
|
94
89
|
expect(carbButton).toBeNull();
|
|
95
90
|
});
|
|
96
91
|
test(`Negative carbs doesn't invoke changedRecommendedCarbs callback`, () => {
|
|
97
92
|
const removeMock = jest.fn();
|
|
98
93
|
const changeMock = jest.fn();
|
|
99
|
-
const wrapper =
|
|
100
|
-
const numberInput = wrapper.UNSAFE_getByType(
|
|
101
|
-
|
|
94
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock} recommendedCarbs={`1`}/>);
|
|
95
|
+
const numberInput = wrapper.UNSAFE_getByType(InvisibleNumberInput);
|
|
96
|
+
fireEvent(numberInput, `onEnd`, -12);
|
|
102
97
|
expect(removeMock).not.toBeCalled();
|
|
103
98
|
expect(changeMock).not.toBeCalled();
|
|
104
99
|
});
|
|
105
100
|
test(`Carb error limit is > 300`, () => {
|
|
106
101
|
const removeMock = jest.fn();
|
|
107
102
|
const changeMock = jest.fn();
|
|
108
|
-
const wrapper =
|
|
103
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} recommendedCarbs={`25`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock}/>);
|
|
109
104
|
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
110
|
-
const invisInput = wrapper.getByTestId(
|
|
111
|
-
|
|
105
|
+
const invisInput = wrapper.getByTestId(RecommendedCarbsTestIds.InvisibleCarbInput);
|
|
106
|
+
fireEvent(invisInput, `onEnd`, 302);
|
|
112
107
|
expect(wrapper.getAllByText(`25`).length).toBe(2);
|
|
113
|
-
|
|
108
|
+
expectTextNotExists(wrapper, `302`);
|
|
114
109
|
});
|
|
115
110
|
test(`Pressing on the remove button invokes the removeRecommendedCarbs callback`, () => {
|
|
116
111
|
const removeMock = jest.fn();
|
|
117
112
|
const changeMock = jest.fn();
|
|
118
|
-
const wrapper =
|
|
113
|
+
const wrapper = render(<RecommendedCarbs enteredCarbs={`0`} changedRecommendedCarbs={changeMock} removeRecommendedCarbs={removeMock} recommendedCarbs={`1`}/>);
|
|
119
114
|
expect(removeMock).not.toBeCalled();
|
|
120
115
|
const removeButton = wrapper.getByA11yLabel(`removeRecommendedCarbs`);
|
|
121
|
-
|
|
116
|
+
fireEvent(removeButton, `onPress`);
|
|
122
117
|
expect(removeMock).toBeCalled();
|
|
123
118
|
});
|
|
124
119
|
});
|