@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.
Files changed (87) hide show
  1. package/coverage/clover.xml +2 -2
  2. package/coverage/lcov-report/index.html +1 -1
  3. package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1 -1
  4. package/coverage/lcov-report/src/__tests__/index.html +1 -1
  5. package/coverage/lcov-report/src/__tests__/utils.tsx.html +1 -1
  6. package/coverage/lcov-report/src/components/Header.tsx.html +1 -1
  7. package/coverage/lcov-report/src/components/InfoBars.tsx.html +1 -1
  8. package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +1 -1
  9. package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +1 -1
  10. package/coverage/lcov-report/src/components/LineSeparator.tsx.html +1 -1
  11. package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +1 -1
  12. package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +1 -1
  13. package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +1 -1
  14. package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +1 -1
  15. package/coverage/lcov-report/src/components/Remeasure.tsx.html +1 -1
  16. package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +1 -1
  17. package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +1 -1
  18. package/coverage/lcov-report/src/components/activity/Activity.tsx.html +1 -1
  19. package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +1 -1
  20. package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +1 -1
  21. package/coverage/lcov-report/src/components/activity/index.html +1 -1
  22. package/coverage/lcov-report/src/components/index.html +1 -1
  23. package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +1 -1
  24. package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +1 -1
  25. package/coverage/lcov-report/src/components/mood/index.html +1 -1
  26. package/coverage/lcov-report/src/index.html +1 -1
  27. package/coverage/lcov-report/src/locale/i18nUtils.ts.html +1 -1
  28. package/coverage/lcov-report/src/locale/index.html +1 -1
  29. package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +1 -1
  30. package/coverage/lcov-report/src/utils/Constants.ts.html +1 -1
  31. package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +1 -1
  32. package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +1 -1
  33. package/coverage/lcov-report/src/utils/Translations.ts.html +1 -1
  34. package/coverage/lcov-report/src/utils/Utils.ts.html +1 -1
  35. package/coverage/lcov-report/src/utils/Validations.ts.html +1 -1
  36. package/coverage/lcov-report/src/utils/index.html +1 -1
  37. package/index.js +5 -31
  38. package/package.json +2 -1
  39. package/src/RecommendationScreen.js +76 -101
  40. package/src/__tests__/RecommendationScreen.test.js +404 -409
  41. package/src/__tests__/RecommendationUtils.test.js +117 -119
  42. package/src/__tests__/Translate.test.js +14 -16
  43. package/src/__tests__/Utils.test.js +16 -18
  44. package/src/__tests__/Validations.test.js +30 -51
  45. package/src/__tests__/components/Activity.test.js +51 -56
  46. package/src/__tests__/components/Emotion.test.js +28 -33
  47. package/src/__tests__/components/Header.test.js +24 -29
  48. package/src/__tests__/components/InfoBars.test.js +59 -64
  49. package/src/__tests__/components/InvisibleNumberInput.test.js +22 -27
  50. package/src/__tests__/components/LimitationMessage.test.js +28 -33
  51. package/src/__tests__/components/MoodIcon.test.js +9 -14
  52. package/src/__tests__/components/RecommendationModal.test.js +56 -61
  53. package/src/__tests__/components/RecommendedCarbs.test.js +58 -63
  54. package/src/__tests__/components/RecommendedInsulin.test.js +60 -65
  55. package/src/__tests__/components/Remeasure.test.js +32 -37
  56. package/src/__tests__/components/TransferToLogbook.test.js +15 -20
  57. package/src/__tests__/components/TwoOptionModal.test.js +22 -27
  58. package/src/__tests__/utils.js +22 -38
  59. package/src/components/Header.js +34 -41
  60. package/src/components/Icon.js +2 -8
  61. package/src/components/InfoBars.js +36 -43
  62. package/src/components/InvisibleNumberInput.js +5 -11
  63. package/src/components/LimitationMessage.js +18 -40
  64. package/src/components/LineSeparator.js +7 -13
  65. package/src/components/RecentInsulin.js +33 -39
  66. package/src/components/RecommendationModal.js +59 -85
  67. package/src/components/RecommendedCarbs.js +93 -99
  68. package/src/components/RecommendedInsulin.js +46 -52
  69. package/src/components/Remeasure.js +36 -42
  70. package/src/components/TransferToLogbook.js +20 -26
  71. package/src/components/TwoOptionModal.js +39 -65
  72. package/src/components/activity/Activity.js +42 -48
  73. package/src/components/activity/ActivityIcon.js +15 -21
  74. package/src/components/activity/ActivityIntensity.js +19 -25
  75. package/src/components/mood/Emotion.js +17 -23
  76. package/src/components/mood/MoodIcon.js +11 -17
  77. package/src/locale/i18nUtils.js +17 -24
  78. package/src/types/enum.js +28 -31
  79. package/src/types/types.js +1 -2
  80. package/src/utils/AttentionMessages.js +24 -32
  81. package/src/utils/Constants.js +23 -26
  82. package/src/utils/RecommendationError.js +28 -54
  83. package/src/utils/RecommendationUtils.js +60 -72
  84. package/src/utils/Translations.js +6 -9
  85. package/src/utils/Utils.js +8 -12
  86. package/src/utils/Validations.js +77 -107
  87. package/tsconfig.json +3 -3
