@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,72 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
+ import { View } from "react-native";
4
+ import { SelectInternalPicker } from ".";
5
+ import { Text } from "../../../Text";
6
+ let Platform;
7
+ beforeEach(() => {
8
+ Platform = require("react-native").Platform;
9
+ Object.defineProperty(Platform, "Version", { get: () => undefined });
10
+ });
11
+ function MockPicker() {
12
+ return React.createElement("MockPicker");
13
+ }
14
+ const MockPickerItem = () => React.createElement(React.Fragment, null);
15
+ jest.mock("@react-native-picker/picker", () => ({ Picker: MockPicker }));
16
+ MockPicker.Item = MockPickerItem;
17
+ afterEach(() => {
18
+ jest.resetAllMocks();
19
+ });
20
+ const RCTPicker = "RCTATLPicker";
21
+ const childText = "Click me";
22
+ const handleChange = jest.fn();
23
+ function setup(props) {
24
+ return render(React.createElement(View, { testID: "SelectInternalPicker" },
25
+ React.createElement(SelectInternalPicker, { onChange: handleChange, disabled: props === null || props === void 0 ? void 0 : props.disabled, options: [
26
+ { value: "1", label: "First option" },
27
+ { value: "2", label: "Second option" },
28
+ ] },
29
+ React.createElement(Text, null, childText))));
30
+ }
31
+ describe("SelectInternalPicker", () => {
32
+ it("fires the onChange", () => {
33
+ const screen = setup();
34
+ fireEvent.press(screen.getByText(childText));
35
+ const menu = screen
36
+ .getByTestId("SelectInternalPicker")
37
+ .findByType(MockPicker);
38
+ expect(menu).toBeDefined();
39
+ fireEvent(menu, "onChange", "1");
40
+ expect(handleChange).toHaveBeenCalledWith("1");
41
+ });
42
+ describe("iOS 13 and below fallback", () => {
43
+ it("renders the iOS 14 native menu picker", () => {
44
+ Platform.OS = "ios";
45
+ Object.defineProperty(Platform, "Version", { get: () => "14.1" });
46
+ const screen = setup();
47
+ const menu = screen
48
+ .getByTestId("SelectInternalPicker")
49
+ .findByType(RCTPicker);
50
+ expect(menu).toBeDefined();
51
+ });
52
+ it.each([
53
+ ["ios", "13.1"],
54
+ ["android", 100],
55
+ ])("renders the menu picker on %s", (os, version) => {
56
+ Platform.OS = os;
57
+ Object.defineProperty(Platform, "Version", { get: () => version });
58
+ const screen = setup();
59
+ fireEvent.press(screen.getByText(childText));
60
+ expect(screen.getByTestId("SelectInternalPicker").findByType(MockPicker)).toBeDefined();
61
+ });
62
+ });
63
+ describe("Disabled", () => {
64
+ it("should not render the picker", () => {
65
+ const screen = setup({ disabled: true });
66
+ const menu = screen
67
+ .getByTestId("SelectInternalPicker")
68
+ .findAllByType(RCTPicker);
69
+ expect(menu).toEqual([]);
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,51 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { StatusLabel } from "./StatusLabel";
4
+ describe("StatusLabel", () => {
5
+ describe("alignment", () => {
6
+ describe('when alignment prop set to default ("start")', () => {
7
+ it("should match snapshot", () => {
8
+ const view = render(React.createElement(StatusLabel, { text: "Start Aligned" })).toJSON();
9
+ expect(view).toMatchSnapshot();
10
+ });
11
+ });
12
+ describe('when alignment prop set to "end"', () => {
13
+ it("should match snapshot", () => {
14
+ const view = render(React.createElement(StatusLabel, { text: "End Aligned", alignment: "end" })).toJSON();
15
+ expect(view).toMatchSnapshot();
16
+ });
17
+ });
18
+ });
19
+ describe("status", () => {
20
+ describe('when status prop set to default ("success")', () => {
21
+ it("should match snapshot", () => {
22
+ const view = render(React.createElement(StatusLabel, { text: "Success" })).toJSON();
23
+ expect(view).toMatchSnapshot();
24
+ });
25
+ });
26
+ describe('when status prop set to "warning"', () => {
27
+ it("should match snapshot", () => {
28
+ const view = render(React.createElement(StatusLabel, { text: "Warning", status: "warning" })).toJSON();
29
+ expect(view).toMatchSnapshot();
30
+ });
31
+ });
32
+ describe('when status prop set to "critical"', () => {
33
+ it("should match snapshot", () => {
34
+ const view = render(React.createElement(StatusLabel, { text: "Critical", status: "critical" })).toJSON();
35
+ expect(view).toMatchSnapshot();
36
+ });
37
+ });
38
+ describe('when status prop set to "inactive"', () => {
39
+ it("should match snapshot", () => {
40
+ const view = render(React.createElement(StatusLabel, { text: "Inactive", status: "inactive" })).toJSON();
41
+ expect(view).toMatchSnapshot();
42
+ });
43
+ });
44
+ describe('when status prop set to "informative"', () => {
45
+ it("should match snapshot", () => {
46
+ const view = render(React.createElement(StatusLabel, { text: "Informative", status: "informative" })).toJSON();
47
+ expect(view).toMatchSnapshot();
48
+ });
49
+ });
50
+ });
51
+ });
@@ -0,0 +1,60 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
+ import { Switch } from "./Switch";
4
+ it("renders a labeled Switch with value true", () => {
5
+ const { getByLabelText } = render(React.createElement(Switch, { value: true, label: "true switch" }));
6
+ const valueProp = getByLabelText("true switch").props.value;
7
+ expect(valueProp).toEqual(true);
8
+ });
9
+ it("renders a labeled Switch with value false", () => {
10
+ const { getByLabelText } = render(React.createElement(Switch, { value: false, label: "false switch" }));
11
+ const valueProp = getByLabelText("false switch").props.value;
12
+ expect(valueProp).toEqual(false);
13
+ });
14
+ it("renders an unlabeled Switch with value true", () => {
15
+ const { getByRole } = render(React.createElement(Switch, { value: true }));
16
+ const valueProp = getByRole("switch").props.value;
17
+ expect(valueProp).toEqual(true);
18
+ });
19
+ it("renders an unlabeled Switch with value false", () => {
20
+ const { getByRole } = render(React.createElement(Switch, { value: false }));
21
+ const valueProp = getByRole("switch").props.value;
22
+ expect(valueProp).toEqual(false);
23
+ });
24
+ describe("description", () => {
25
+ it("renders a Switch with label and description", () => {
26
+ const { getByText } = render(React.createElement(Switch, { label: "Label", description: "Description" }));
27
+ expect(getByText("Label")).toBeDefined();
28
+ expect(getByText("Description")).toBeDefined();
29
+ });
30
+ it("matches the width of the label and description", () => {
31
+ const { getByTestId } = render(React.createElement(Switch, { label: "Label", description: "Description" }));
32
+ const labelView = getByTestId("switch-label-view");
33
+ const descriptionView = getByTestId("switch-description-view");
34
+ fireEvent(labelView, "onLayout", {
35
+ nativeEvent: {
36
+ layout: {
37
+ width: 123,
38
+ },
39
+ },
40
+ });
41
+ const flattenedStyle = descriptionView.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
42
+ expect(flattenedStyle).toEqual(expect.objectContaining({
43
+ maxWidth: 123,
44
+ }));
45
+ });
46
+ });
47
+ describe("accessibilityLabel", () => {
48
+ it("uses accessibilityLabel if specified", () => {
49
+ const { getByLabelText } = render(React.createElement(Switch, { value: true, label: "label", accessibilityLabel: "accessibilityLabel" }));
50
+ expect(getByLabelText("accessibilityLabel")).toBeTruthy();
51
+ });
52
+ it("uses placeholder if unspecified", () => {
53
+ const { getByLabelText } = render(React.createElement(Switch, { value: true, label: "label" }));
54
+ expect(getByLabelText("label")).toBeTruthy();
55
+ });
56
+ it("unavailable if unspecified", () => {
57
+ const { queryByLabelText } = render(React.createElement(Switch, { value: true }));
58
+ expect(queryByLabelText("label")).not.toBeTruthy();
59
+ });
60
+ });
@@ -0,0 +1,61 @@
1
+ import React from "react";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
+ import { BaseSwitch } from "./BaseSwitch";
4
+ describe("BaseSwitch", () => {
5
+ describe("rendering", () => {
6
+ it("renders with value true", () => {
7
+ const { getByRole } = render(React.createElement(BaseSwitch, { value: true }));
8
+ const switchElement = getByRole("switch");
9
+ expect(switchElement).toBeDefined();
10
+ expect(switchElement.props.accessibilityState.checked).toBe(true);
11
+ });
12
+ it("renders with defaultValue true", () => {
13
+ const { getByRole } = render(React.createElement(BaseSwitch, { defaultValue: true }));
14
+ const switchElement = getByRole("switch");
15
+ expect(switchElement).toBeDefined();
16
+ expect(switchElement.props.accessibilityState.checked).toBe(true);
17
+ });
18
+ it("renders with value false", () => {
19
+ const { getByRole } = render(React.createElement(BaseSwitch, { value: false }));
20
+ const switchElement = getByRole("switch");
21
+ expect(switchElement).toBeDefined();
22
+ expect(switchElement.props.accessibilityState.checked).toBe(false);
23
+ });
24
+ it("renders with defaultValue false", () => {
25
+ const { getByRole } = render(React.createElement(BaseSwitch, { defaultValue: false }));
26
+ const switchElement = getByRole("switch");
27
+ expect(switchElement).toBeDefined();
28
+ expect(switchElement.props.accessibilityState.checked).toBe(false);
29
+ });
30
+ it("renders correctly when disabled with value true", () => {
31
+ const { getByRole } = render(React.createElement(BaseSwitch, { value: true, disabled: true }));
32
+ const switchElement = getByRole("switch");
33
+ expect(switchElement).toBeDefined();
34
+ expect(switchElement.props.accessibilityState.checked).toBe(true);
35
+ expect(switchElement.props.accessibilityState.disabled).toBe(true);
36
+ });
37
+ it("renders correctly when disabled with value false", () => {
38
+ const { getByRole } = render(React.createElement(BaseSwitch, { value: false, disabled: true }));
39
+ const switchElement = getByRole("switch");
40
+ expect(switchElement).toBeDefined();
41
+ expect(switchElement.props.accessibilityState.checked).toBe(false);
42
+ expect(switchElement.props.accessibilityState.disabled).toBe(true);
43
+ });
44
+ });
45
+ describe("behavior", () => {
46
+ it("invokes the valueChange callback", () => {
47
+ const valueChangedCallback = jest.fn();
48
+ const { getByLabelText } = render(React.createElement(BaseSwitch, { value: false, onValueChange: valueChangedCallback, accessibilityLabel: "test switch" }));
49
+ fireEvent(getByLabelText("test switch"), "valueChange", true);
50
+ expect(valueChangedCallback).toHaveBeenCalledWith(true);
51
+ fireEvent(getByLabelText("test switch"), "valueChange", false);
52
+ expect(valueChangedCallback).toHaveBeenCalledWith(false);
53
+ });
54
+ it("doesn't invoke the valueChange callback if disabled", () => {
55
+ const valueChangedCallback = jest.fn();
56
+ const { getByLabelText } = render(React.createElement(BaseSwitch, { value: false, disabled: true, onValueChange: valueChangedCallback, accessibilityLabel: "test switch" }));
57
+ fireEvent(getByLabelText("test switch"), "valueChange", true);
58
+ expect(valueChangedCallback).not.toHaveBeenCalled();
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,161 @@
1
+ import React from "react";
2
+ import { fireEvent, render, screen } from "@testing-library/react-native";
3
+ import { Text } from ".";
4
+ import { tokens } from "../utils/design";
5
+ it("renders text with no additional props", () => {
6
+ const text = render(React.createElement(Text, null, "Test Text"));
7
+ expect(text.toJSON()).toMatchSnapshot();
8
+ });
9
+ it("renders text with base variation", () => {
10
+ const text = render(React.createElement(Text, { variation: "base" }, "Test Text"));
11
+ expect(text.toJSON()).toMatchSnapshot();
12
+ });
13
+ it("renders text with success variation", () => {
14
+ const text = render(React.createElement(Text, { variation: "success" }, "Test Text"));
15
+ expect(text.toJSON()).toMatchSnapshot();
16
+ });
17
+ it("renders text with error variation", () => {
18
+ const text = render(React.createElement(Text, { variation: "error" }, "Test Text"));
19
+ expect(text.toJSON()).toMatchSnapshot();
20
+ });
21
+ it("renders text with warn variation", () => {
22
+ const text = render(React.createElement(Text, { variation: "warn" }, "Test Text"));
23
+ expect(text.toJSON()).toMatchSnapshot();
24
+ });
25
+ it("renders text with info variation", () => {
26
+ const text = render(React.createElement(Text, { variation: "info" }, "Test Text"));
27
+ expect(text.toJSON()).toMatchSnapshot();
28
+ });
29
+ it("renders text with subdued variation", () => {
30
+ const text = render(React.createElement(Text, { variation: "subdued" }, "Test Text"));
31
+ expect(text.toJSON()).toMatchSnapshot();
32
+ });
33
+ it("renders text with success variation reverseTheme true", () => {
34
+ const text = render(React.createElement(Text, { variation: "success", reverseTheme: true }, "Test Text"));
35
+ expect(text.toJSON()).toMatchSnapshot();
36
+ });
37
+ it("renders text with error variation reverseTheme true", () => {
38
+ const text = render(React.createElement(Text, { variation: "error", reverseTheme: true }, "Test Text"));
39
+ expect(text.toJSON()).toMatchSnapshot();
40
+ });
41
+ it("renders text supporting with no additional props", () => {
42
+ const text = render(React.createElement(Text, { level: "textSupporting" }, "Test Text"));
43
+ expect(text.toJSON()).toMatchSnapshot();
44
+ });
45
+ it("renders text supporting with variation success", () => {
46
+ const text = render(React.createElement(Text, { level: "textSupporting", variation: "success" }, "Test Text"));
47
+ expect(text.toJSON()).toMatchSnapshot();
48
+ });
49
+ it("renders text supporting with variation success reverseTheme true", () => {
50
+ const text = render(React.createElement(Text, { level: "textSupporting", variation: "success", reverseTheme: true }, "Test Text"));
51
+ expect(text.toJSON()).toMatchSnapshot();
52
+ });
53
+ it("renders text with right alignment", () => {
54
+ const text = render(React.createElement(Text, { align: "end" }, "Test Text"));
55
+ expect(text.toJSON()).toMatchSnapshot();
56
+ });
57
+ it("renders text with center alignment", () => {
58
+ const text = render(React.createElement(Text, { align: "center" }, "Test Text"));
59
+ expect(text.toJSON()).toMatchSnapshot();
60
+ });
61
+ it("renders text with left alignment", () => {
62
+ const text = render(React.createElement(Text, { align: "start" }, "Test Text"));
63
+ expect(text.toJSON()).toMatchSnapshot();
64
+ });
65
+ it("renders text that is scaled down with adjustsFontSize true", () => {
66
+ const text = render(React.createElement(Text, { maxLines: "base", adjustsFontSizeToFit: true }, "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog"));
67
+ expect(text.toJSON()).toMatchSnapshot();
68
+ });
69
+ it("renders text that is not scaled down with adjustsFontSize false", () => {
70
+ const text = render(React.createElement(Text, { maxLines: "base", adjustsFontSizeToFit: false }, "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog"));
71
+ expect(text.toJSON()).toMatchSnapshot();
72
+ });
73
+ it("renders text with accessibilityRole set as text", () => {
74
+ const text = render(React.createElement(Text, null, "Test Text"));
75
+ expect(text.getByRole("text")).toBeDefined();
76
+ });
77
+ it("renders with strikethrough styling", () => {
78
+ const text = render(React.createElement(Text, { strikeThrough: true }, "Test Text"));
79
+ expect(text.toJSON()).toMatchSnapshot();
80
+ });
81
+ it("renders with italic styling", () => {
82
+ const text = render(React.createElement(Text, { italic: true }, "Test Text"));
83
+ expect(text.toJSON()).toMatchSnapshot();
84
+ });
85
+ it("renders text that is inaccessible", () => {
86
+ const text = render(React.createElement(Text, { hideFromScreenReader: true }, "Test Text"));
87
+ expect(text.root.props).toEqual(expect.objectContaining({
88
+ accessibilityRole: "none",
89
+ accessible: false,
90
+ importantForAccessibility: "no-hide-descendants",
91
+ }));
92
+ });
93
+ it("renders text with underline styling", () => {
94
+ const text = render(React.createElement(Text, { underline: "dotted" }, "Test Text"));
95
+ expect(text.toJSON()).toMatchSnapshot();
96
+ });
97
+ it("supports nested Text children with mixed styles", () => {
98
+ const { getByText, toJSON } = render(React.createElement(Text, null,
99
+ "Hello ",
100
+ React.createElement(Text, { emphasis: "strong" }, "World"),
101
+ "!"));
102
+ expect(getByText("World")).toBeDefined();
103
+ expect(toJSON()).toMatchSnapshot();
104
+ });
105
+ describe("UNSAFE_style", () => {
106
+ it("applies custom styles via UNSAFE_style prop", () => {
107
+ const customStyle = {
108
+ textStyle: {
109
+ fontSize: 20,
110
+ color: tokens["color-blue--dark"],
111
+ },
112
+ };
113
+ render(React.createElement(Text, { UNSAFE_style: customStyle }, "Test Text"));
114
+ const textElement = screen.getByRole("text");
115
+ expect(textElement.props.style).toContainEqual(expect.objectContaining(customStyle.textStyle));
116
+ });
117
+ });
118
+ describe("onTextLayout", () => {
119
+ it("calls onTextLayout callback when text layout event occurs", () => {
120
+ const onTextLayoutMock = jest.fn();
121
+ render(React.createElement(Text, { onTextLayout: onTextLayoutMock }, "Test Text"));
122
+ const textElement = screen.getByRole("text");
123
+ const mockEvent = {
124
+ nativeEvent: {
125
+ lines: [
126
+ {
127
+ text: "Test Text",
128
+ x: 0,
129
+ y: 0,
130
+ width: 100,
131
+ height: 20,
132
+ ascender: 15,
133
+ descender: -5,
134
+ capHeight: 14,
135
+ xHeight: 10,
136
+ },
137
+ ],
138
+ },
139
+ };
140
+ fireEvent(textElement, "onTextLayout", mockEvent);
141
+ expect(onTextLayoutMock).toHaveBeenCalledTimes(1);
142
+ expect(onTextLayoutMock).toHaveBeenCalledWith(mockEvent);
143
+ });
144
+ });
145
+ describe("TypographyGestureDetector", () => {
146
+ it("wraps text with TypographyGestureDetector by default (collapsable=false)", () => {
147
+ const { getByRole } = render(React.createElement(Text, null, "Test Text"));
148
+ const textElement = getByRole("text");
149
+ expect(textElement.props.collapsable).toBe(false);
150
+ });
151
+ it("wraps text with TypographyGestureDetector (collapsable=false) when selectable=true", () => {
152
+ const { getByRole } = render(React.createElement(Text, { selectable: true }, "Test Text"));
153
+ const textElement = getByRole("text");
154
+ expect(textElement.props.collapsable).toBe(false);
155
+ });
156
+ it("does not wrap text with TypographyGestureDetector when selectable=false", () => {
157
+ const { getByRole } = render(React.createElement(Text, { selectable: false }, "Test Text"));
158
+ const textElement = getByRole("text");
159
+ expect(textElement.props.collapsable).toBeUndefined();
160
+ });
161
+ });
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { TextList } from "./TextList";
4
+ describe("TextList", () => {
5
+ describe("when the bulletItems is provided", () => {
6
+ it("displays the text list", () => {
7
+ const items = ["this is list item uno", "this is list item dos"];
8
+ const tree = render(React.createElement(TextList, { items: items }));
9
+ expect(tree.toJSON()).toMatchSnapshot();
10
+ });
11
+ it("displays will not display a bulleted list", () => {
12
+ const tree = render(React.createElement(TextList, null));
13
+ expect(tree.toJSON()).toMatchSnapshot();
14
+ });
15
+ });
16
+ });
@@ -0,0 +1,72 @@
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, screen } from "@testing-library/react-native";
12
+ import { ThumbnailList } from "./ThumbnailList";
13
+ const snapshotFile = [
14
+ {
15
+ contentType: "image/jpeg",
16
+ fileName: "image.jpeg",
17
+ thumbnailUrl: "https://imageurl.com/ababathumb.jpg",
18
+ url: "https://imageurl.com/ababa1.jpg",
19
+ fileSize: 1024,
20
+ },
21
+ ];
22
+ const files = [
23
+ {
24
+ contentType: "image/jpeg",
25
+ fileName: "image.jpeg",
26
+ thumbnailUrl: "https://imageurl.com/ababathumb.jpg",
27
+ url: "https://imageurl.com/ababa1.jpg",
28
+ fileSize: 1024,
29
+ },
30
+ {
31
+ contentType: "image/jpeg",
32
+ fileName: "image1.jpeg",
33
+ thumbnailUrl: "https://imageurl.com/ababathumb.jpg",
34
+ url: "https://imageurl.com/ababa2.jpg",
35
+ fileSize: 1024,
36
+ },
37
+ {
38
+ contentType: "pdf",
39
+ fileName: "image2.pdf",
40
+ thumbnailUrl: "https://imageurl.com/ababathumb.jpg",
41
+ url: undefined,
42
+ fileSize: 1024,
43
+ },
44
+ ];
45
+ const onOpenFile = jest.fn();
46
+ const mockCreateThumbnail = jest.fn(() => __awaiter(void 0, void 0, void 0, function* () {
47
+ return ({
48
+ thumbnail: "thumbnail",
49
+ error: false,
50
+ });
51
+ }));
52
+ function setup(snapshot) {
53
+ return render(React.createElement(ThumbnailList, { files: snapshot ? snapshotFile : files, handleOpenFile: onOpenFile, createThumbnail: mockCreateThumbnail }));
54
+ }
55
+ beforeEach(() => {
56
+ jest.clearAllMocks();
57
+ });
58
+ it("renders a thumbnail component with attachments", () => {
59
+ setup(true);
60
+ expect(screen.toJSON()).toMatchSnapshot();
61
+ });
62
+ describe("when a an array of files is provided", () => {
63
+ it("calls the previewImages util on pressing a valid file", () => {
64
+ setup();
65
+ fireEvent.press(screen.getByLabelText(files[0].fileName ? files[0].fileName : "file"));
66
+ expect(onOpenFile).toHaveBeenCalledTimes(1);
67
+ });
68
+ it("calls createThumbnail", () => {
69
+ setup();
70
+ expect(mockCreateThumbnail).toHaveBeenCalledTimes(2);
71
+ });
72
+ });
@@ -0,0 +1,51 @@
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, screen, waitFor, } from "@testing-library/react-native";
12
+ import { AccessibilityInfo } from "react-native";
13
+ import { Toast, showToast } from ".";
14
+ import { Button } from "../Button";
15
+ import { MockSafeAreaProvider } from "../utils/test";
16
+ function expectToastWithMessage(message) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ expect(yield screen.findByText(message)).toBeDefined();
19
+ yield waitFor(() => {
20
+ // We also need to assert the accessibility info because otherwise
21
+ // the test will 'overflow' and cause other tests to fail.
22
+ expect(AccessibilityInfo.announceForAccessibility).toHaveBeenCalledWith(message);
23
+ jest.mocked(AccessibilityInfo.announceForAccessibility).mockClear();
24
+ });
25
+ });
26
+ }
27
+ function setup({ bottomOffset, message = "Notify message" }) {
28
+ return render(React.createElement(MockSafeAreaProvider, null,
29
+ React.createElement(Button, { label: "Press me", accessibilityLabel: "Button label", onPress: () => showToast({ message, bottomTabsVisible: false }) }),
30
+ React.createElement(Toast, { bottomOffset: bottomOffset })));
31
+ }
32
+ describe("Toast", () => {
33
+ it("shows the toast on trigger", () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const { getByLabelText } = setup({ bottomOffset: 20 });
35
+ const toastTriggerButton = getByLabelText("Button label");
36
+ fireEvent.press(toastTriggerButton);
37
+ yield expectToastWithMessage("Notify message");
38
+ }));
39
+ describe("When the message length exceed the defined maximum", () => {
40
+ const over60CharactersMsg = "really really really really really really really really really really really really really really really really really really really long message";
41
+ it("should log a warning that the message length is too long", () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const consoleSpy = jest.spyOn(console, "warn").mockImplementation();
43
+ const { getByLabelText } = setup({ message: over60CharactersMsg });
44
+ const toastTriggerButton = getByLabelText("Button label");
45
+ fireEvent.press(toastTriggerButton);
46
+ yield expectToastWithMessage(over60CharactersMsg);
47
+ expect(consoleSpy).toHaveBeenCalledWith("Jobber Design Warning: Message length limit exceeded, your current length is 145, the maximum allowed is 60. please talk with your designer");
48
+ consoleSpy.mockRestore();
49
+ }));
50
+ });
51
+ });