@jobber/components-native 0.101.3 → 0.101.4

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 (182) hide show
  1. package/dist/package.json +19 -11
  2. package/dist/src/ActionItem/ActionItem.test.js +81 -0
  3. package/dist/src/ActionItem/ActionItemGroup.test.js +25 -0
  4. package/dist/src/ActionItem/components/ActionItemContainer.test.js +24 -0
  5. package/dist/src/ActionLabel/ActionLabel.test.js +81 -0
  6. package/dist/src/ActivityIndicator/ActivityIndicator.test.js +23 -0
  7. package/dist/src/AtlantisContext/AtlantisContext.test.js +35 -0
  8. package/dist/src/AtlantisThemeContext/AtlantisThemeContext.test.js +65 -0
  9. package/dist/src/AtlantisThemeContext/buildThemedStyles.test.js +43 -0
  10. package/dist/src/AutoLink/AutoLink.test.js +133 -0
  11. package/dist/src/AutoLink/components/Link/Link.test.js +18 -0
  12. package/dist/src/Banner/Banner.test.js +98 -0
  13. package/dist/src/BottomSheet/BottomSheet.test.js +105 -0
  14. package/dist/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.js +19 -0
  15. package/dist/src/BottomSheet/hooks/useBottomSheetBackHandler.test.js +68 -0
  16. package/dist/src/Button/Button.test.js +228 -0
  17. package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.js +25 -0
  18. package/dist/src/ButtonGroup/ButtonGroup.test.js +153 -0
  19. package/dist/src/Card/Card.test.js +80 -0
  20. package/dist/src/Card/components/InternalCardHeader.test.js +18 -0
  21. package/dist/src/Checkbox/Checkbox.test.js +135 -0
  22. package/dist/src/Checkbox/CheckboxGroup.test.js +197 -0
  23. package/dist/src/Checkbox/CheckboxGroupReducer.test.js +25 -0
  24. package/dist/src/Chip/Chip.test.js +69 -0
  25. package/dist/src/Content/Content.test.js +250 -0
  26. package/dist/src/ContentOverlay/ContentOverlay.test.js +297 -0
  27. package/dist/src/ContentOverlay/computeContentOverlayBehavior.test.js +197 -0
  28. package/dist/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.js +62 -0
  29. package/dist/src/ContentOverlay/hooks/useKeyboardVisibility.test.js +41 -0
  30. package/dist/src/ContentOverlay/hooks/useViewLayoutHeight.test.js +62 -0
  31. package/dist/src/Disclosure/Disclosure.test.js +64 -0
  32. package/dist/src/Divider/Divider.test.js +65 -0
  33. package/dist/src/EmptyState/EmptyState.test.js +82 -0
  34. package/dist/src/ErrorMessageWrapper/ErrorMessageWrapper.test.js +29 -0
  35. package/dist/src/Flex/Flex.test.js +104 -0
  36. package/dist/src/Form/Form.test.js +393 -0
  37. package/dist/src/Form/components/FormErrorBanner/FormErrorBanner.test.js +41 -0
  38. package/dist/src/Form/components/FormMessage/FormMessage.test.js +73 -0
  39. package/dist/src/Form/components/FormMessageBanner/FormMessageBanner.test.js +30 -0
  40. package/dist/src/Form/components/FormSaveButton/FormSaveButton.test.js +82 -0
  41. package/dist/src/Form/context/AtlantisFormContext.test.js +28 -0
  42. package/dist/src/Form/hooks/useScrollToError/useScrollToError.test.js +89 -0
  43. package/dist/src/FormField/FormField.test.js +81 -0
  44. package/dist/src/FormatFile/FormatFile.test.js +212 -0
  45. package/dist/src/FormatFile/FormatFileThumbnail.test.js +192 -0
  46. package/dist/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.js +74 -0
  47. package/dist/src/FormatFile/components/MediaView/MediaView.test.js +202 -0
  48. package/dist/src/FormatFile/utils/parseFile.test.js +188 -0
  49. package/dist/src/Glimmer/Glimmer.test.js +61 -0
  50. package/dist/src/Heading/Heading.test.js +61 -0
  51. package/dist/src/Icon/Icon.test.js +40 -0
  52. package/dist/src/IconButton/IconButton.test.js +38 -0
  53. package/dist/src/InputCurrency/InputCurrency.test.js +106 -0
  54. package/dist/src/InputDate/InputDate.test.js +184 -0
  55. package/dist/src/InputEmail/InputEmail.test.js +27 -0
  56. package/dist/src/InputFieldWrapper/InputFieldWrapper.test.js +279 -0
  57. package/dist/src/InputFieldWrapper/components/ClearAction/ClearAction.test.js +9 -0
  58. package/dist/src/InputFieldWrapper/components/Prefix/Prefix.test.js +130 -0
  59. package/dist/src/InputFieldWrapper/components/Suffix/Suffix.test.js +51 -0
  60. package/dist/src/InputNumber/InputNumber.test.js +220 -0
  61. package/dist/src/InputPassword/InputPassword.test.js +63 -0
  62. package/dist/src/InputPressable/InputPressable.test.js +138 -0
  63. package/dist/src/InputSearch/InputSearch.test.js +54 -0
  64. package/dist/src/InputText/InputText.test.js +652 -0
  65. package/dist/src/InputText/context/InputAccessoriesProvider.test.js +71 -0
  66. package/dist/src/InputTime/InputTime.test.js +199 -0
  67. package/dist/src/InputTime/utils/utils.test.js +32 -0
  68. package/dist/src/ProgressBar/ProgressBar.test.js +89 -0
  69. package/dist/src/Select/Select.test.js +183 -0
  70. package/dist/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.js +51 -0
  71. package/dist/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.js +72 -0
  72. package/dist/src/StatusLabel/StatusLabel.test.js +51 -0
  73. package/dist/src/Switch/Switch.test.js +60 -0
  74. package/dist/src/Switch/components/BaseSwitch/BaseSwitch.test.js +61 -0
  75. package/dist/src/Text/Text.test.js +161 -0
  76. package/dist/src/TextList/TextList.test.js +16 -0
  77. package/dist/src/ThumbnailList/ThumbnailList.test.js +72 -0
  78. package/dist/src/Toast/Toast.test.js +51 -0
  79. package/dist/src/Typography/Typography.test.js +225 -0
  80. package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.test.js +103 -0
  81. package/dist/src/utils/meta/meta.test.js +83 -0
  82. package/dist/tsconfig.build.json +5 -1
  83. package/dist/tsconfig.build.tsbuildinfo +1 -1
  84. package/dist/tsconfig.eslint.json +14 -0
  85. package/dist/tsconfig.json +3 -4
  86. package/dist/types/src/ActionItem/ActionItem.test.d.ts +1 -0
  87. package/dist/types/src/ActionItem/ActionItemGroup.test.d.ts +1 -0
  88. package/dist/types/src/ActionItem/components/ActionItemContainer.test.d.ts +1 -0
  89. package/dist/types/src/ActionLabel/ActionLabel.test.d.ts +1 -0
  90. package/dist/types/src/ActivityIndicator/ActivityIndicator.test.d.ts +1 -0
  91. package/dist/types/src/AtlantisContext/AtlantisContext.test.d.ts +1 -0
  92. package/dist/types/src/AtlantisThemeContext/AtlantisThemeContext.test.d.ts +1 -0
  93. package/dist/types/src/AtlantisThemeContext/buildThemedStyles.test.d.ts +1 -0
  94. package/dist/types/src/AutoLink/AutoLink.test.d.ts +1 -0
  95. package/dist/types/src/AutoLink/components/Link/Link.test.d.ts +1 -0
  96. package/dist/types/src/Banner/Banner.test.d.ts +1 -0
  97. package/dist/types/src/BottomSheet/BottomSheet.test.d.ts +1 -0
  98. package/dist/types/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.d.ts +1 -0
  99. package/dist/types/src/BottomSheet/hooks/useBottomSheetBackHandler.test.d.ts +1 -0
  100. package/dist/types/src/Button/Button.test.d.ts +1 -0
  101. package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.d.ts +1 -0
  102. package/dist/types/src/ButtonGroup/ButtonGroup.test.d.ts +1 -0
  103. package/dist/types/src/Card/Card.test.d.ts +1 -0
  104. package/dist/types/src/Card/components/InternalCardHeader.test.d.ts +1 -0
  105. package/dist/types/src/Checkbox/Checkbox.test.d.ts +1 -0
  106. package/dist/types/src/Checkbox/CheckboxGroup.test.d.ts +1 -0
  107. package/dist/types/src/Checkbox/CheckboxGroupReducer.test.d.ts +1 -0
  108. package/dist/types/src/Chip/Chip.test.d.ts +1 -0
  109. package/dist/types/src/Content/Content.test.d.ts +1 -0
  110. package/dist/types/src/ContentOverlay/BottomSheetKeyboardAwareScrollView.d.ts +2 -1
  111. package/dist/types/src/ContentOverlay/ContentOverlay.test.d.ts +1 -0
  112. package/dist/types/src/ContentOverlay/computeContentOverlayBehavior.test.d.ts +1 -0
  113. package/dist/types/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.d.ts +1 -0
  114. package/dist/types/src/ContentOverlay/hooks/useKeyboardVisibility.test.d.ts +1 -0
  115. package/dist/types/src/ContentOverlay/hooks/useViewLayoutHeight.test.d.ts +1 -0
  116. package/dist/types/src/Disclosure/Disclosure.test.d.ts +1 -0
  117. package/dist/types/src/Divider/Divider.test.d.ts +1 -0
  118. package/dist/types/src/EmptyState/EmptyState.test.d.ts +1 -0
  119. package/dist/types/src/ErrorMessageWrapper/ErrorMessageWrapper.test.d.ts +1 -0
  120. package/dist/types/src/Flex/Flex.test.d.ts +1 -0
  121. package/dist/types/src/Form/Form.test.d.ts +1 -0
  122. package/dist/types/src/Form/components/FormErrorBanner/FormErrorBanner.test.d.ts +1 -0
  123. package/dist/types/src/Form/components/FormMessage/FormMessage.test.d.ts +1 -0
  124. package/dist/types/src/Form/components/FormMessageBanner/FormMessageBanner.test.d.ts +1 -0
  125. package/dist/types/src/Form/components/FormSaveButton/FormSaveButton.test.d.ts +1 -0
  126. package/dist/types/src/Form/context/AtlantisFormContext.test.d.ts +1 -0
  127. package/dist/types/src/Form/hooks/useScrollToError/useScrollToError.test.d.ts +1 -0
  128. package/dist/types/src/FormField/FormField.test.d.ts +1 -0
  129. package/dist/types/src/FormatFile/FormatFile.test.d.ts +1 -0
  130. package/dist/types/src/FormatFile/FormatFileThumbnail.test.d.ts +1 -0
  131. package/dist/types/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.d.ts +1 -0
  132. package/dist/types/src/FormatFile/components/MediaView/MediaView.test.d.ts +1 -0
  133. package/dist/types/src/FormatFile/utils/parseFile.test.d.ts +1 -0
  134. package/dist/types/src/Glimmer/Glimmer.test.d.ts +1 -0
  135. package/dist/types/src/Heading/Heading.test.d.ts +1 -0
  136. package/dist/types/src/Icon/Icon.test.d.ts +1 -0
  137. package/dist/types/src/IconButton/IconButton.test.d.ts +1 -0
  138. package/dist/types/src/InputCurrency/InputCurrency.test.d.ts +1 -0
  139. package/dist/types/src/InputDate/InputDate.test.d.ts +1 -0
  140. package/dist/types/src/InputEmail/InputEmail.test.d.ts +1 -0
  141. package/dist/types/src/InputFieldWrapper/InputFieldWrapper.test.d.ts +1 -0
  142. package/dist/types/src/InputFieldWrapper/components/ClearAction/ClearAction.test.d.ts +1 -0
  143. package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.test.d.ts +1 -0
  144. package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.test.d.ts +1 -0
  145. package/dist/types/src/InputNumber/InputNumber.test.d.ts +1 -0
  146. package/dist/types/src/InputPassword/InputPassword.test.d.ts +1 -0
  147. package/dist/types/src/InputPressable/InputPressable.test.d.ts +1 -0
  148. package/dist/types/src/InputSearch/InputSearch.test.d.ts +1 -0
  149. package/dist/types/src/InputText/InputText.test.d.ts +1 -0
  150. package/dist/types/src/InputText/context/InputAccessoriesProvider.test.d.ts +1 -0
  151. package/dist/types/src/InputTime/InputTime.test.d.ts +1 -0
  152. package/dist/types/src/InputTime/utils/utils.test.d.ts +1 -0
  153. package/dist/types/src/ProgressBar/ProgressBar.test.d.ts +1 -0
  154. package/dist/types/src/Select/Select.test.d.ts +1 -0
  155. package/dist/types/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.d.ts +1 -0
  156. package/dist/types/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.d.ts +1 -0
  157. package/dist/types/src/StatusLabel/StatusLabel.test.d.ts +1 -0
  158. package/dist/types/src/Switch/Switch.test.d.ts +1 -0
  159. package/dist/types/src/Switch/components/BaseSwitch/BaseSwitch.test.d.ts +1 -0
  160. package/dist/types/src/Text/Text.test.d.ts +1 -0
  161. package/dist/types/src/TextList/TextList.test.d.ts +1 -0
  162. package/dist/types/src/ThumbnailList/ThumbnailList.test.d.ts +1 -0
  163. package/dist/types/src/Toast/Toast.test.d.ts +1 -0
  164. package/dist/types/src/Typography/Typography.test.d.ts +1 -0
  165. package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.test.d.ts +1 -0
  166. package/dist/types/src/utils/meta/meta.test.d.ts +1 -0
  167. package/package.json +19 -11
  168. package/src/Button/Button.test.tsx +6 -2
  169. package/src/ContentOverlay/hooks/useViewLayoutHeight.test.ts +3 -3
  170. package/src/Divider/Divider.stories.tsx +1 -1
  171. package/src/Flex/Flex.test.tsx +1 -1
  172. package/src/Form/Form.test.tsx +3 -1
  173. package/src/FormField/FormField.test.tsx +5 -1
  174. package/src/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
  175. package/src/InputDate/InputDate.test.tsx +7 -1
  176. package/src/InputText/InputText.test.tsx +2 -1
  177. package/src/InputTime/InputTime.test.tsx +7 -1
  178. package/src/Select/Select.test.tsx +1 -1
  179. package/src/StatusLabel/__snapshots__/StatusLabel.test.tsx.snap +8 -8
  180. package/src/Text/__snapshots__/Text.test.tsx.snap +2 -2
  181. package/src/ThumbnailList/__snapshots__/ThumbnailList.test.tsx.snap +1 -1
  182. package/src/Typography/__snapshots__/Typography.test.tsx.snap +4 -4