@@ -1,23 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const types_1 = require("@hedia/types");
7
- const react_1 = require("@lingui/react");
8
- const react_2 = __importDefault(require("react"));
9
- const react_native_testing_library_1 = require("react-native-testing-library");
10
- const Activity_1 = __importDefault(require("../../components/activity/Activity"));
11
- const i18nUtils_1 = require("../../locale/i18nUtils");
12
- const enum_1 = require("../../types/enum");
13
- const Translations_1 = require("../../utils/Translations");
14
- const utils_1 = require("../utils");
15
- const ActivityIntensity = types_1.Activity.Enums.ActivityIntensity;
1
+ import { Activity, Languages } from "@hedia/types";
2
+ import { I18nProvider } from "@lingui/react";
3
+ import React from "react";
4
+ import { cleanup, render } from "react-native-testing-library";
5
+ import { default as ActivityComponent } from "../../components/activity/Activity";
6
+ import { i18n } from "../../locale/i18nUtils";
7
+ import { ActivityTestIds } from "../../types/enum";
8
+ import { ActivityIntensityTranslations } from "../../utils/Translations";
9
+ import { expectTextExists, generateActivityProps, getRecommendationProps, i18nProvided, queryTextFromComponent, } from "../utils";
10
+ const ActivityIntensity = Activity.Enums.ActivityIntensity;
16
11
  const { light, moderate, hard } = ActivityIntensity;
17
12
  describe(`Activity - Component`, () => {
18
- afterEach(react_native_testing_library_1.cleanup);
13
+ afterEach(cleanup);
19
14
  beforeEach(() => {
20
- i18nUtils_1.i18n.activate(types_1.Languages.en);
15
+ i18n.activate(Languages.en);
21
16
  });
22
17
  test.each `
23
18
  activityIntensity
@@ -25,14 +20,14 @@ describe(`Activity - Component`, () => {
25
20
  ${moderate}
26
21
  ${hard}
27
22
  `(`Renders $activityIntensity`, ({ activityIntensity }) => {
28
- const { activityDisplayProps } = utils_1.getRecommendationProps();
29
- const activity = utils_1.generateActivityProps();
30
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Activity_1.default activity={{ ...activity, activityIntensity }} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
31
- utils_1.expectTextExists(wrapper, `Activity`);
32
- utils_1.expectTextExists(wrapper, `30`);
33
- utils_1.expectTextExists(wrapper, `min`);
34
- utils_1.expectTextExists(wrapper, `Based on the selected activity your insulin recommendation is reduced by:`);
35
- utils_1.expectTextExists(wrapper, Translations_1.ActivityIntensityTranslations[activityIntensity]());
23
+ const { activityDisplayProps } = getRecommendationProps();
24
+ const activity = generateActivityProps();
25
+ const wrapper = render(i18nProvided(<ActivityComponent activity={{ ...activity, activityIntensity }} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
26
+ expectTextExists(wrapper, `Activity`);
27
+ expectTextExists(wrapper, `30`);
28
+ expectTextExists(wrapper, `min`);
29
+ expectTextExists(wrapper, `Based on the selected activity your insulin recommendation is reduced by:`);
30
+ expectTextExists(wrapper, ActivityIntensityTranslations[activityIntensity]());
36
31
  });
37
32
  test.each `
38
33
  reduction
@@ -42,49 +37,49 @@ describe(`Activity - Component`, () => {
42
37
  ${0.5}
43
38
  ${0.8}
44
39
  `(`Renders activity reduction from decimal: $reduction to percentage`, ({ reduction }) => {
45
- const { activityDisplayProps } = utils_1.getRecommendationProps();
46
- const activity = utils_1.generateActivityProps();
47
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Activity_1.default activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityReduction={reduction} activityTitle={activityDisplayProps?.activityTitle ?? null}/>));
48
- utils_1.expectTextExists(wrapper, `${reduction * 100}%`);
40
+ const { activityDisplayProps } = getRecommendationProps();
41
+ const activity = generateActivityProps();
42
+ const wrapper = render(i18nProvided(<ActivityComponent activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityReduction={reduction} activityTitle={activityDisplayProps?.activityTitle ?? null}/>));
43
+ expectTextExists(wrapper, `${reduction * 100}%`);
49
44
  });
50
45
  test(`Renders activity reduction as 0 when null is passed`, () => {
51
- const { activityDisplayProps } = utils_1.getRecommendationProps();
52
- const activity = utils_1.generateActivityProps();
46
+ const { activityDisplayProps } = getRecommendationProps();
47
+ const activity = generateActivityProps();
53
48
  const reduction = null;
54
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Activity_1.default activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityReduction={reduction} activityTitle={activityDisplayProps?.activityTitle ?? null}/>));
55
- const text = utils_1.queryTextFromComponent(wrapper, enum_1.ActivityTestIds.ActivityReduction);
49
+ const wrapper = render(i18nProvided(<ActivityComponent activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityReduction={reduction} activityTitle={activityDisplayProps?.activityTitle ?? null}/>));
50
+ const text = queryTextFromComponent(wrapper, ActivityTestIds.ActivityReduction);
56
51
  expect(text).toBe(`0%`);
57
52
  });
