@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.
- package/dist/package.json +19 -11
- package/dist/src/ActionItem/ActionItem.test.js +81 -0
- package/dist/src/ActionItem/ActionItemGroup.test.js +25 -0
- package/dist/src/ActionItem/components/ActionItemContainer.test.js +24 -0
- package/dist/src/ActionLabel/ActionLabel.test.js +81 -0
- package/dist/src/ActivityIndicator/ActivityIndicator.test.js +23 -0
- package/dist/src/AtlantisContext/AtlantisContext.test.js +35 -0
- package/dist/src/AtlantisThemeContext/AtlantisThemeContext.test.js +65 -0
- package/dist/src/AtlantisThemeContext/buildThemedStyles.test.js +43 -0
- package/dist/src/AutoLink/AutoLink.test.js +133 -0
- package/dist/src/AutoLink/components/Link/Link.test.js +18 -0
- package/dist/src/Banner/Banner.test.js +98 -0
- package/dist/src/BottomSheet/BottomSheet.test.js +105 -0
- package/dist/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.js +19 -0
- package/dist/src/BottomSheet/hooks/useBottomSheetBackHandler.test.js +68 -0
- package/dist/src/Button/Button.test.js +228 -0
- package/dist/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.js +25 -0
- package/dist/src/ButtonGroup/ButtonGroup.test.js +153 -0
- package/dist/src/Card/Card.test.js +80 -0
- package/dist/src/Card/components/InternalCardHeader.test.js +18 -0
- package/dist/src/Checkbox/Checkbox.test.js +135 -0
- package/dist/src/Checkbox/CheckboxGroup.test.js +197 -0
- package/dist/src/Checkbox/CheckboxGroupReducer.test.js +25 -0
- package/dist/src/Chip/Chip.test.js +69 -0
- package/dist/src/Content/Content.test.js +250 -0
- package/dist/src/ContentOverlay/ContentOverlay.test.js +297 -0
- package/dist/src/ContentOverlay/computeContentOverlayBehavior.test.js +197 -0
- package/dist/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.js +62 -0
- package/dist/src/ContentOverlay/hooks/useKeyboardVisibility.test.js +41 -0
- package/dist/src/ContentOverlay/hooks/useViewLayoutHeight.test.js +62 -0
- package/dist/src/Disclosure/Disclosure.test.js +64 -0
- package/dist/src/Divider/Divider.test.js +65 -0
- package/dist/src/EmptyState/EmptyState.test.js +82 -0
- package/dist/src/ErrorMessageWrapper/ErrorMessageWrapper.test.js +29 -0
- package/dist/src/Flex/Flex.test.js +104 -0
- package/dist/src/Form/Form.test.js +393 -0
- package/dist/src/Form/components/FormErrorBanner/FormErrorBanner.test.js +41 -0
- package/dist/src/Form/components/FormMessage/FormMessage.test.js +73 -0
- package/dist/src/Form/components/FormMessageBanner/FormMessageBanner.test.js +30 -0
- package/dist/src/Form/components/FormSaveButton/FormSaveButton.test.js +82 -0
- package/dist/src/Form/context/AtlantisFormContext.test.js +28 -0
- package/dist/src/Form/hooks/useScrollToError/useScrollToError.test.js +89 -0
- package/dist/src/FormField/FormField.test.js +81 -0
- package/dist/src/FormatFile/FormatFile.test.js +212 -0
- package/dist/src/FormatFile/FormatFileThumbnail.test.js +192 -0
- package/dist/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.js +74 -0
- package/dist/src/FormatFile/components/MediaView/MediaView.test.js +202 -0
- package/dist/src/FormatFile/utils/parseFile.test.js +188 -0
- package/dist/src/Glimmer/Glimmer.test.js +61 -0
- package/dist/src/Heading/Heading.test.js +61 -0
- package/dist/src/Icon/Icon.test.js +40 -0
- package/dist/src/IconButton/IconButton.test.js +38 -0
- package/dist/src/InputCurrency/InputCurrency.test.js +106 -0
- package/dist/src/InputDate/InputDate.test.js +184 -0
- package/dist/src/InputEmail/InputEmail.test.js +27 -0
- package/dist/src/InputFieldWrapper/InputFieldWrapper.test.js +279 -0
- package/dist/src/InputFieldWrapper/components/ClearAction/ClearAction.test.js +9 -0
- package/dist/src/InputFieldWrapper/components/Prefix/Prefix.test.js +130 -0
- package/dist/src/InputFieldWrapper/components/Suffix/Suffix.test.js +51 -0
- package/dist/src/InputNumber/InputNumber.test.js +220 -0
- package/dist/src/InputPassword/InputPassword.test.js +63 -0
- package/dist/src/InputPressable/InputPressable.test.js +138 -0
- package/dist/src/InputSearch/InputSearch.test.js +54 -0
- package/dist/src/InputText/InputText.test.js +652 -0
- package/dist/src/InputText/context/InputAccessoriesProvider.test.js +71 -0
- package/dist/src/InputTime/InputTime.test.js +199 -0
- package/dist/src/InputTime/utils/utils.test.js +32 -0
- package/dist/src/ProgressBar/ProgressBar.test.js +89 -0
- package/dist/src/Select/Select.test.js +183 -0
- package/dist/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.js +51 -0
- package/dist/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.js +72 -0
- package/dist/src/StatusLabel/StatusLabel.test.js +51 -0
- package/dist/src/Switch/Switch.test.js +60 -0
- package/dist/src/Switch/components/BaseSwitch/BaseSwitch.test.js +61 -0
- package/dist/src/Text/Text.test.js +161 -0
- package/dist/src/TextList/TextList.test.js +16 -0
- package/dist/src/ThumbnailList/ThumbnailList.test.js +72 -0
- package/dist/src/Toast/Toast.test.js +51 -0
- package/dist/src/Typography/Typography.test.js +225 -0
- package/dist/src/hooks/useAtlantisI18n/useAtlantisI18n.test.js +103 -0
- package/dist/src/utils/meta/meta.test.js +83 -0
- package/dist/tsconfig.build.json +5 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/tsconfig.eslint.json +14 -0
- package/dist/tsconfig.json +3 -4
- package/dist/types/src/ActionItem/ActionItem.test.d.ts +1 -0
- package/dist/types/src/ActionItem/ActionItemGroup.test.d.ts +1 -0
- package/dist/types/src/ActionItem/components/ActionItemContainer.test.d.ts +1 -0
- package/dist/types/src/ActionLabel/ActionLabel.test.d.ts +1 -0
- package/dist/types/src/ActivityIndicator/ActivityIndicator.test.d.ts +1 -0
- package/dist/types/src/AtlantisContext/AtlantisContext.test.d.ts +1 -0
- package/dist/types/src/AtlantisThemeContext/AtlantisThemeContext.test.d.ts +1 -0
- package/dist/types/src/AtlantisThemeContext/buildThemedStyles.test.d.ts +1 -0
- package/dist/types/src/AutoLink/AutoLink.test.d.ts +1 -0
- package/dist/types/src/AutoLink/components/Link/Link.test.d.ts +1 -0
- package/dist/types/src/Banner/Banner.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/BottomSheet.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/components/BottomSheetOption/BottomSheetOption.test.d.ts +1 -0
- package/dist/types/src/BottomSheet/hooks/useBottomSheetBackHandler.test.d.ts +1 -0
- package/dist/types/src/Button/Button.test.d.ts +1 -0
- package/dist/types/src/Button/components/InternalButtonLoading/InternalButtonLoading.test.d.ts +1 -0
- package/dist/types/src/ButtonGroup/ButtonGroup.test.d.ts +1 -0
- package/dist/types/src/Card/Card.test.d.ts +1 -0
- package/dist/types/src/Card/components/InternalCardHeader.test.d.ts +1 -0
- package/dist/types/src/Checkbox/Checkbox.test.d.ts +1 -0
- package/dist/types/src/Checkbox/CheckboxGroup.test.d.ts +1 -0
- package/dist/types/src/Checkbox/CheckboxGroupReducer.test.d.ts +1 -0
- package/dist/types/src/Chip/Chip.test.d.ts +1 -0
- package/dist/types/src/Content/Content.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/BottomSheetKeyboardAwareScrollView.d.ts +2 -1
- package/dist/types/src/ContentOverlay/ContentOverlay.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/computeContentOverlayBehavior.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useBottomSheetModalBackHandler.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useKeyboardVisibility.test.d.ts +1 -0
- package/dist/types/src/ContentOverlay/hooks/useViewLayoutHeight.test.d.ts +1 -0
- package/dist/types/src/Disclosure/Disclosure.test.d.ts +1 -0
- package/dist/types/src/Divider/Divider.test.d.ts +1 -0
- package/dist/types/src/EmptyState/EmptyState.test.d.ts +1 -0
- package/dist/types/src/ErrorMessageWrapper/ErrorMessageWrapper.test.d.ts +1 -0
- package/dist/types/src/Flex/Flex.test.d.ts +1 -0
- package/dist/types/src/Form/Form.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormErrorBanner/FormErrorBanner.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormMessage/FormMessage.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormMessageBanner/FormMessageBanner.test.d.ts +1 -0
- package/dist/types/src/Form/components/FormSaveButton/FormSaveButton.test.d.ts +1 -0
- package/dist/types/src/Form/context/AtlantisFormContext.test.d.ts +1 -0
- package/dist/types/src/Form/hooks/useScrollToError/useScrollToError.test.d.ts +1 -0
- package/dist/types/src/FormField/FormField.test.d.ts +1 -0
- package/dist/types/src/FormatFile/FormatFile.test.d.ts +1 -0
- package/dist/types/src/FormatFile/FormatFileThumbnail.test.d.ts +1 -0
- package/dist/types/src/FormatFile/components/FormatFileBottomSheet/FormatFileBottomSheet.test.d.ts +1 -0
- package/dist/types/src/FormatFile/components/MediaView/MediaView.test.d.ts +1 -0
- package/dist/types/src/FormatFile/utils/parseFile.test.d.ts +1 -0
- package/dist/types/src/Glimmer/Glimmer.test.d.ts +1 -0
- package/dist/types/src/Heading/Heading.test.d.ts +1 -0
- package/dist/types/src/Icon/Icon.test.d.ts +1 -0
- package/dist/types/src/IconButton/IconButton.test.d.ts +1 -0
- package/dist/types/src/InputCurrency/InputCurrency.test.d.ts +1 -0
- package/dist/types/src/InputDate/InputDate.test.d.ts +1 -0
- package/dist/types/src/InputEmail/InputEmail.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/InputFieldWrapper.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/ClearAction/ClearAction.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.test.d.ts +1 -0
- package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.test.d.ts +1 -0
- package/dist/types/src/InputNumber/InputNumber.test.d.ts +1 -0
- package/dist/types/src/InputPassword/InputPassword.test.d.ts +1 -0
- package/dist/types/src/InputPressable/InputPressable.test.d.ts +1 -0
- package/dist/types/src/InputSearch/InputSearch.test.d.ts +1 -0
- package/dist/types/src/InputText/InputText.test.d.ts +1 -0
- package/dist/types/src/InputText/context/InputAccessoriesProvider.test.d.ts +1 -0
- package/dist/types/src/InputTime/InputTime.test.d.ts +1 -0
- package/dist/types/src/InputTime/utils/utils.test.d.ts +1 -0
- package/dist/types/src/ProgressBar/ProgressBar.test.d.ts +1 -0
- package/dist/types/src/Select/Select.test.d.ts +1 -0
- package/dist/types/src/Select/components/SelectDefaultPicker/SelectDefaultPicker.test.d.ts +1 -0
- package/dist/types/src/Select/components/SelectInternalPicker/SelectInternalPicker.test.d.ts +1 -0
- package/dist/types/src/StatusLabel/StatusLabel.test.d.ts +1 -0
- package/dist/types/src/Switch/Switch.test.d.ts +1 -0
- package/dist/types/src/Switch/components/BaseSwitch/BaseSwitch.test.d.ts +1 -0
- package/dist/types/src/Text/Text.test.d.ts +1 -0
- package/dist/types/src/TextList/TextList.test.d.ts +1 -0
- package/dist/types/src/ThumbnailList/ThumbnailList.test.d.ts +1 -0
- package/dist/types/src/Toast/Toast.test.d.ts +1 -0
- package/dist/types/src/Typography/Typography.test.d.ts +1 -0
- package/dist/types/src/hooks/useAtlantisI18n/useAtlantisI18n.test.d.ts +1 -0
- package/dist/types/src/utils/meta/meta.test.d.ts +1 -0
- package/package.json +19 -11
- package/src/Button/Button.test.tsx +6 -2
- package/src/ContentOverlay/hooks/useViewLayoutHeight.test.ts +3 -3
- package/src/Divider/Divider.stories.tsx +1 -1
- package/src/Flex/Flex.test.tsx +1 -1
- package/src/Form/Form.test.tsx +3 -1
- package/src/FormField/FormField.test.tsx +5 -1
- package/src/Heading/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/InputDate/InputDate.test.tsx +7 -1
- package/src/InputText/InputText.test.tsx +2 -1
- package/src/InputTime/InputTime.test.tsx +7 -1
- package/src/Select/Select.test.tsx +1 -1
- package/src/StatusLabel/__snapshots__/StatusLabel.test.tsx.snap +8 -8
- package/src/Text/__snapshots__/Text.test.tsx.snap +2 -2
- package/src/ThumbnailList/__snapshots__/ThumbnailList.test.tsx.snap +1 -1
- package/src/Typography/__snapshots__/Typography.test.tsx.snap +4 -4
|
@@ -0,0 +1,652 @@
|
|
|
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, { useEffect } from "react";
|
|
11
|
+
import { fireEvent, render, renderHook, screen, waitFor, } from "@testing-library/react-native";
|
|
12
|
+
import { Button, Platform } from "react-native";
|
|
13
|
+
import { FormProvider, useForm } from "react-hook-form";
|
|
14
|
+
import { InputText } from "./InputText";
|
|
15
|
+
import { InputAccessoriesProvider } from "./context";
|
|
16
|
+
import { useCommonInputStyles } from "../InputFieldWrapper";
|
|
17
|
+
const MockInputFieldWrapper = jest.fn();
|
|
18
|
+
jest.mock("../InputFieldWrapper", () => (Object.assign(Object.assign({}, jest.requireActual("../InputFieldWrapper")), { InputFieldWrapper: function Mock(props) {
|
|
19
|
+
MockInputFieldWrapper(props);
|
|
20
|
+
return jest.requireActual("../InputFieldWrapper").InputFieldWrapper(props);
|
|
21
|
+
} })));
|
|
22
|
+
const mockLabel = { label: "$" };
|
|
23
|
+
const android = "android";
|
|
24
|
+
const ios = "ios";
|
|
25
|
+
const platforms = [
|
|
26
|
+
["ios", "done"],
|
|
27
|
+
["android", "next"],
|
|
28
|
+
];
|
|
29
|
+
function renderInputText(props) {
|
|
30
|
+
return render(React.createElement(InputText, Object.assign({}, props)));
|
|
31
|
+
}
|
|
32
|
+
const clearInput = "Clear input";
|
|
33
|
+
let commonInputStyles;
|
|
34
|
+
beforeAll(() => {
|
|
35
|
+
const commonInputStylesHook = renderHook(() => useCommonInputStyles());
|
|
36
|
+
commonInputStyles = commonInputStylesHook.result.current;
|
|
37
|
+
});
|
|
38
|
+
// eslint-disable-next-line max-statements
|
|
39
|
+
describe("InputText", () => {
|
|
40
|
+
describe("InputFieldWrapper gets the expected props", () => {
|
|
41
|
+
it("renders an invalid InputText", () => {
|
|
42
|
+
const props = { invalid: true };
|
|
43
|
+
renderInputText(props);
|
|
44
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
|
|
45
|
+
});
|
|
46
|
+
it("renders an invalid InputText with non-empty string", () => {
|
|
47
|
+
const props = { invalid: "Always invalid" };
|
|
48
|
+
renderInputText(props);
|
|
49
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
|
|
50
|
+
});
|
|
51
|
+
it("renders a valid InputText with empty string", () => {
|
|
52
|
+
const props = { invalid: "" };
|
|
53
|
+
renderInputText(props);
|
|
54
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
|
|
55
|
+
});
|
|
56
|
+
it("renders a disabled InputText", () => {
|
|
57
|
+
const props = { disabled: true };
|
|
58
|
+
renderInputText(props);
|
|
59
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
|
|
60
|
+
});
|
|
61
|
+
describe("readonly", () => {
|
|
62
|
+
it.each([[false], [true]])("sets the readOnly to %s", expected => {
|
|
63
|
+
const { getByTestId } = renderInputText({
|
|
64
|
+
testID: "InputText",
|
|
65
|
+
readonly: expected,
|
|
66
|
+
});
|
|
67
|
+
expect(getByTestId("InputText").props.readOnly).toBe(expected);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it("renders a InputText with placeholder", () => {
|
|
71
|
+
const props = { placeholder: "Foobar" };
|
|
72
|
+
renderInputText(props);
|
|
73
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining(props));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
it("renders a InputText with defaultValue", () => {
|
|
77
|
+
const defaultValue = "Default Foobar";
|
|
78
|
+
const { getByDisplayValue } = renderInputText({
|
|
79
|
+
defaultValue,
|
|
80
|
+
});
|
|
81
|
+
expect(getByDisplayValue(defaultValue)).toBeTruthy();
|
|
82
|
+
});
|
|
83
|
+
it("renders a InputText with autoCompleteType", () => {
|
|
84
|
+
const { getByTestId } = renderInputText({
|
|
85
|
+
testID: "InputText",
|
|
86
|
+
autoComplete: "name",
|
|
87
|
+
});
|
|
88
|
+
expect(getByTestId("InputText").props.autoComplete).toBe("name");
|
|
89
|
+
});
|
|
90
|
+
describe("autoCorrect prop", () => {
|
|
91
|
+
it("defaults the autoCorrect prop to undefined", () => {
|
|
92
|
+
const { getByTestId } = renderInputText({ testID: "Text" });
|
|
93
|
+
expect(getByTestId("Text").props.autoCorrect).toEqual(undefined);
|
|
94
|
+
});
|
|
95
|
+
describe("setting the autoCorrect field", () => {
|
|
96
|
+
it("allows setting the field when a value is passed in", () => {
|
|
97
|
+
const { getByTestId } = renderInputText({
|
|
98
|
+
testID: "Text",
|
|
99
|
+
autoCorrect: true,
|
|
100
|
+
});
|
|
101
|
+
expect(getByTestId("Text").props.autoCorrect).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("Suffix and Prefix", () => {
|
|
106
|
+
it("renders a prefix icon when specified", () => {
|
|
107
|
+
const { getByTestId } = renderInputText({ prefix: { icon: "invoice" } });
|
|
108
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
109
|
+
});
|
|
110
|
+
it("renders a suffix icon when specified", () => {
|
|
111
|
+
const { getByTestId } = renderInputText({ suffix: { icon: "invoice" } });
|
|
112
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("when given a value", () => {
|
|
116
|
+
const value = "Foobar";
|
|
117
|
+
it("renders the InputText with the value", () => {
|
|
118
|
+
const { getByDisplayValue } = renderInputText({ value: value });
|
|
119
|
+
expect(getByDisplayValue(value)).toBeTruthy();
|
|
120
|
+
});
|
|
121
|
+
it("renders a prefix label", () => {
|
|
122
|
+
const { getByText } = renderInputText({
|
|
123
|
+
prefix: mockLabel,
|
|
124
|
+
value: value,
|
|
125
|
+
});
|
|
126
|
+
expect(getByText(mockLabel.label)).toBeTruthy();
|
|
127
|
+
});
|
|
128
|
+
it("renders a suffix label", () => {
|
|
129
|
+
const { getByText } = renderInputText({
|
|
130
|
+
suffix: mockLabel,
|
|
131
|
+
value: value,
|
|
132
|
+
});
|
|
133
|
+
expect(getByText(mockLabel.label)).toBeTruthy();
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe("when no value", () => {
|
|
137
|
+
it("does not render a prefix label", () => {
|
|
138
|
+
const { queryByText } = renderInputText({ prefix: mockLabel });
|
|
139
|
+
expect(queryByText(mockLabel.label)).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
it("does not render a suffix label", () => {
|
|
142
|
+
const { queryByText } = renderInputText({ suffix: mockLabel });
|
|
143
|
+
expect(queryByText(mockLabel.label)).toBeNull();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("Callbacks", () => {
|
|
147
|
+
it("calls onChangeText callback on input", () => {
|
|
148
|
+
const changeCallback = jest.fn();
|
|
149
|
+
const a11yLabel = "Test InputText";
|
|
150
|
+
const { getByLabelText } = render(React.createElement(InputText, { onChangeText: changeCallback, value: "Initial value", accessibilityLabel: a11yLabel }));
|
|
151
|
+
fireEvent.changeText(getByLabelText(a11yLabel), "New value");
|
|
152
|
+
expect(changeCallback).toHaveBeenCalledWith("New value");
|
|
153
|
+
});
|
|
154
|
+
describe("onBlur", () => {
|
|
155
|
+
it("calls onBlur callback on input", () => {
|
|
156
|
+
const blurCallback = jest.fn();
|
|
157
|
+
const a11yLabel = "Test InputText";
|
|
158
|
+
const { getByLabelText } = render(React.createElement(InputText, { onBlur: blurCallback, value: "Initial value", accessibilityLabel: a11yLabel }));
|
|
159
|
+
fireEvent(getByLabelText(a11yLabel), "blur");
|
|
160
|
+
expect(blurCallback).toHaveBeenCalledTimes(1);
|
|
161
|
+
});
|
|
162
|
+
describe("when whitespace is present at the start or end of the value", () => {
|
|
163
|
+
const value = " Hello World ";
|
|
164
|
+
it("trims whitespace", () => {
|
|
165
|
+
const onChangeHandler = jest.fn();
|
|
166
|
+
const a11yLabel = "Test InputText";
|
|
167
|
+
const { getByLabelText } = render(React.createElement(InputText, { value: value, accessibilityLabel: a11yLabel, onChangeText: onChangeHandler }));
|
|
168
|
+
fireEvent(getByLabelText(a11yLabel), "blur");
|
|
169
|
+
expect(onChangeHandler).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(onChangeHandler).toHaveBeenLastCalledWith("Hello World");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe("when whitespace is not present at the start or end of the value", () => {
|
|
174
|
+
const value = "Hello World";
|
|
175
|
+
it("does not invoke the onChangeText callback", () => {
|
|
176
|
+
const onChangeHandler = jest.fn();
|
|
177
|
+
const a11yLabel = "Test InputText";
|
|
178
|
+
const { getByLabelText } = render(React.createElement(InputText, { value: value, accessibilityLabel: a11yLabel, onChangeText: onChangeHandler }));
|
|
179
|
+
fireEvent(getByLabelText(a11yLabel), "blur");
|
|
180
|
+
expect(onChangeHandler).toHaveBeenCalledTimes(0);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it("calls onFocus callback on focus", () => {
|
|
185
|
+
const focusCallback = jest.fn();
|
|
186
|
+
const a11yLabel = "Test InputText";
|
|
187
|
+
const { getByLabelText } = render(React.createElement(InputText, { onFocus: focusCallback, accessibilityLabel: a11yLabel }));
|
|
188
|
+
fireEvent(getByLabelText(a11yLabel), "onFocus");
|
|
189
|
+
expect(focusCallback).toHaveBeenCalled();
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe("Validations", () => {
|
|
193
|
+
it("calls validations on blur", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
|
+
const validationMock = jest.fn();
|
|
195
|
+
const a11yLabel = "Test InputText";
|
|
196
|
+
const { getByLabelText } = render(React.createElement(InputText, { value: "Initial value", accessibilityLabel: a11yLabel, validations: { validate: validationMock } }));
|
|
197
|
+
yield waitFor(() => {
|
|
198
|
+
fireEvent(getByLabelText(a11yLabel), "blur");
|
|
199
|
+
});
|
|
200
|
+
expect(validationMock).toHaveBeenCalled();
|
|
201
|
+
}));
|
|
202
|
+
it("renders validation messages after blur", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
+
const a11yLabel = "Test InputText";
|
|
204
|
+
const { getByLabelText, getByText } = render(React.createElement(InputText, { accessibilityLabel: a11yLabel, validations: { required: { value: true, message: "Foobar" } } }));
|
|
205
|
+
yield waitFor(() => {
|
|
206
|
+
fireEvent(getByLabelText(a11yLabel), "blur");
|
|
207
|
+
});
|
|
208
|
+
expect(getByText("Foobar", { includeHiddenElements: true })).toBeDefined();
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
describe("accessibilityLabel", () => {
|
|
212
|
+
it("uses accessibilityLabel if specified", () => {
|
|
213
|
+
const changeCallback = jest.fn();
|
|
214
|
+
const { getByLabelText } = render(React.createElement(InputText, { onChangeText: changeCallback, value: "", placeholder: "placeholder", accessibilityLabel: "accessibilityLabel" }));
|
|
215
|
+
expect(getByLabelText("accessibilityLabel")).toBeTruthy();
|
|
216
|
+
});
|
|
217
|
+
it("uses placeholder if unspecified", () => {
|
|
218
|
+
const changeCallback = jest.fn();
|
|
219
|
+
const { getByLabelText } = render(React.createElement(InputText, { onChangeText: changeCallback, value: "", placeholder: "placeholder" }));
|
|
220
|
+
expect(getByLabelText("placeholder")).toBeTruthy();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
describe("clearable button", () => {
|
|
224
|
+
function setup({ clearable, value, accessibilityLabel, onChangeText, disabled, }) {
|
|
225
|
+
return render(React.createElement(InputText, { clearable: clearable, value: value, placeholder: "placeholder", accessibilityLabel: accessibilityLabel, onChangeText: onChangeText, disabled: disabled }));
|
|
226
|
+
}
|
|
227
|
+
describe("clearable set to always", () => {
|
|
228
|
+
it("renders the clear button when there is a value", () => {
|
|
229
|
+
const { getByLabelText } = setup({
|
|
230
|
+
clearable: "always",
|
|
231
|
+
value: "test value",
|
|
232
|
+
});
|
|
233
|
+
const clearButton = getByLabelText(clearInput);
|
|
234
|
+
expect(clearButton).toBeDefined();
|
|
235
|
+
});
|
|
236
|
+
it("doesn't render the clear button if there is no value", () => {
|
|
237
|
+
const { queryByLabelText } = setup({ clearable: "always", value: "" });
|
|
238
|
+
const clearButton = queryByLabelText(clearInput);
|
|
239
|
+
expect(clearButton).toBeNull();
|
|
240
|
+
});
|
|
241
|
+
it("renders the clear button when there is a value and you are focused", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
+
const { getByLabelText } = setup({
|
|
243
|
+
clearable: "always",
|
|
244
|
+
value: "test value",
|
|
245
|
+
accessibilityLabel: "clearableTest",
|
|
246
|
+
});
|
|
247
|
+
yield fireEvent(getByLabelText("clearableTest"), "focus");
|
|
248
|
+
const clearButton = getByLabelText(clearInput);
|
|
249
|
+
expect(clearButton).toBeDefined();
|
|
250
|
+
}));
|
|
251
|
+
});
|
|
252
|
+
describe("clearable set to when editing", () => {
|
|
253
|
+
it("renders the clear button when there is a value and it is being edited", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
254
|
+
const { getByLabelText } = setup({
|
|
255
|
+
clearable: "while-editing",
|
|
256
|
+
value: "Test Input",
|
|
257
|
+
accessibilityLabel: "clearableTest",
|
|
258
|
+
});
|
|
259
|
+
yield fireEvent(getByLabelText("clearableTest"), "focus");
|
|
260
|
+
const clearButton = getByLabelText(clearInput);
|
|
261
|
+
expect(clearButton).toBeDefined();
|
|
262
|
+
}));
|
|
263
|
+
it("doesn't render the clear button if the user isn't editing", () => {
|
|
264
|
+
const { queryByLabelText } = setup({
|
|
265
|
+
clearable: "while-editing",
|
|
266
|
+
value: "Test value",
|
|
267
|
+
});
|
|
268
|
+
const clearButton = queryByLabelText(clearInput);
|
|
269
|
+
expect(clearButton).toBeNull();
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
describe("clearable set to never", () => {
|
|
273
|
+
it("shouldn't show the button when it is being edited", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
+
const { getByLabelText, queryByLabelText } = setup({
|
|
275
|
+
clearable: "never",
|
|
276
|
+
value: "Test Input",
|
|
277
|
+
accessibilityLabel: "clearableTest",
|
|
278
|
+
});
|
|
279
|
+
yield fireEvent(getByLabelText("clearableTest"), "focus");
|
|
280
|
+
const clearButton = queryByLabelText(clearInput);
|
|
281
|
+
expect(clearButton).toBeNull();
|
|
282
|
+
}));
|
|
283
|
+
it("shouldn't show the clear button when the user is not editing", () => {
|
|
284
|
+
const { queryByLabelText } = setup({
|
|
285
|
+
clearable: "never",
|
|
286
|
+
value: "Test Input",
|
|
287
|
+
accessibilityLabel: "clearableTest",
|
|
288
|
+
});
|
|
289
|
+
const clearButton = queryByLabelText(clearInput);
|
|
290
|
+
expect(clearButton).toBeNull();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
it("should clear the value when the clear button is pressed", () => {
|
|
294
|
+
const onChangeHandler = jest.fn();
|
|
295
|
+
const { getByLabelText } = setup({
|
|
296
|
+
clearable: "always",
|
|
297
|
+
value: "Test Input",
|
|
298
|
+
onChangeText: onChangeHandler,
|
|
299
|
+
});
|
|
300
|
+
const clearButton = getByLabelText(clearInput);
|
|
301
|
+
fireEvent(clearButton, "press");
|
|
302
|
+
expect(onChangeHandler).toHaveBeenCalledWith("");
|
|
303
|
+
});
|
|
304
|
+
it("shouldn't render the clear button if the input is disabled", () => {
|
|
305
|
+
const { queryByLabelText } = setup({
|
|
306
|
+
clearable: "always",
|
|
307
|
+
value: "Test value",
|
|
308
|
+
accessibilityLabel: "clearableTest",
|
|
309
|
+
disabled: true,
|
|
310
|
+
});
|
|
311
|
+
const clearButton = queryByLabelText(clearInput);
|
|
312
|
+
expect(clearButton).toBeNull();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
describe.each(platforms)("%s returnKeyLabel", (platform, expectedReturnKeyType) => {
|
|
316
|
+
it("doesn't set a returnKeyType for multiline inputs", () => {
|
|
317
|
+
Platform.OS = platform;
|
|
318
|
+
const { getByTestId } = renderInputText({
|
|
319
|
+
multiline: true,
|
|
320
|
+
testID: "multiline",
|
|
321
|
+
});
|
|
322
|
+
const rnTextInput = getByTestId("multiline");
|
|
323
|
+
expect(rnTextInput.props.returnKeyType).toBeUndefined();
|
|
324
|
+
});
|
|
325
|
+
it("sets the correct returnKeyType when in the InputAccessoryContext", () => {
|
|
326
|
+
Platform.OS = platform;
|
|
327
|
+
const { getByTestId } = render(React.createElement(InputAccessoriesProvider, null,
|
|
328
|
+
React.createElement(InputText, { testID: "returnKeyType" })));
|
|
329
|
+
const rnTextInput = getByTestId("returnKeyType");
|
|
330
|
+
expect(rnTextInput.props.returnKeyType).toBe(expectedReturnKeyType);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
describe("Style", () => {
|
|
334
|
+
it("displays default text styles", () => {
|
|
335
|
+
const defaultValue = "Default Foobar";
|
|
336
|
+
const { getByDisplayValue } = renderInputText({ defaultValue });
|
|
337
|
+
const textInput = getByDisplayValue(defaultValue);
|
|
338
|
+
expect(textInput.props.style).toContainEqual(Object.assign({}, commonInputStyles.input));
|
|
339
|
+
});
|
|
340
|
+
it("displays overriden text styles", () => {
|
|
341
|
+
const defaultValue = "Default Foobar";
|
|
342
|
+
const styleOverride = {
|
|
343
|
+
inputText: {
|
|
344
|
+
fontFamily: "inter-extrabold",
|
|
345
|
+
fontSize: 50,
|
|
346
|
+
lineHeight: 60,
|
|
347
|
+
letterSpacing: 10,
|
|
348
|
+
color: "purple",
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
const { getByDisplayValue } = renderInputText({
|
|
352
|
+
defaultValue,
|
|
353
|
+
styleOverride,
|
|
354
|
+
});
|
|
355
|
+
const textInput = getByDisplayValue(defaultValue);
|
|
356
|
+
const flattenedStyle = textInput.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
357
|
+
expect(styleOverride.inputText.fontFamily).toEqual(flattenedStyle.fontFamily);
|
|
358
|
+
expect(styleOverride.inputText.fontSize).toEqual(flattenedStyle.fontSize);
|
|
359
|
+
expect(styleOverride.inputText.lineHeight).toEqual(flattenedStyle.lineHeight);
|
|
360
|
+
expect(styleOverride.inputText.letterSpacing).toEqual(flattenedStyle.letterSpacing);
|
|
361
|
+
expect(styleOverride.inputText.color).toEqual(flattenedStyle.color);
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
describe("showMiniLabel", () => {
|
|
365
|
+
it("defaults to true", () => {
|
|
366
|
+
const props = { placeholder: "placeholder", value: "value" };
|
|
367
|
+
renderInputText(props);
|
|
368
|
+
expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
|
|
369
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
|
|
370
|
+
placeholderMode: "mini",
|
|
371
|
+
}));
|
|
372
|
+
});
|
|
373
|
+
describe("when true", () => {
|
|
374
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
375
|
+
const props = { showMiniLabel: true, placeholder: "placeholder" };
|
|
376
|
+
renderInputText(props);
|
|
377
|
+
expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
|
|
378
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
|
|
379
|
+
placeholderMode: "normal",
|
|
380
|
+
}));
|
|
381
|
+
});
|
|
382
|
+
it("renders the placeholder as a mini label when the input has a value", () => {
|
|
383
|
+
const props = {
|
|
384
|
+
showMiniLabel: true,
|
|
385
|
+
placeholder: "placeholder",
|
|
386
|
+
value: "value",
|
|
387
|
+
};
|
|
388
|
+
renderInputText(props);
|
|
389
|
+
expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
|
|
390
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
|
|
391
|
+
placeholderMode: "mini",
|
|
392
|
+
}));
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
describe("when false", () => {
|
|
396
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
397
|
+
const props = { showMiniLabel: false, placeholder: "placeholder" };
|
|
398
|
+
renderInputText(props);
|
|
399
|
+
expect(screen.getByText("placeholder", { includeHiddenElements: true })).toBeDefined();
|
|
400
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(expect.objectContaining({
|
|
401
|
+
placeholderMode: "normal",
|
|
402
|
+
}));
|
|
403
|
+
});
|
|
404
|
+
it("does not render the placeholder when the input has a value", () => {
|
|
405
|
+
const props = {
|
|
406
|
+
showMiniLabel: false,
|
|
407
|
+
placeholder: "placeholder",
|
|
408
|
+
value: "value",
|
|
409
|
+
};
|
|
410
|
+
renderInputText(props);
|
|
411
|
+
expect(screen.queryByText("placeholder", { includeHiddenElements: true })).toBeNull();
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
describe("with FormProvider", () => {
|
|
416
|
+
const mockOnSubmit = jest.fn();
|
|
417
|
+
const inputName = "testInput";
|
|
418
|
+
const inputAccessibilityLabel = "Test Input";
|
|
419
|
+
const saveButtonText = "Save";
|
|
420
|
+
function FormWithProvider({ defaultValue, }) {
|
|
421
|
+
const formMethods = useForm();
|
|
422
|
+
return (React.createElement(FormProvider, Object.assign({}, formMethods),
|
|
423
|
+
React.createElement(InputText, { name: inputName, defaultValue: defaultValue, accessibilityLabel: inputAccessibilityLabel }),
|
|
424
|
+
React.createElement(Button, { onPress: formMethods.handleSubmit(values => mockOnSubmit(values)), title: saveButtonText, accessibilityLabel: saveButtonText })));
|
|
425
|
+
}
|
|
426
|
+
beforeEach(() => {
|
|
427
|
+
mockOnSubmit.mockClear();
|
|
428
|
+
});
|
|
429
|
+
describe("defaultValue prop sets form value", () => {
|
|
430
|
+
it("sets form value to string when defaultValue is provided", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
431
|
+
const testValue = "test value";
|
|
432
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultValue: testValue }));
|
|
433
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
434
|
+
yield waitFor(() => {
|
|
435
|
+
fireEvent.press(saveButton);
|
|
436
|
+
});
|
|
437
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
438
|
+
[inputName]: testValue,
|
|
439
|
+
});
|
|
440
|
+
}));
|
|
441
|
+
it("sets form value to undefined when defaultValue is undefined", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
442
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, null));
|
|
443
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
444
|
+
yield waitFor(() => {
|
|
445
|
+
fireEvent.press(saveButton);
|
|
446
|
+
});
|
|
447
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
448
|
+
[inputName]: undefined,
|
|
449
|
+
});
|
|
450
|
+
}));
|
|
451
|
+
it("sets form value to undefined when defaultValue is empty string", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
452
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultValue: "" }));
|
|
453
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
454
|
+
yield waitFor(() => {
|
|
455
|
+
fireEvent.press(saveButton);
|
|
456
|
+
});
|
|
457
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
458
|
+
[inputName]: undefined,
|
|
459
|
+
});
|
|
460
|
+
}));
|
|
461
|
+
});
|
|
462
|
+
describe("input value updates form value", () => {
|
|
463
|
+
it("updates form value when input text is changed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
464
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultValue: "initial" }));
|
|
465
|
+
const input = getByLabelText(inputAccessibilityLabel);
|
|
466
|
+
fireEvent.changeText(input, "new value");
|
|
467
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
468
|
+
yield waitFor(() => {
|
|
469
|
+
fireEvent.press(saveButton);
|
|
470
|
+
});
|
|
471
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
472
|
+
[inputName]: "new value",
|
|
473
|
+
});
|
|
474
|
+
}));
|
|
475
|
+
it("preserves defaultValue when input is not interacted with", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
476
|
+
const testValue = "preserved value";
|
|
477
|
+
const { getByLabelText } = render(React.createElement(FormWithProvider, { defaultValue: testValue }));
|
|
478
|
+
const saveButton = getByLabelText(saveButtonText);
|
|
479
|
+
yield waitFor(() => {
|
|
480
|
+
fireEvent.press(saveButton);
|
|
481
|
+
});
|
|
482
|
+
expect(mockOnSubmit).toHaveBeenCalledWith({
|
|
483
|
+
[inputName]: testValue,
|
|
484
|
+
});
|
|
485
|
+
}));
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
describe("Transform", () => {
|
|
490
|
+
const base64Transformer = {
|
|
491
|
+
input: (a) => {
|
|
492
|
+
if (!a)
|
|
493
|
+
return a;
|
|
494
|
+
return atob(a);
|
|
495
|
+
},
|
|
496
|
+
output: (a) => {
|
|
497
|
+
if (!a)
|
|
498
|
+
return a;
|
|
499
|
+
return btoa(a);
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
describe("when working with controlled components", () => {
|
|
503
|
+
it("form state gets corect value during change", () => {
|
|
504
|
+
const a11yLabel = "Test InputText";
|
|
505
|
+
const onFormValueUpdate = jest.fn();
|
|
506
|
+
const { getByLabelText } = renderInputText({
|
|
507
|
+
onChangeText: onFormValueUpdate,
|
|
508
|
+
accessibilityLabel: a11yLabel,
|
|
509
|
+
transform: base64Transformer,
|
|
510
|
+
});
|
|
511
|
+
const input = getByLabelText(a11yLabel);
|
|
512
|
+
fireEvent.changeText(input, "New value ");
|
|
513
|
+
expect(onFormValueUpdate).toHaveBeenCalledWith("TmV3IHZhbHVlIA==");
|
|
514
|
+
});
|
|
515
|
+
it("form state gets corect value on blur", () => {
|
|
516
|
+
const a11yLabel = "Test InputText";
|
|
517
|
+
const onFormValueUpdate = jest.fn();
|
|
518
|
+
const { getByLabelText } = renderInputText({
|
|
519
|
+
onChangeText: onFormValueUpdate,
|
|
520
|
+
accessibilityLabel: a11yLabel,
|
|
521
|
+
transform: base64Transformer,
|
|
522
|
+
});
|
|
523
|
+
const input = getByLabelText(a11yLabel);
|
|
524
|
+
fireEvent.changeText(input, "New value ");
|
|
525
|
+
fireEvent(input, "blur");
|
|
526
|
+
expect(onFormValueUpdate).toHaveBeenCalledTimes(2);
|
|
527
|
+
expect(onFormValueUpdate).toHaveBeenLastCalledWith("TmV3IHZhbHVl");
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
describe("When working with uncontrolled components", () => {
|
|
531
|
+
const onFormValueUpdate = jest.fn();
|
|
532
|
+
beforeEach(jest.clearAllMocks);
|
|
533
|
+
function FormWrapper({ children }) {
|
|
534
|
+
const form = useForm();
|
|
535
|
+
useEffect(() => {
|
|
536
|
+
return form.watch(value => {
|
|
537
|
+
onFormValueUpdate(value);
|
|
538
|
+
}).unsubscribe;
|
|
539
|
+
}, [form]);
|
|
540
|
+
return React.createElement(FormProvider, Object.assign({}, form), children);
|
|
541
|
+
}
|
|
542
|
+
it("change handler gets corect value during change", () => {
|
|
543
|
+
const a11yLabel = "Test InputText";
|
|
544
|
+
const { getByLabelText } = render(React.createElement(FormWrapper, null,
|
|
545
|
+
React.createElement(InputText, { name: "test", accessibilityLabel: a11yLabel, defaultValue: "", transform: base64Transformer })));
|
|
546
|
+
const input = getByLabelText(a11yLabel);
|
|
547
|
+
fireEvent.changeText(input, "New value ");
|
|
548
|
+
expect(onFormValueUpdate).toHaveBeenCalledWith({
|
|
549
|
+
test: "TmV3IHZhbHVlIA==",
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
it("change handler gets corect value on blur", () => {
|
|
553
|
+
const a11yLabel = "Test InputText";
|
|
554
|
+
const { getByLabelText } = render(React.createElement(FormWrapper, null,
|
|
555
|
+
React.createElement(InputText, { name: "test", accessibilityLabel: a11yLabel, transform: base64Transformer })));
|
|
556
|
+
const input = getByLabelText(a11yLabel);
|
|
557
|
+
fireEvent.changeText(input, "New value ");
|
|
558
|
+
fireEvent(input, "blur");
|
|
559
|
+
expect(onFormValueUpdate).toHaveBeenCalledTimes(2);
|
|
560
|
+
expect(onFormValueUpdate).toHaveBeenLastCalledWith({
|
|
561
|
+
test: "TmV3IHZhbHVl",
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
describe("Bottom Sheet keyboard handling integration", () => {
|
|
566
|
+
beforeEach(() => {
|
|
567
|
+
jest.clearAllMocks();
|
|
568
|
+
});
|
|
569
|
+
// eslint-disable-next-line max-statements
|
|
570
|
+
it("updates animatedKeyboardState on focus when inside ContentOverlay", () => {
|
|
571
|
+
const mockSet = jest.fn();
|
|
572
|
+
const mockGet = jest.fn(() => ({ target: undefined }));
|
|
573
|
+
const mockKeyboardState = {
|
|
574
|
+
value: { target: undefined },
|
|
575
|
+
set: mockSet,
|
|
576
|
+
get: mockGet,
|
|
577
|
+
};
|
|
578
|
+
const mockTextInputNodesRef = { current: new Set() };
|
|
579
|
+
// Mock the useBottomSheetInternal hook to simulate being inside ContentOverlay
|
|
580
|
+
jest
|
|
581
|
+
.spyOn(require("@gorhom/bottom-sheet"), "useBottomSheetInternal")
|
|
582
|
+
.mockReturnValue({
|
|
583
|
+
animatedKeyboardState: mockKeyboardState,
|
|
584
|
+
textInputNodesRef: mockTextInputNodesRef,
|
|
585
|
+
});
|
|
586
|
+
const a11yLabel = "Test InputText";
|
|
587
|
+
const { getByLabelText } = render(React.createElement(InputText, { accessibilityLabel: a11yLabel }));
|
|
588
|
+
const input = getByLabelText(a11yLabel);
|
|
589
|
+
fireEvent(input, "onFocus", {
|
|
590
|
+
nativeEvent: { target: 123 },
|
|
591
|
+
});
|
|
592
|
+
expect(mockSet).toHaveBeenCalledWith(expect.any(Function));
|
|
593
|
+
// Verify the set callback updates the state correctly
|
|
594
|
+
const setCallback = mockSet.mock.calls[0][0];
|
|
595
|
+
const newState = setCallback({ target: undefined });
|
|
596
|
+
expect(newState).toEqual({ target: 123 });
|
|
597
|
+
});
|
|
598
|
+
// eslint-disable-next-line max-statements
|
|
599
|
+
it("consumer onFocus and onBlur callbacks still fire when inside ContentOverlay", () => {
|
|
600
|
+
const focusCallback = jest.fn();
|
|
601
|
+
const blurCallback = jest.fn();
|
|
602
|
+
const mockSet = jest.fn();
|
|
603
|
+
const mockGet = jest.fn(() => ({ target: undefined }));
|
|
604
|
+
const mockKeyboardState = {
|
|
605
|
+
value: { target: undefined },
|
|
606
|
+
set: mockSet,
|
|
607
|
+
get: mockGet,
|
|
608
|
+
};
|
|
609
|
+
const mockTextInputNodesRef = { current: new Set() };
|
|
610
|
+
jest
|
|
611
|
+
.spyOn(require("@gorhom/bottom-sheet"), "useBottomSheetInternal")
|
|
612
|
+
.mockReturnValue({
|
|
613
|
+
animatedKeyboardState: mockKeyboardState,
|
|
614
|
+
textInputNodesRef: mockTextInputNodesRef,
|
|
615
|
+
});
|
|
616
|
+
const a11yLabel = "Test InputText";
|
|
617
|
+
const { getByLabelText } = render(React.createElement(InputText, { onFocus: focusCallback, onBlur: blurCallback, accessibilityLabel: a11yLabel }));
|
|
618
|
+
const input = getByLabelText(a11yLabel);
|
|
619
|
+
fireEvent(input, "onFocus", {
|
|
620
|
+
nativeEvent: { target: 123 },
|
|
621
|
+
});
|
|
622
|
+
expect(focusCallback).toHaveBeenCalled();
|
|
623
|
+
fireEvent(input, "onBlur", {
|
|
624
|
+
nativeEvent: { target: 123 },
|
|
625
|
+
});
|
|
626
|
+
expect(blurCallback).toHaveBeenCalled();
|
|
627
|
+
});
|
|
628
|
+
it("handles value changes when inside ContentOverlay", () => {
|
|
629
|
+
const mockSet = jest.fn();
|
|
630
|
+
const mockGet = jest.fn(() => ({ target: undefined }));
|
|
631
|
+
const mockKeyboardState = {
|
|
632
|
+
value: { target: undefined },
|
|
633
|
+
set: mockSet,
|
|
634
|
+
get: mockGet,
|
|
635
|
+
};
|
|
636
|
+
const mockTextInputNodesRef = { current: new Set() };
|
|
637
|
+
const changeCallback = jest.fn();
|
|
638
|
+
jest
|
|
639
|
+
.spyOn(require("@gorhom/bottom-sheet"), "useBottomSheetInternal")
|
|
640
|
+
.mockReturnValue({
|
|
641
|
+
animatedKeyboardState: mockKeyboardState,
|
|
642
|
+
textInputNodesRef: mockTextInputNodesRef,
|
|
643
|
+
});
|
|
644
|
+
const a11yLabel = "Test InputText";
|
|
645
|
+
const { getByLabelText } = render(React.createElement(InputText, { onChangeText: changeCallback, accessibilityLabel: a11yLabel }));
|
|
646
|
+
const input = getByLabelText(a11yLabel);
|
|
647
|
+
fireEvent.changeText(input, "New value");
|
|
648
|
+
// Value changes should work normally
|
|
649
|
+
expect(changeCallback).toHaveBeenCalledWith("New value");
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
});
|