@@ -0,0 +1,220 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React from "react";
11
+ import { fireEvent, render, waitFor } from "@testing-library/react-native";
12
+ import { InputNumber } from ".";
13
+ let Platform;
14
+ beforeEach(() => {
15
+ Platform = require("react-native").Platform;
16
+ });
17
+ const platforms = ["ios", "android"];
18
+ it.each(platforms)("renders an InputNumber on %s", platform => {
19
+ Platform.OS = platform;
20
+ const label = "My Accessible label";
21
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: label }));
22
+ expect(getByLabelText(label)).toBeTruthy();
23
+ });
24
+ it.each(platforms)("renders an InputNumber with defaultValue on %s", platform => {
25
+ Platform.OS = platform;
26
+ const value = 200;
27
+ const { getByDisplayValue } = render(React.createElement(InputNumber, { value: value }));
28
+ expect(getByDisplayValue(value.toString())).toBeTruthy();
29
+ });
30
+ const notANumberErrorMessage = "Enter a number";
31
+ it("Displays a validation message when the value is not a number", () => __awaiter(void 0, void 0, void 0, function* () {
32
+ const a11yLabel = "InputNumberTest";
33
+ const onChange = jest.fn();
34
+ const { getByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
35
+ const inputValue = "this";
36
+ fireEvent.changeText(getByLabelText(a11yLabel), inputValue);
37
+ yield waitFor(() => {
38
+ fireEvent(getByLabelText(a11yLabel), "blur");
39
+ });
40
+ expect(getByText(notANumberErrorMessage, {
41
+ includeHiddenElements: true,
42
+ })).toBeDefined();
43
+ expect(onChange).toHaveBeenCalledWith(inputValue);
44
+ }));
45
+ it("When onChange is called it returns a number", () => __awaiter(void 0, void 0, void 0, function* () {
46
+ const a11yLabel = "InputNumberTest";
47
+ const onChange = jest.fn();
48
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
49
+ fireEvent.changeText(getByLabelText(a11yLabel), "100");
50
+ expect(onChange).toHaveBeenCalledWith(100);
51
+ }));
52
+ it("doesn't change the value when the input is controlled without an onChange", () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const a11yLabel = "InputNumberTest";
54
+ const initialValue = 12;
55
+ const changeValue = 100;
56
+ const { queryByText, getByLabelText, getByDisplayValue } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, value: initialValue }));
57
+ fireEvent.changeText(getByLabelText(a11yLabel), changeValue.toString());
58
+ expect(queryByText(changeValue.toString())).toBeNull();
59
+ expect(getByDisplayValue(initialValue.toString())).toBeDefined();
60
+ }));
61
+ it("passes validation when decimal value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
62
+ const a11yLabel = "InputNumberTest";
63
+ const onChange = jest.fn();
64
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
65
+ const numInput = "13.5";
66
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
67
+ yield waitFor(() => {
68
+ fireEvent(getByLabelText(a11yLabel), "blur");
69
+ });
70
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
71
+ expect(onChange).toHaveBeenCalledWith(parseFloat(numInput));
72
+ }));
73
+ it("passes validation when negative value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
74
+ const a11yLabel = "InputNumberTest";
75
+ const onChange = jest.fn();
76
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
77
+ const numInput = "-15";
78
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
79
+ yield waitFor(() => {
80
+ fireEvent(getByLabelText(a11yLabel), "blur");
81
+ });
82
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
83
+ expect(onChange).toHaveBeenCalledWith(parseInt(numInput, 10));
84
+ }));
85
+ it("passes validation when negative decimal value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
86
+ const a11yLabel = "InputNumberTest";
87
+ const onChange = jest.fn();
88
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
89
+ const numInput = "-15.123";
90
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
91
+ yield waitFor(() => {
92
+ fireEvent(getByLabelText(a11yLabel), "blur");
93
+ });
94
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
95
+ expect(onChange).toHaveBeenCalledWith(parseFloat(numInput));
96
+ }));
97
+ it("passes validation when explicit positive value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
98
+ const a11yLabel = "InputNumberTest";
99
+ const onChange = jest.fn();
100
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
101
+ const numInput = "+15";
102
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
103
+ yield waitFor(() => {
104
+ fireEvent(getByLabelText(a11yLabel), "blur");
105
+ });
106
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
107
+ expect(onChange).toHaveBeenCalledWith(parseInt(numInput, 10));
108
+ }));
109
+ it("passes validation when e notation value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
110
+ const a11yLabel = "InputNumberTest";
111
+ const onChange = jest.fn();
112
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
113
+ const numInput = "6e10";
114
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
115
+ yield waitFor(() => {
116
+ fireEvent(getByLabelText(a11yLabel), "blur");
117
+ });
118
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
119
+ expect(onChange).toHaveBeenCalledWith(parseFloat(numInput));
120
+ }));
121
+ it("passes validation when e notation decimal value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
122
+ const a11yLabel = "InputNumberTest";
123
+ const onChange = jest.fn();
124
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
125
+ const numInput = "6.456e10";
126
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
127
+ yield waitFor(() => {
128
+ fireEvent(getByLabelText(a11yLabel), "blur");
129
+ });
130
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
131
+ expect(onChange).toHaveBeenCalledWith(parseFloat(numInput));
132
+ }));
133
+ it("passes validation when e notation for representing decimal value is entered", () => __awaiter(void 0, void 0, void 0, function* () {
134
+ const a11yLabel = "InputNumberTest";
135
+ const onChange = jest.fn();
136
+ const { queryByText, getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
137
+ const numInput = "6e-10";
138
+ fireEvent.changeText(getByLabelText(a11yLabel), numInput);
139
+ yield waitFor(() => {
140
+ fireEvent(getByLabelText(a11yLabel), "blur");
141
+ });
142
+ expect(queryByText(notANumberErrorMessage)).toBeNull();
143
+ expect(onChange).toHaveBeenCalledWith(parseFloat(numInput));
144
+ }));
145
+ describe("when the value ends with period", () => {
146
+ const values = [".", "0.", "12.", "+1.", "-0."];
147
+ it.each(values)("doesn't convert the value %s", value => {
148
+ const a11yLabel = "InputNumberTest";
149
+ const onChange = jest.fn();
150
+ const { getByLabelText, getByDisplayValue } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
151
+ fireEvent.changeText(getByLabelText(a11yLabel), value);
152
+ expect(getByDisplayValue(value)).toBeDefined();
153
+ });
154
+ });
155
+ describe("when the value ends with scientific notation", () => {
156
+ const values = ["1e", "+2e", "1.2e", "-3e"];
157
+ it.each(values)("doesn't convert the value %s", value => {
158
+ const a11yLabel = "InputNumberTest";
159
+ const onChange = jest.fn();
160
+ const { getByLabelText, getByDisplayValue } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
161
+ fireEvent.changeText(getByLabelText(a11yLabel), value);
162
+ expect(getByDisplayValue(value)).toBeDefined();
163
+ });
164
+ });
165
+ describe("when the value ends with + or -", () => {
166
+ const values = ["+", "-"];
167
+ it.each(values)("doesn't convert the value %s", value => {
168
+ const a11yLabel = "InputNumberTest";
169
+ const onChange = jest.fn();
170
+ const { getByLabelText, getByDisplayValue } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
171
+ fireEvent.changeText(getByLabelText(a11yLabel), value);
172
+ expect(getByDisplayValue(value)).toBeDefined();
173
+ });
174
+ });
175
+ describe("when the value ends with zero decimal", () => {
176
+ const values = ["0.0", "+0.00000", "-3.00000", "2.100", ".0", ".00000"];
177
+ it.each(values)("doesn't convert the value %s", value => {
178
+ const a11yLabel = "InputNumberTest";
179
+ const onChange = jest.fn();
180
+ const { getByLabelText, getByDisplayValue } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, onChange: onChange }));
181
+ fireEvent.changeText(getByLabelText(a11yLabel), value);
182
+ expect(getByDisplayValue(value)).toBeDefined();
183
+ });
184
+ });
185
+ describe("when the OS is iOS", () => {
186
+ const a11yLabel = "InputNumberTest";
187
+ beforeEach(() => {
188
+ Platform.OS = "ios";
189
+ });
190
+ it("uses the decimal-pad keyboard when keyboard is 'decimal-pad'", () => {
191
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, keyboard: "decimal-pad" }));
192
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("decimal-pad");
193
+ });
194
+ it("uses the default numbers-and-punctuation keyboard when missing keyboard prop", () => {
195
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel }));
196
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("numbers-and-punctuation");
197
+ });
198
+ it("uses the numbers-and-punctuation keyboard when keyboard is 'numbers-and-punctuation'", () => {
199
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, keyboard: "numbers-and-punctuation" }));
200
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("numbers-and-punctuation");
201
+ });
202
+ });
203
+ describe("when the OS is android", () => {
204
+ const a11yLabel = "InputNumberTest";
205
+ beforeEach(() => {
206
+ Platform.OS = "android";
207
+ });
208
+ it("uses the numeric keyboard when missing keyboard prop", () => {
209
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel }));
210
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("numeric");
211
+ });
212
+ it("uses the numeric keyboard when keyboard is 'decimal-pad'", () => {
213
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, keyboard: "decimal-pad" }));
214
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("numeric");
215
+ });
216
+ it("uses the numeric keyboard when keyboard is 'numbers-and-punctuation'", () => {
217
+ const { getByLabelText } = render(React.createElement(InputNumber, { accessibilityLabel: a11yLabel, keyboard: "numbers-and-punctuation" }));
218
+ expect(getByLabelText(a11yLabel).props.keyboardType).toEqual("numeric");
219
+ });
220
+ });
@@ -0,0 +1,63 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React from "react";
11
+ import { fireEvent, render, waitFor } from "@testing-library/react-native";
12
+ import { InputPassword } from "./InputPassword";
13
+ const MockInputFieldWrapper = jest.fn();
14
+ jest.mock("../InputFieldWrapper", () => (Object.assign(Object.assign({}, jest.requireActual("../InputFieldWrapper")), { InputFieldWrapper: function Mock(props) {
15
+ MockInputFieldWrapper(props);
16
+ return jest.requireActual("../InputFieldWrapper").InputFieldWrapper(props);
17
+ } })));
18
+ describe("InputPassword", () => {
19
+ it("renders an InputPassword", () => {
20
+ const value = "password";
21
+ const { getByDisplayValue } = render(React.createElement(InputPassword, { value: value }));
22
+ expect(getByDisplayValue(value)).toBeTruthy();
23
+ });
24
+ it("displays the validation message when an invalid password is entered", () => __awaiter(void 0, void 0, void 0, function* () {
25
+ const a11yLabel = "InputPasswordTest";
26
+ const { getByText, getByLabelText } = render(React.createElement(InputPassword, { value: "", accessibilityLabel: a11yLabel }));
27
+ yield waitFor(() => {
28
+ fireEvent(getByLabelText(a11yLabel), "blur");
29
+ });
30
+ expect(getByText("Enter a password", {
31
+ includeHiddenElements: true,
32
+ })).toBeDefined();
33
+ }));
34
+ describe("InputPassword gets the expected props", () => {
35
+ it("renders an invalid InputPassword", () => {
36
+ const props = { invalid: true };
37
+ render(React.createElement(InputPassword, Object.assign({}, props)));
38
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
39
+ });
40
+ });
41
+ describe("Privacy eye", () => {
42
+ it("renders when usePrivaryEye is true", () => {
43
+ const testId = "eye";
44
+ const { getByTestId } = render(React.createElement(InputPassword, { value: "password", suffix: {
45
+ icon: testId,
46
+ } }));
47
+ expect(getByTestId("eye")).toBeDefined();
48
+ });
49
+ it("does not render when usePrivaryEye is false", () => {
50
+ const testId = "eye";
51
+ const { queryByTestId } = render(React.createElement(InputPassword, { value: "password", usePrivacyEye: false, suffix: {
52
+ icon: testId,
53
+ } }));
54
+ expect(queryByTestId("eye")).toBeNull();
55
+ });
56
+ it("obscures the password by default", () => {
57
+ const { getByDisplayValue } = render(React.createElement(InputPassword, { value: "password", suffix: {
58
+ icon: "eye",
59
+ } }));
60
+ expect(getByDisplayValue("password").props.secureTextEntry).toBeTruthy();
61
+ });
62
+ });
63
+ });
@@ -0,0 +1,138 @@
1
+ import React from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react-native";
3
+ import { InputPressable } from ".";
4
+ const MockInputFieldWrapper = jest.fn();
5
+ jest.mock("../InputFieldWrapper", () => (Object.assign(Object.assign({}, jest.requireActual("../InputFieldWrapper")), { InputFieldWrapper: function Mock(props) {
6
+ MockInputFieldWrapper(props);
7
+ return jest.requireActual("../InputFieldWrapper").InputFieldWrapper(props);
8
+ } })));
9
+ describe("InputPressable", () => {
10
+ describe("InputFieldWrapper gets the expected props", () => {
11
+ it("renders an invalid InputPressable", () => {
12
+ const props = { invalid: true };
13
+ render(React.createElement(InputPressable, Object.assign({}, props)));
14
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
15
+ });
16
+ it("renders an invalid InputPressable with text", () => {
17
+ const props = { invalid: "this test is invalid" };
18
+ render(React.createElement(InputPressable, Object.assign({}, props)));
19
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
20
+ });
21
+ it("renders a valid InputText with empty string", () => {
22
+ const props = { invalid: "" };
23
+ render(React.createElement(InputPressable, Object.assign({}, props)));
24
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
25
+ });
26
+ it("renders a disabled InputPressable", () => {
27
+ const props = { disabled: true };
28
+ render(React.createElement(InputPressable, Object.assign({}, props)));
29
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
30
+ });
31
+ it("renders an InputPressable with a placeholder", () => {
32
+ const props = { placeholder: "test placeholder" };
33
+ render(React.createElement(InputPressable, Object.assign({}, props)));
34
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
35
+ });
36
+ });
37
+ it("renders an InputPressable with a value", () => {
38
+ const value = "test value";
39
+ const { getByText } = render(React.createElement(InputPressable, { value: value }));
40
+ expect(getByText(value, { includeHiddenElements: true })).toBeTruthy();
41
+ });
42
+ it("renders a prefix label when specified", () => {
43
+ const label = "test label";
44
+ const { getByText } = render(React.createElement(InputPressable, { prefix: { label }, value: "hey" }));
45
+ expect(getByText(label)).toBeDefined();
46
+ });
47
+ it("renders a prefix icon when specified", () => {
48
+ const { getByTestId } = render(React.createElement(InputPressable, { prefix: { icon: "calendar" } }));
49
+ expect(getByTestId("calendar")).toBeDefined();
50
+ });
51
+ it("renders a suffix icon when specified", () => {
52
+ const { getByTestId } = render(React.createElement(InputPressable, { suffix: { icon: "calendar" } }));
53
+ expect(getByTestId("calendar")).toBeDefined();
54
+ });
55
+ it("calls onPress when pressed", () => {
56
+ const onPressMock = jest.fn();
57
+ const a11yLabel = "test InputPressable";
58
+ const { getByLabelText } = render(React.createElement(InputPressable, { onPress: onPressMock, value: "test value", accessibilityLabel: a11yLabel }));
59
+ fireEvent.press(getByLabelText(a11yLabel));
60
+ expect(onPressMock).toHaveBeenCalledTimes(1);
61
+ });
62
+ describe("when given a value", () => {
63
+ const value = "A value";
64
+ it("renders an InputPressable with the value", () => {
65
+ const { getByText } = render(React.createElement(InputPressable, { value: value }));
66
+ expect(getByText(value, { includeHiddenElements: true })).toBeDefined();
67
+ });
68
+ it("renders a prefix label when specified", () => {
69
+ const { getByText } = render(React.createElement(InputPressable, { prefix: { label: "test" }, value: value }));
70
+ expect(getByText(value, { includeHiddenElements: true })).toBeDefined();
71
+ });
72
+ it("renders a suffix label when specified", () => {
73
+ const { getByText } = render(React.createElement(InputPressable, { suffix: { label: "test" }, value: value }));
74
+ expect(getByText(value, { includeHiddenElements: true })).toBeDefined();
75
+ });
76
+ });
77
+ describe("showMiniLabel", () => {
78
+ it("defaults to true", () => {
79
+ const props = { placeholder: "placeholder", value: "value" };
80
+ render(React.createElement(InputPressable, Object.assign({}, props)));
81
+ expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
82
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
83
+ placeholderMode: "mini",
84
+ }));
85
+ });
86
+ describe("when true", () => {
87
+ it("renders the placeholder in its normal position when the input has no value", () => {
88
+ const props = { showMiniLabel: true, placeholder: "placeholder" };
89
+ render(React.createElement(InputPressable, Object.assign({}, props)));
90
+ expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
91
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
92
+ placeholderMode: "normal",
93
+ }));
94
+ });
95
+ it("renders the placeholder as a mini label when the input has a value", () => {
96
+ const props = {
97
+ showMiniLabel: true,
98
+ placeholder: "placeholder",
99
+ value: "value",
100
+ };
101
+ render(React.createElement(InputPressable, Object.assign({}, props)));
102
+ expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
103
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
104
+ placeholderMode: "mini",
105
+ }));
106
+ });
107
+ });
108
+ describe("when false", () => {
109
+ it("renders the placeholder in its normal position when the input has no value", () => {
110
+ const props = { showMiniLabel: false, placeholder: "placeholder" };
111
+ render(React.createElement(InputPressable, Object.assign({}, props)));
112
+ expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
113
+ expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
114
+ placeholderMode: "normal",
115
+ }));
116
+ });
117
+ it("does not render the placeholder when the input has a value", () => {
118
+ const props = {
119
+ showMiniLabel: false,
120
+ placeholder: "placeholder",
121
+ value: "value",
122
+ };
123
+ render(React.createElement(InputPressable, Object.assign({}, props)));
124
+ expect(screen.queryByText("placeholder", { includeHiddenElements: true })).toBeNull();
125
+ });
126
+ });
127
+ });
128
+ });
129
+ describe("accessibilityLabel", () => {
130
+ it("uses accessibilityLabel if specified", () => {
131
+ const { getByLabelText } = render(React.createElement(InputPressable, { value: "test value", placeholder: "placeholder", accessibilityLabel: "accessibilityLabel" }));
132
+ expect(getByLabelText("accessibilityLabel")).toBeTruthy();
133
+ });
134
+ it("uses placeholder if unspecified", () => {
135
+ const { getByLabelText } = render(React.createElement(InputPressable, { value: "test value", placeholder: "placeholder" }));
136
+ expect(getByLabelText("placeholder")).toBeTruthy();
137
+ });
138
+ });
@@ -0,0 +1,54 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React from "react";
11
+ import { fireEvent, render, waitFor } from "@testing-library/react-native";
12
+ import { InputSearch } from "./InputSearch";
13
+ const accessibilityLabelSearch = "Search";
14
+ const accessibilityHint = "Search clients, properties, quotes, etc.";
15
+ const mockOnChange = jest.fn();
16
+ const mockOnDebouncedChange = jest.fn();
17
+ let searchValue;
18
+ beforeEach(() => {
19
+ mockOnChange.mockReset();
20
+ mockOnDebouncedChange.mockReset();
21
+ searchValue = "";
22
+ });
23
+ function setup() {
24
+ return render(React.createElement(InputSearch, { accessibilityHint: accessibilityHint, accessibilityLabel: accessibilityLabelSearch, placeholder: accessibilityHint, value: searchValue, onChange: mockOnChange, onDebouncedChange: mockOnDebouncedChange }));
25
+ }
26
+ describe("InputSearch", () => {
27
+ it("renders the search input text", () => {
28
+ const { getByHintText, getByLabelText } = setup();
29
+ expect(getByLabelText(accessibilityLabelSearch)).toBeDefined();
30
+ expect(getByHintText(accessibilityHint)).toBeDefined();
31
+ });
32
+ it("passes the correct search value to onChange when the value changed", () => {
33
+ const { getByLabelText } = setup();
34
+ const inputSearch = getByLabelText(accessibilityLabelSearch);
35
+ fireEvent.changeText(inputSearch, "Apollo Client");
36
+ expect(mockOnChange).toHaveBeenCalledWith("Apollo Client");
37
+ });
38
+ it("passes the correcet search value to onDebouncedChange when the value changed", () => __awaiter(void 0, void 0, void 0, function* () {
39
+ const { getByLabelText } = setup();
40
+ const inputSearch = getByLabelText(accessibilityLabelSearch);
41
+ yield waitFor(() => {
42
+ fireEvent.changeText(inputSearch, "Update Apollo Client");
43
+ expect(mockOnDebouncedChange).toHaveBeenCalled();
44
+ });
45
+ }));
46
+ it("clears the search value when the clear button is pressed", () => {
47
+ searchValue = "test search value";
48
+ const { getByLabelText } = setup();
49
+ fireEvent(getByLabelText(accessibilityLabelSearch), "focus");
50
+ const inputSearchClearButton = getByLabelText("Clear input");
51
+ fireEvent.press(inputSearchClearButton);
52
+ expect(mockOnChange).toHaveBeenCalledWith("");
53
+ });
54
+ });