58
53
  test(`Can render activity title`, () => {
59
- const { activityDisplayProps } = utils_1.getRecommendationProps();
60
- const activity = utils_1.generateActivityProps();
61
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Activity_1.default activity={{ ...activity }} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
62
- utils_1.expectTextExists(wrapper, activityDisplayProps?.activityTitle);
54
+ const { activityDisplayProps } = getRecommendationProps();
55
+ const activity = generateActivityProps();
56
+ const wrapper = render(i18nProvided(<ActivityComponent activity={{ ...activity }} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
57
+ expectTextExists(wrapper, activityDisplayProps?.activityTitle);
63
58
  });
64
59
  test.each `
65
60
  language | locale | message
66
- ${`English`} | ${types_1.Languages.en} | ${`Activity`}
67
- ${`Danish`} | ${types_1.Languages.da} | ${`Aktivitet`}
68
- ${`German`} | ${types_1.Languages.de} | ${`Aktivität`}
69
- ${`Spanish`} | ${types_1.Languages.es} | ${`Actividad`}
70
- ${`Italian`} | ${types_1.Languages.it} | ${`Attività fisica`}
71
- ${`French`} | ${types_1.Languages.fr} | ${`Activité`}
61
+ ${`English`} | ${Languages.en} | ${`Activity`}
62
+ ${`Danish`} | ${Languages.da} | ${`Aktivitet`}
63
+ ${`German`} | ${Languages.de} | ${`Aktivität`}
64
+ ${`Spanish`} | ${Languages.es} | ${`Actividad`}
65
+ ${`Italian`} | ${Languages.it} | ${`Attività fisica`}
66
+ ${`French`} | ${Languages.fr} | ${`Activité`}
72
67
  `(`Can render in $language`, ({ message, locale }) => {
73
- const { activityDisplayProps } = utils_1.getRecommendationProps();
74
- const activity = utils_1.generateActivityProps();
75
- i18nUtils_1.i18n.activate(locale);
76
- const wrapper = react_native_testing_library_1.render(<react_1.I18nProvider language={locale} i18n={i18nUtils_1.i18n}>
77
- <Activity_1.default activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>
78
- </react_1.I18nProvider>);
79
- utils_1.expectTextExists(wrapper, message);
68
+ const { activityDisplayProps } = getRecommendationProps();
69
+ const activity = generateActivityProps();
70
+ i18n.activate(locale);
71
+ const wrapper = render(<I18nProvider language={locale} i18n={i18n}>
72
+ <ActivityComponent activity={activity} activityType={activityDisplayProps?.activityType ?? null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>
73
+ </I18nProvider>);
74
+ expectTextExists(wrapper, message);
80
75
  });
81
76
  test(`ActivityIcon defaults to other if activityType is null`, () => {
82
- const { activityDisplayProps } = utils_1.getRecommendationProps();
83
- const activity = utils_1.generateActivityProps();
84
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Activity_1.default activity={{ ...activity }} activityType={null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
85
- utils_1.expectTextExists(wrapper, activityDisplayProps?.activityTitle);
86
- const existingLabel = `${types_1.Activity.Enums.ActivityEnum[types_1.Activity.Enums.ActivityEnum.Other]}_activity`;
87
- const nonExistingLabel = `${types_1.Activity.Enums.ActivityEnum[types_1.Activity.Enums.ActivityEnum.Run]}_activity`;
77
+ const { activityDisplayProps } = getRecommendationProps();
78
+ const activity = generateActivityProps();
79
+ const wrapper = render(i18nProvided(<ActivityComponent activity={{ ...activity }} activityType={null} activityTitle={activityDisplayProps?.activityTitle ?? null} activityReduction={0}/>));
80
+ expectTextExists(wrapper, activityDisplayProps?.activityTitle);
81
+ const existingLabel = `${Activity.Enums.ActivityEnum[Activity.Enums.ActivityEnum.Other]}_activity`;
82
+ const nonExistingLabel = `${Activity.Enums.ActivityEnum[Activity.Enums.ActivityEnum.Run]}_activity`;
88
83
  expect(wrapper.queryByA11yLabel(existingLabel)).not.toBeNull();
89
84
  expect(wrapper.queryByA11yLabel(nonExistingLabel)).toBeNull();
90
85
  });
@@ -1,24 +1,19 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
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 Emotion_1 = __importDefault(require("../../components/mood/Emotion"));
10
- const i18nUtils_1 = require("../../locale/i18nUtils");
11
- const utils_1 = require("../utils");
12
- const MoodEnum = types_1.Logbook.Enums.MoodEnum;
1
+ import { Languages, Logbook } from "@hedia/types";
2
+ import React from "react";
3
+ import { cleanup, fireEvent, render } from "react-native-testing-library";
4
+ import Emotion from "../../components/mood/Emotion";
5
+ import { i18n } from "../../locale/i18nUtils";
6
+ import { expectTextExists, getIcon, i18nProvided } from "../utils";
7
+ const MoodEnum = Logbook.Enums.MoodEnum;
13
8
  describe(`Emotion - Component`, () => {
14
- afterEach(react_native_testing_library_1.cleanup);
9
+ afterEach(cleanup);
15
10
  beforeEach(() => {
16
- i18nUtils_1.i18n.activate(types_1.Languages.en);
11
+ i18n.activate(Languages.en);
17
12
  });
18
13
  test(`Can mount component in `, () => {
19
14
  const mockSelected = jest.fn();
20
- const wrapper = react_native_testing_library_1.render(utils_1.i18nProvided(<Emotion_1.default moodSelected={mockSelected} currentMood={null}/>));
21
- utils_1.expectTextExists(wrapper, `How are you feeling?`);
15
+ const wrapper = render(i18nProvided(<Emotion moodSelected={mockSelected} currentMood={null}/>));
16
+ expectTextExists(wrapper, `How are you feeling?`);
22
17
  });
23
18
  test.each `
24
19
  mood | moodName | preselected | preselectedName
@@ -30,28 +25,28 @@ describe(`Emotion - Component`, () => {
30
25
  `(`Pressing on $moodName icon deselects others`, ({ mood, moodName, preselected, preselectedName, }) => {
31
26
  let mockedStateMood = preselected;
32
27
  const mockSelected = jest.fn((selectedMood) => (mockedStateMood = selectedMood));
33
- const wrapper = react_native_testing_library_1.render(<Emotion_1.default moodSelected={mockSelected} currentMood={mockedStateMood}/>);
34
- const preIcon = utils_1.getIcon(wrapper, preselectedName, true);
28
+ const wrapper = render(<Emotion moodSelected={mockSelected} currentMood={mockedStateMood}/>);
29
+ const preIcon = getIcon(wrapper, preselectedName, true);
35
30
  if (preIcon === null) {
36
31
  return fail(`No icon found for queryByA11yLabel: ${preselectedName}_${true}`);
37
32
  }
38
- const newIcon = utils_1.getIcon(wrapper, moodName, false);
33
+ const newIcon = getIcon(wrapper, moodName, false);
39
34
  if (newIcon === null) {
40
35
  return fail(`No icon found for queryByA11yLabel: ${moodName}_${false}`);
41
36
  }
42
37
  // Select a different mood
43
- react_native_testing_library_1.fireEvent(newIcon, `onPress`);
38
+ fireEvent(newIcon, `onPress`);
44
39
  expect(mockedStateMood).toBe(mood);
45
- wrapper.update(<Emotion_1.default moodSelected={mockSelected} currentMood={mockedStateMood}/>);
40
+ wrapper.update(<Emotion moodSelected={mockSelected} currentMood={mockedStateMood}/>);
46
41
  const moodValues = Object.values(MoodEnum).filter((value) => typeof value === `string`);
47
42
  moodValues.forEach((value) => {
48
43
  if (moodName === value) {
49
- expect(utils_1.getIcon(wrapper, value, true)).not.toBeNull();
50
- expect(utils_1.getIcon(wrapper, value, false)).toBeNull();
44
+ expect(getIcon(wrapper, value, true)).not.toBeNull();
45
+ expect(getIcon(wrapper, value, false)).toBeNull();
51
46
  }
52
47
  else {
53
- expect(utils_1.getIcon(wrapper, value, false)).not.toBeNull();
54
- expect(utils_1.getIcon(wrapper, value, true)).toBeNull();
48
+ expect(getIcon(wrapper, value, false)).not.toBeNull();
49
+ expect(getIcon(wrapper, value, true)).toBeNull();
55
50
  }
56
51
  });
57
52
  });
@@ -59,17 +54,17 @@ describe(`Emotion - Component`, () => {
59
54
  let mockedStateMood = MoodEnum.Happy;
60
55
  const mockSelected = jest.fn((newMood) => (mockedStateMood = newMood));
61
56
  const mood = MoodEnum[mockedStateMood];
62
- const wrapper = react_native_testing_library_1.render(<Emotion_1.default moodSelected={mockSelected} currentMood={mockedStateMood}/>);
57
+ const wrapper = render(<Emotion moodSelected={mockSelected} currentMood={mockedStateMood}/>);
63
58
  // current mood has already been selected: Happy
64
- expect(utils_1.getIcon(wrapper, mood, true)).not.toBeNull();
65
- expect(utils_1.getIcon(wrapper, mood, false)).toBeNull();
66
- const icon = utils_1.getIcon(wrapper, mood, true);
59
+ expect(getIcon(wrapper, mood, true)).not.toBeNull();
60
+ expect(getIcon(wrapper, mood, false)).toBeNull();
61
+ const icon = getIcon(wrapper, mood, true);
67
62
  if (icon === null) {
68
63
  return fail(`No icon found for queryByA11yLabel: ${mood}_${true}`);
69
64
  }
70
- react_native_testing_library_1.fireEvent(icon, `onPress`);
71
- wrapper.update(<Emotion_1.default moodSelected={mockSelected} currentMood={mockedStateMood}/>);
72
- expect(utils_1.getIcon(wrapper, mood, true)).toBeNull();
73
- expect(utils_1.getIcon(wrapper, mood, false)).not.toBeNull();
65
+ fireEvent(icon, `onPress`);
66
+ wrapper.update(<Emotion moodSelected={mockSelected} currentMood={mockedStateMood}/>);
67
+ expect(getIcon(wrapper, mood, true)).toBeNull();
68
+ expect(getIcon(wrapper, mood, false)).not.toBeNull();
74
69
  });
75
70
  });
@@ -1,41 +1,36 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 utils_1 = require("../utils");
9
- const react_2 = require("@lingui/react");
10
- const Header_1 = __importDefault(require("../../components/Header"));
11
- const types_1 = require("@hedia/types");
12
- const i18nUtils_1 = require("../../locale/i18nUtils");
13
- const enum_1 = require("../../types/enum");
1
+ import React from "react";
2
+ import { cleanup, fireEvent, render } from "react-native-testing-library";
3
+ import { expectTextExists, getRecommendationProps } from "../utils";
4
+ import { I18nProvider } from "@lingui/react";
5
+ import Header from "../../components/Header";
6
+ import { Languages } from "@hedia/types";
7
+ import { i18n } from "../../locale/i18nUtils";
8
+ import { HeaderTestIds } from "../../types/enum";
14
9
  describe(`Header Component`, () => {
15
- afterEach(react_native_testing_library_1.cleanup);
10
+ afterEach(cleanup);
16
11
  test(`Exit button calls exitCallback`, () => {
17
- const props = utils_1.getRecommendationProps();
18
- const { getByTestId } = react_native_testing_library_1.render(<Header_1.default exitCallback={props.exitCallback}/>);
12
+ const props = getRecommendationProps();
13
+ const { getByTestId } = render(<Header exitCallback={props.exitCallback}/>);
19
14
  expect(props.exitCallback).not.toBeCalled();
20
- react_native_testing_library_1.fireEvent.press(getByTestId(enum_1.HeaderTestIds.ExitCalculation));
15
+ fireEvent.press(getByTestId(HeaderTestIds.ExitCalculation));
21
16
  expect(props.exitCallback).toBeCalled();
22
17
  });
23
18
  test.each `
24
19
  language | locale | header
25
- ${`English`} | ${types_1.Languages.en} | ${`INSULIN\nRECOMMENDATION`}
26
- ${`Danish`} | ${types_1.Languages.da} | ${`INSULIN\nANBEFALING`}
27
- ${`German`} | ${types_1.Languages.de} | ${`INSULIN\nEMPFEHLUNG`}
28
- ${`Spanish`} | ${types_1.Languages.es} | ${`RECOMENDACIÓN\nDE INSULINA`}
29
- ${`Italian`} | ${types_1.Languages.it} | ${`PRESCRIZIONE DI\nINSULINA`}
30
- ${`French`} | ${types_1.Languages.fr} | ${`RECOMMANDATION\nD’INSULINE`}
20
+ ${`English`} | ${Languages.en} | ${`INSULIN\nRECOMMENDATION`}
21
+ ${`Danish`} | ${Languages.da} | ${`INSULIN\nANBEFALING`}
22
+ ${`German`} | ${Languages.de} | ${`INSULIN\nEMPFEHLUNG`}
23
+ ${`Spanish`} | ${Languages.es} | ${`RECOMENDACIÓN\nDE INSULINA`}
24
+ ${`Italian`} | ${Languages.it} | ${`PRESCRIZIONE DI\nINSULINA`}
25
+ ${`French`} | ${Languages.fr} | ${`RECOMMANDATION\nD’INSULINE`}
31
26
  `(`Header is translated to $language`, ({ header, locale }) => {
32
- const props = utils_1.getRecommendationProps({
27
+ const props = getRecommendationProps({
33
28
  language: locale,
34
29
  });
35
- i18nUtils_1.i18n.activate(locale);
36
- const wrapper = react_native_testing_library_1.render(<react_2.I18nProvider language={locale} i18n={i18nUtils_1.i18n}>
37
- <Header_1.default exitCallback={props.exitCallback}/>
38
- </react_2.I18nProvider>);
39
- utils_1.expectTextExists(wrapper, header);
30
+ i18n.activate(locale);
31
+ const wrapper = render(<I18nProvider language={locale} i18n={i18n}>
32
+ <Header exitCallback={props.exitCallback}/>
33
+ </I18nProvider>);
34
+ expectTextExists(wrapper, header);
40
35
  });
41
36
  });
@@ -1,20 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
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 InfoBars_1 = __importDefault(require("../../components/InfoBars"));
10
- const utils_1 = require("../utils");
1
+ import { BloodGlucoseUnit, BloodKetonesUnit } from "@hedia/types";
2
+ import React from "react";
3
+ import { cleanup, render } from "react-native-testing-library";
4
+ import InfoBars from "../../components/InfoBars";
5
+ import { expectTextExists, expectTextNotExists } from "../utils";
11
6
  var DisplayedUnit;
12
7
  (function (DisplayedUnit) {
13
8
  DisplayedUnit["MG_DL"] = "mg/dL";
14
9
  DisplayedUnit["MMOL_L"] = "mmol/L";
15
10
  })(DisplayedUnit || (DisplayedUnit = {}));
16
11
  describe(`Info Bars Component`, () => {
17
- afterEach(react_native_testing_library_1.cleanup);
12
+ afterEach(cleanup);
18
13
  test(`Active Insulin info bar shows value`, () => {
19
14
  const props = {
20
15
  label: `Active Insulin`,
@@ -22,11 +17,11 @@ describe(`Info Bars Component`, () => {
22
17
  value: `4.5`,
23
18
  showNullAsDash: true,
24
19
  };
25
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
26
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MMOL_L}`);
27
- utils_1.expectTextExists(InfoBarsComponent, props.label);
28
- utils_1.expectTextExists(InfoBarsComponent, `${props.unit}`);
29
- utils_1.expectTextExists(InfoBarsComponent, props.value);
20
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
21
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MMOL_L}`);
22
+ expectTextExists(InfoBarsComponent, props.label);
23
+ expectTextExists(InfoBarsComponent, `${props.unit}`);
24
+ expectTextExists(InfoBarsComponent, props.value);
30
25
  });
31
26
  test(`Active Insulin info bar - showNullAsDash`, () => {
32
27
  const props = {
@@ -35,11 +30,11 @@ describe(`Info Bars Component`, () => {
35
30
  showNullAsDash: true,
36
31
  value: null,
37
32
  };
38
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
39
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MG_DL}`);
40
- utils_1.expectTextExists(InfoBarsComponent, props.label);
41
- utils_1.expectTextExists(InfoBarsComponent, `${props.unit}`);
42
- utils_1.expectTextExists(InfoBarsComponent, `-.-`);
33
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
34
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MG_DL}`);
35
+ expectTextExists(InfoBarsComponent, props.label);
36
+ expectTextExists(InfoBarsComponent, `${props.unit}`);
37
+ expectTextExists(InfoBarsComponent, `-.-`);
43
38
  });
44
39
  test(`Active Insulin info bar - don't showNullAsDash`, () => {
45
40
  const props = {
@@ -48,80 +43,80 @@ describe(`Info Bars Component`, () => {
48
43
  value: `3.5`,
49
44
  showNullAsDash: false,
50
45
  };
51
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
52
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MG_DL}`);
53
- utils_1.expectTextExists(InfoBarsComponent, props.label);
54
- utils_1.expectTextExists(InfoBarsComponent, `${props.unit}`);
55
- utils_1.expectTextExists(InfoBarsComponent, props.value);
46
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
47
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MG_DL}`);
48
+ expectTextExists(InfoBarsComponent, props.label);
49
+ expectTextExists(InfoBarsComponent, `${props.unit}`);
50
+ expectTextExists(InfoBarsComponent, props.value);
56
51
  });
57
52
  test(`Blood Glucose mmol/l can be displayed`, () => {
58
53
  const props = {
59
54
  label: `Blood Glucose Levels`,
60
- unit: types_1.BloodGlucoseUnit.MMOL_L,
55
+ unit: BloodGlucoseUnit.MMOL_L,
61
56
  value: `4.5`,
62
57
  showNullAsDash: true,
63
58
  };
64
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
65
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MG_DL}`);
66
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MMOL_L}`);
67
- utils_1.expectTextExists(InfoBarsComponent, props.label);
68
- utils_1.expectTextExists(InfoBarsComponent, DisplayedUnit.MMOL_L);
69
- utils_1.expectTextExists(InfoBarsComponent, props.value);
59
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
60
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MG_DL}`);
61
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MMOL_L}`);
62
+ expectTextExists(InfoBarsComponent, props.label);
63
+ expectTextExists(InfoBarsComponent, DisplayedUnit.MMOL_L);
64
+ expectTextExists(InfoBarsComponent, props.value);
70
65
  });
71
66
  test(`Blood Glucose mg/dl can be displayed`, () => {
72
67
  const props = {
73
68
  label: `Blood Glucose Levels`,
74
- unit: types_1.BloodGlucoseUnit.MG_DL,
69
+ unit: BloodGlucoseUnit.MG_DL,
75
70
  value: `135`,
76
71
  showNullAsDash: true,
77
72
  };
78
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
79
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MMOL_L}`);
80
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodGlucoseUnit.MG_DL}`);
81
- utils_1.expectTextExists(InfoBarsComponent, props.label);
82
- utils_1.expectTextExists(InfoBarsComponent, DisplayedUnit.MG_DL);
83
- utils_1.expectTextExists(InfoBarsComponent, props.value);
73
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
74
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MMOL_L}`);
75
+ expectTextNotExists(InfoBarsComponent, `${BloodGlucoseUnit.MG_DL}`);
76
+ expectTextExists(InfoBarsComponent, props.label);
77
+ expectTextExists(InfoBarsComponent, DisplayedUnit.MG_DL);
78
+ expectTextExists(InfoBarsComponent, props.value);
84
79
  });
85
80
  test(`Blood Ketones mmol/l can be displayed`, () => {
86
81
  const props = {
87
82
  label: `Blood Ketone Level`,
88
- unit: types_1.BloodKetonesUnit.MMOL_L,
83
+ unit: BloodKetonesUnit.MMOL_L,
89
84
  value: `2.2`,
90
85
  showNullAsDash: true,
91
86
  };
92
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
93
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodKetonesUnit.MG_DL}`);
94
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodKetonesUnit.MMOL_L}`);
95
- utils_1.expectTextExists(InfoBarsComponent, props.label);
96
- utils_1.expectTextExists(InfoBarsComponent, DisplayedUnit.MMOL_L);
97
- utils_1.expectTextExists(InfoBarsComponent, props.value);
87
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
88
+ expectTextNotExists(InfoBarsComponent, `${BloodKetonesUnit.MG_DL}`);
89
+ expectTextNotExists(InfoBarsComponent, `${BloodKetonesUnit.MMOL_L}`);
90
+ expectTextExists(InfoBarsComponent, props.label);
91
+ expectTextExists(InfoBarsComponent, DisplayedUnit.MMOL_L);
92
+ expectTextExists(InfoBarsComponent, props.value);
98
93
  });
99
94
  test(`Blood Ketones mg/dl can be displayed`, () => {
100
95
  const props = {
101
96
  label: `Blood Ketone Level`,
102
- unit: types_1.BloodKetonesUnit.MG_DL,
97
+ unit: BloodKetonesUnit.MG_DL,
103
98
  value: `10`,
104
99
  showNullAsDash: true,
105
100
  };
106
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
107
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodKetonesUnit.MMOL_L}`);
108
- utils_1.expectTextNotExists(InfoBarsComponent, `${types_1.BloodKetonesUnit.MG_DL}`);
109
- utils_1.expectTextExists(InfoBarsComponent, props.label);
110
- utils_1.expectTextExists(InfoBarsComponent, DisplayedUnit.MG_DL);
111
- utils_1.expectTextExists(InfoBarsComponent, props.value);
101
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
102
+ expectTextNotExists(InfoBarsComponent, `${BloodKetonesUnit.MMOL_L}`);
103
+ expectTextNotExists(InfoBarsComponent, `${BloodKetonesUnit.MG_DL}`);
104
+ expectTextExists(InfoBarsComponent, props.label);
105
+ expectTextExists(InfoBarsComponent, DisplayedUnit.MG_DL);
106
+ expectTextExists(InfoBarsComponent, props.value);
112
107
  });
113
108
  test.each `
114
109
  value | showNullAsDash | unit | expected
115
110
  ${null} | ${false} | ${`units`} | ${`0`}
116
- ${null} | ${false} | ${types_1.BloodGlucoseUnit.MG_DL} | ${`0`}
117
- ${null} | ${false} | ${types_1.BloodGlucoseUnit.MG_DL} | ${`0`}
118
- ${null} | ${false} | ${types_1.BloodKetonesUnit.MG_DL} | ${`0`}
119
- ${null} | ${false} | ${types_1.BloodKetonesUnit.MMOL_L} | ${`0`}
111
+ ${null} | ${false} | ${BloodGlucoseUnit.MG_DL} | ${`0`}
112
+ ${null} | ${false} | ${BloodGlucoseUnit.MG_DL} | ${`0`}
113
+ ${null} | ${false} | ${BloodKetonesUnit.MG_DL} | ${`0`}
114
+ ${null} | ${false} | ${BloodKetonesUnit.MMOL_L} | ${`0`}
120
115
  ${null} | ${true} | ${`units`} | ${`-.-`}
121
- ${null} | ${true} | ${types_1.BloodGlucoseUnit.MG_DL} | ${`-`}
122
- ${null} | ${true} | ${types_1.BloodGlucoseUnit.MMOL_L} | ${`-.-`}
123
- ${null} | ${true} | ${types_1.BloodKetonesUnit.MG_DL} | ${`-`}
124
- ${null} | ${true} | ${types_1.BloodKetonesUnit.MMOL_L} | ${`-.-`}
116
+ ${null} | ${true} | ${BloodGlucoseUnit.MG_DL} | ${`-`}
117
+ ${null} | ${true} | ${BloodGlucoseUnit.MMOL_L} | ${`-.-`}
118
+ ${null} | ${true} | ${BloodKetonesUnit.MG_DL} | ${`-`}
119
+ ${null} | ${true} | ${BloodKetonesUnit.MMOL_L} | ${`-.-`}
125
120
  `(`$value will be displayed as $expected when showNullAsDash === $showNullAsDash`, ({ expected, showNullAsDash, unit, value }) => {
126
121
  const props = {
127
122
  label: `Blood Glucose Levels`,
@@ -129,7 +124,7 @@ describe(`Info Bars Component`, () => {
129
124
  value,
130
125
  showNullAsDash,
131
126
  };
132
- const InfoBarsComponent = react_native_testing_library_1.render(<InfoBars_1.default {...props}/>);
133
- utils_1.expectTextExists(InfoBarsComponent, expected);
127
+ const InfoBarsComponent = render(<InfoBars {...props}/>);
128
+ expectTextExists(InfoBarsComponent, expected);
134
129
  });
135
130
  });