@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,279 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render, renderHook, screen, } from "@testing-library/react-native";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
import { InputFieldWrapper, useCommonInputStyles } from ".";
|
|
5
|
+
import { useStyles } from "./InputFieldWrapper.style";
|
|
6
|
+
import { INPUT_FIELD_WRAPPER_GLIMMERS_TEST_ID, INPUT_FIELD_WRAPPER_SPINNER_TEST_ID, } from "./InputFieldWrapper";
|
|
7
|
+
import { useTypographyStyles } from "../Typography";
|
|
8
|
+
const mockLabel = { label: "$" };
|
|
9
|
+
let styles;
|
|
10
|
+
let commonInputStyles;
|
|
11
|
+
let typographyStyles;
|
|
12
|
+
beforeAll(() => {
|
|
13
|
+
const stylesHook = renderHook(() => useStyles());
|
|
14
|
+
const commonInputStylesHook = renderHook(() => useCommonInputStyles());
|
|
15
|
+
const typographyStylesHook = renderHook(() => useTypographyStyles());
|
|
16
|
+
styles = stylesHook.result.current;
|
|
17
|
+
commonInputStyles = commonInputStylesHook.result.current;
|
|
18
|
+
typographyStyles = typographyStylesHook.result.current;
|
|
19
|
+
});
|
|
20
|
+
function renderInputFieldWrapper(props) {
|
|
21
|
+
return render(React.createElement(InputFieldWrapper, Object.assign({}, props),
|
|
22
|
+
React.createElement(Text, null, "Test")));
|
|
23
|
+
}
|
|
24
|
+
function renderWithPrefixLabel(hasValue) {
|
|
25
|
+
return renderInputFieldWrapper({ prefix: mockLabel, hasValue });
|
|
26
|
+
}
|
|
27
|
+
function renderWithSuffixLabel(hasValue) {
|
|
28
|
+
return renderInputFieldWrapper({ suffix: mockLabel, hasValue });
|
|
29
|
+
}
|
|
30
|
+
const clearInput = "Clear input";
|
|
31
|
+
// eslint-disable-next-line max-statements
|
|
32
|
+
describe("InputFieldWrapper", () => {
|
|
33
|
+
it("renders an invalid InputFieldWrapper", () => {
|
|
34
|
+
const { getByTestId } = renderInputFieldWrapper({ invalid: true });
|
|
35
|
+
expect(getByTestId("ATL-InputFieldWrapper").props.style).toContainEqual(styles.inputInvalid);
|
|
36
|
+
});
|
|
37
|
+
it("renders an invalid InputFieldWrapper with non-empty string", () => {
|
|
38
|
+
const invalid = "invalid string test";
|
|
39
|
+
const { getByText, getByTestId } = renderInputFieldWrapper({
|
|
40
|
+
invalid,
|
|
41
|
+
});
|
|
42
|
+
expect(getByTestId("ATL-InputFieldWrapper").props.style).toContainEqual(styles.inputInvalid);
|
|
43
|
+
expect(getByText(invalid, { includeHiddenElements: true })).toBeDefined();
|
|
44
|
+
});
|
|
45
|
+
it("renders a valid InputFieldWrapper with empty string", () => {
|
|
46
|
+
const { getByTestId } = renderInputFieldWrapper({ invalid: "" });
|
|
47
|
+
expect(getByTestId("ATL-InputFieldWrapper").props.style).not.toContainEqual(styles.inputInvalid);
|
|
48
|
+
});
|
|
49
|
+
it("renders a disabled InputFieldWrapper", () => {
|
|
50
|
+
const { getByTestId } = renderInputFieldWrapper({ disabled: true });
|
|
51
|
+
expect(getByTestId("ATL-InputFieldWrapper").props.style).toContainEqual({
|
|
52
|
+
backgroundColor: "hsl(0, 0%, 93%)",
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it("renders a InputFieldWrapper with placeholder", () => {
|
|
56
|
+
const placeholder = "test";
|
|
57
|
+
const { getByText } = renderInputFieldWrapper({ placeholder });
|
|
58
|
+
expect(getByText(placeholder, { includeHiddenElements: true })).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
it("renders a prefix icon when specified", () => {
|
|
61
|
+
const { getByTestId } = renderInputFieldWrapper({
|
|
62
|
+
prefix: { icon: "invoice" },
|
|
63
|
+
});
|
|
64
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
65
|
+
});
|
|
66
|
+
it("renders a suffix icon when specified", () => {
|
|
67
|
+
const { getByTestId } = renderInputFieldWrapper({
|
|
68
|
+
suffix: { icon: "invoice" },
|
|
69
|
+
});
|
|
70
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
describe("when hasValue", () => {
|
|
73
|
+
it("renders a prefix label", () => {
|
|
74
|
+
const { getByText } = renderWithPrefixLabel(true);
|
|
75
|
+
expect(getByText(mockLabel.label)).toBeDefined();
|
|
76
|
+
});
|
|
77
|
+
it("renders a suffix label", () => {
|
|
78
|
+
const { getByText } = renderWithSuffixLabel(true);
|
|
79
|
+
expect(getByText(mockLabel.label)).toBeDefined();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("when not hasValue", () => {
|
|
83
|
+
it("does not render a prefix label", () => {
|
|
84
|
+
const { queryByText } = renderWithPrefixLabel(false);
|
|
85
|
+
expect(queryByText(mockLabel.label)).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
it("does not render a suffix label", () => {
|
|
88
|
+
const { queryByText } = renderWithSuffixLabel(false);
|
|
89
|
+
expect(queryByText(mockLabel.label)).toBeNull();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe("ClearAction", () => {
|
|
93
|
+
it("renders the Clear Action Button when showClearAction is true", () => {
|
|
94
|
+
const { getByLabelText } = renderInputFieldWrapper({
|
|
95
|
+
showClearAction: true,
|
|
96
|
+
});
|
|
97
|
+
expect(getByLabelText(clearInput)).toBeDefined();
|
|
98
|
+
});
|
|
99
|
+
it("does not render the Clear Action Button when showClearAction is false", () => {
|
|
100
|
+
const { queryByLabelText } = renderInputFieldWrapper({
|
|
101
|
+
showClearAction: false,
|
|
102
|
+
});
|
|
103
|
+
expect(queryByLabelText(clearInput)).toBeNull();
|
|
104
|
+
});
|
|
105
|
+
it("calls onClear when the Clear Action button is pressed", () => {
|
|
106
|
+
const onClear = jest.fn();
|
|
107
|
+
const { getByLabelText } = renderInputFieldWrapper({
|
|
108
|
+
showClearAction: true,
|
|
109
|
+
onClear: onClear,
|
|
110
|
+
});
|
|
111
|
+
fireEvent(getByLabelText(clearInput), "press");
|
|
112
|
+
expect(onClear).toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("Custom Styling", () => {
|
|
116
|
+
it("has the default container styling when no style override is provided", () => {
|
|
117
|
+
const { getByTestId } = renderInputFieldWrapper({});
|
|
118
|
+
const container = getByTestId("ATL-InputFieldWrapper");
|
|
119
|
+
expect(container.props.style).toContainEqual(Object.assign(Object.assign({}, commonInputStyles.container), { flexDirection: "column" }));
|
|
120
|
+
});
|
|
121
|
+
it("shows the container style override when provided", () => {
|
|
122
|
+
const styleOverride = {
|
|
123
|
+
container: {
|
|
124
|
+
backgroundColor: "purple",
|
|
125
|
+
width: "50%",
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const { getByTestId } = renderInputFieldWrapper({
|
|
129
|
+
styleOverride,
|
|
130
|
+
});
|
|
131
|
+
const container = getByTestId("ATL-InputFieldWrapper");
|
|
132
|
+
const flattenedStyle = container.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
133
|
+
expect(flattenedStyle.backgroundColor).toEqual(styleOverride.container.backgroundColor);
|
|
134
|
+
expect(flattenedStyle.width).toEqual(styleOverride.container.width);
|
|
135
|
+
expect(flattenedStyle.borderColor).toEqual(commonInputStyles.container.borderColor);
|
|
136
|
+
expect(flattenedStyle.marginVertical).toEqual(commonInputStyles.container.marginVertical);
|
|
137
|
+
});
|
|
138
|
+
it("has the default placeholder styling when no style override is provided", () => {
|
|
139
|
+
const placeholderText = "myplaceholder";
|
|
140
|
+
const { getByText } = renderInputFieldWrapper({
|
|
141
|
+
placeholder: placeholderText,
|
|
142
|
+
focused: true,
|
|
143
|
+
});
|
|
144
|
+
const placeholder = getByText(placeholderText, {
|
|
145
|
+
includeHiddenElements: true,
|
|
146
|
+
});
|
|
147
|
+
expect(placeholder.props.style).toContainEqual(typographyStyles.subdued);
|
|
148
|
+
expect(placeholder.props.style).toContainEqual(typographyStyles.defaultSize);
|
|
149
|
+
});
|
|
150
|
+
it("shows the placeholder style override when provided", () => {
|
|
151
|
+
const placeholderText = "myplaceholder";
|
|
152
|
+
const styleOverride = {
|
|
153
|
+
placeholderText: {
|
|
154
|
+
color: "purple",
|
|
155
|
+
fontSize: 30,
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const { getByText } = renderInputFieldWrapper({
|
|
159
|
+
placeholder: placeholderText,
|
|
160
|
+
styleOverride,
|
|
161
|
+
});
|
|
162
|
+
const placeholder = getByText(placeholderText, {
|
|
163
|
+
includeHiddenElements: true,
|
|
164
|
+
});
|
|
165
|
+
const flattenedStyle = placeholder.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
166
|
+
expect(flattenedStyle.color).toEqual(styleOverride.placeholderText.color);
|
|
167
|
+
expect(flattenedStyle.fontSize).toEqual(styleOverride.placeholderText.fontSize);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
describe("Toolbar", () => {
|
|
171
|
+
it("renders a toolbar on focused", () => {
|
|
172
|
+
const { getByText } = renderInputFieldWrapper({
|
|
173
|
+
focused: true,
|
|
174
|
+
toolbar: React.createElement(Text, null, "I am a tool"),
|
|
175
|
+
});
|
|
176
|
+
expect(getByText("I am a tool")).toBeDefined();
|
|
177
|
+
});
|
|
178
|
+
it("does not render a toolbar when not focused", () => {
|
|
179
|
+
const { queryByText } = renderInputFieldWrapper({
|
|
180
|
+
focused: false,
|
|
181
|
+
toolbar: React.createElement(Text, null, "I am a tool"),
|
|
182
|
+
});
|
|
183
|
+
expect(queryByText("I am a tool")).toBeNull();
|
|
184
|
+
});
|
|
185
|
+
it("does not render a toolbar when focused and toolbar is not provided", () => {
|
|
186
|
+
const { getByText, queryByText, rerender } = renderInputFieldWrapper({
|
|
187
|
+
focused: true,
|
|
188
|
+
toolbar: React.createElement(Text, null, "I am a tool"),
|
|
189
|
+
});
|
|
190
|
+
expect(getByText("I am a tool")).toBeDefined();
|
|
191
|
+
rerender(React.createElement(InputFieldWrapper, { focused: true },
|
|
192
|
+
React.createElement(Text, null, "Test")));
|
|
193
|
+
expect(queryByText("I am a tool")).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
it("renders a toolbar when toolbarVisibility is always", () => {
|
|
196
|
+
const { getByText } = renderInputFieldWrapper({
|
|
197
|
+
focused: false,
|
|
198
|
+
toolbar: React.createElement(Text, null, "I am a tool"),
|
|
199
|
+
toolbarVisibility: "always",
|
|
200
|
+
});
|
|
201
|
+
expect(getByText("I am a tool")).toBeDefined();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
describe("Loading state", () => {
|
|
205
|
+
it("does not render any loading indicators", () => {
|
|
206
|
+
const { queryByTestId } = renderInputFieldWrapper({});
|
|
207
|
+
expect(queryByTestId(INPUT_FIELD_WRAPPER_SPINNER_TEST_ID)).toBeNull();
|
|
208
|
+
expect(queryByTestId(INPUT_FIELD_WRAPPER_GLIMMERS_TEST_ID)).toBeNull();
|
|
209
|
+
});
|
|
210
|
+
it("renders a loading spinner by default when loading is true and loadingType is not set", () => {
|
|
211
|
+
const { getByTestId, queryByTestId } = renderInputFieldWrapper({
|
|
212
|
+
loading: true,
|
|
213
|
+
});
|
|
214
|
+
expect(getByTestId(INPUT_FIELD_WRAPPER_SPINNER_TEST_ID)).toBeDefined();
|
|
215
|
+
expect(queryByTestId(INPUT_FIELD_WRAPPER_GLIMMERS_TEST_ID)).toBeNull();
|
|
216
|
+
});
|
|
217
|
+
it("renders a glimmer when loading is true and loadingType is glimmer", () => {
|
|
218
|
+
const { getByTestId, queryByTestId } = renderInputFieldWrapper({
|
|
219
|
+
loading: true,
|
|
220
|
+
loadingType: "glimmer",
|
|
221
|
+
});
|
|
222
|
+
expect(getByTestId(INPUT_FIELD_WRAPPER_GLIMMERS_TEST_ID)).toBeDefined();
|
|
223
|
+
expect(queryByTestId(INPUT_FIELD_WRAPPER_SPINNER_TEST_ID)).toBeNull();
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
describe("placeholderMode", () => {
|
|
227
|
+
it("renders the placeholder in its normal position", () => {
|
|
228
|
+
renderInputFieldWrapper({
|
|
229
|
+
placeholder: "placeholder",
|
|
230
|
+
placeholderMode: "normal",
|
|
231
|
+
});
|
|
232
|
+
const placeholder = screen.getByText("placeholder", {
|
|
233
|
+
includeHiddenElements: true,
|
|
234
|
+
});
|
|
235
|
+
expect(placeholder).toBeDefined();
|
|
236
|
+
expect(placeholder.props.style).toContainEqual(typographyStyles.defaultSize);
|
|
237
|
+
});
|
|
238
|
+
it("renders the placeholder in its mini label position", () => {
|
|
239
|
+
renderInputFieldWrapper({
|
|
240
|
+
placeholder: "placeholder",
|
|
241
|
+
placeholderMode: "mini",
|
|
242
|
+
});
|
|
243
|
+
const placeholder = screen.getByText("placeholder", {
|
|
244
|
+
includeHiddenElements: true,
|
|
245
|
+
});
|
|
246
|
+
expect(placeholder).toBeDefined();
|
|
247
|
+
expect(placeholder.props.style).toContainEqual(typographyStyles.smallSize);
|
|
248
|
+
});
|
|
249
|
+
it("does not render the placeholder", () => {
|
|
250
|
+
renderInputFieldWrapper({
|
|
251
|
+
placeholder: "placeholder",
|
|
252
|
+
placeholderMode: "hidden",
|
|
253
|
+
});
|
|
254
|
+
expect(screen.queryByText("placeholder", {
|
|
255
|
+
includeHiddenElements: true,
|
|
256
|
+
})).toBeNull();
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
describe("multiline", () => {
|
|
260
|
+
it("applies maxWidth of 90% when multiline is true", () => {
|
|
261
|
+
const { getByTestId } = renderInputFieldWrapper({ multiline: true });
|
|
262
|
+
const container = getByTestId("ATL-InputFieldWrapper");
|
|
263
|
+
const flattenedStyle = container.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
264
|
+
expect(flattenedStyle.maxWidth).toEqual("90%");
|
|
265
|
+
});
|
|
266
|
+
it("does not apply maxWidth when multiline is false", () => {
|
|
267
|
+
const { getByTestId } = renderInputFieldWrapper({ multiline: false });
|
|
268
|
+
const container = getByTestId("ATL-InputFieldWrapper");
|
|
269
|
+
const flattenedStyle = container.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
270
|
+
expect(flattenedStyle.maxWidth).toBeUndefined();
|
|
271
|
+
});
|
|
272
|
+
it("does not apply maxWidth when multiline is not provided", () => {
|
|
273
|
+
const { getByTestId } = renderInputFieldWrapper({});
|
|
274
|
+
const container = getByTestId("ATL-InputFieldWrapper");
|
|
275
|
+
const flattenedStyle = container.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
276
|
+
expect(flattenedStyle.maxWidth).toBeUndefined();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
|
+
import { ClearAction } from "./ClearAction";
|
|
4
|
+
it("should call the handler", () => {
|
|
5
|
+
const pressHandler = jest.fn();
|
|
6
|
+
const { getByLabelText } = render(React.createElement(ClearAction, { onPress: pressHandler }));
|
|
7
|
+
fireEvent.press(getByLabelText("Clear input"));
|
|
8
|
+
expect(pressHandler).toHaveBeenCalled();
|
|
9
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, renderHook, screen } from "@testing-library/react-native";
|
|
3
|
+
import { Path } from "react-native-svg";
|
|
4
|
+
import { PrefixIcon, PrefixLabel, prefixIconTestId, prefixLabelTestId, } from "./Prefix";
|
|
5
|
+
import { useTypographyStyles } from "../../../Typography";
|
|
6
|
+
import { useStyles } from "../../InputFieldWrapper.style";
|
|
7
|
+
import { tokens } from "../../../utils/design";
|
|
8
|
+
const mockLabel = "$";
|
|
9
|
+
let styles;
|
|
10
|
+
let typographyStyles;
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
const stylesHook = renderHook(() => useStyles());
|
|
13
|
+
const typographyStylesHook = renderHook(() => useTypographyStyles());
|
|
14
|
+
styles = stylesHook.result.current;
|
|
15
|
+
typographyStyles = typographyStylesHook.result.current;
|
|
16
|
+
});
|
|
17
|
+
function setupLabel({ disabled = false, focused = false, miniLabelActive = false, inputInvalid = false, label = mockLabel, styleOverride, }) {
|
|
18
|
+
return render(React.createElement(PrefixLabel, { disabled: disabled, focused: focused, miniLabelActive: miniLabelActive, inputInvalid: inputInvalid, label: label, styleOverride: styleOverride }));
|
|
19
|
+
}
|
|
20
|
+
function setupIcon({ disabled = false, focused = false, inputInvalid = false, icon = "invoice", }) {
|
|
21
|
+
return render(React.createElement(PrefixIcon, { disabled: disabled, focused: focused, inputInvalid: inputInvalid, icon: icon }));
|
|
22
|
+
}
|
|
23
|
+
describe("Prefix", () => {
|
|
24
|
+
it("renders a prefix label when specified", () => {
|
|
25
|
+
const { getByText } = setupLabel({});
|
|
26
|
+
expect(getByText(mockLabel)).toBeDefined();
|
|
27
|
+
});
|
|
28
|
+
it("renders a prefix icon when specified", () => {
|
|
29
|
+
const { getByTestId } = setupIcon({});
|
|
30
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
describe("updates the styles when focused", () => {
|
|
33
|
+
it("for the label", () => {
|
|
34
|
+
const tree = setupLabel({
|
|
35
|
+
focused: true,
|
|
36
|
+
});
|
|
37
|
+
const expectedStyle = Object.assign(Object.assign({}, styles.fieldAffix), styles.inputFocused);
|
|
38
|
+
const prefixLabel = tree.getByTestId(prefixLabelTestId);
|
|
39
|
+
const flattenedStyle = prefixLabel.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
40
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
41
|
+
});
|
|
42
|
+
it("for the icon", () => {
|
|
43
|
+
const tree = setupIcon({
|
|
44
|
+
focused: true,
|
|
45
|
+
});
|
|
46
|
+
const expectedStyle = Object.assign(Object.assign({}, styles.fieldAffix), styles.inputFocused);
|
|
47
|
+
const icon = tree.getByTestId(prefixIconTestId);
|
|
48
|
+
const flattenedStyle = icon.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
49
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("updates the styles when input is invalid", () => {
|
|
53
|
+
it("for the label", () => {
|
|
54
|
+
const tree = setupLabel({
|
|
55
|
+
inputInvalid: true,
|
|
56
|
+
});
|
|
57
|
+
const expectedStyle = Object.assign(Object.assign({}, styles.fieldAffix), styles.inputInvalid);
|
|
58
|
+
const prefixLabel = tree.getByTestId(prefixLabelTestId);
|
|
59
|
+
const flattenedStyle = prefixLabel.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
60
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
61
|
+
});
|
|
62
|
+
it("for the icon", () => {
|
|
63
|
+
const tree = setupIcon({
|
|
64
|
+
inputInvalid: true,
|
|
65
|
+
});
|
|
66
|
+
const expectedStyle = Object.assign(Object.assign({}, styles.fieldAffix), styles.inputInvalid);
|
|
67
|
+
const prefixIcon = tree.getByTestId(prefixIconTestId);
|
|
68
|
+
const flattenedStyle = prefixIcon.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
69
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it("updates the position of the label when a value is entered", () => {
|
|
73
|
+
const tree = setupLabel({
|
|
74
|
+
miniLabelActive: true,
|
|
75
|
+
});
|
|
76
|
+
const prefixLabel = tree.getByTestId(prefixLabelTestId);
|
|
77
|
+
const labelWrapper = prefixLabel.children[0];
|
|
78
|
+
const expectedStyle = [styles.prefixLabel, styles.fieldAffixMiniLabel];
|
|
79
|
+
expect(labelWrapper.props.style).toEqual(expectedStyle);
|
|
80
|
+
});
|
|
81
|
+
describe("when disabled", () => {
|
|
82
|
+
it("updates the label", () => {
|
|
83
|
+
const tree = setupLabel({
|
|
84
|
+
disabled: true,
|
|
85
|
+
});
|
|
86
|
+
const prefixLabel = tree.getByText(mockLabel);
|
|
87
|
+
const expectedStyle = [
|
|
88
|
+
typographyStyles.baseRegularRegular,
|
|
89
|
+
typographyStyles.disabled,
|
|
90
|
+
typographyStyles.startAlign,
|
|
91
|
+
typographyStyles.defaultSize,
|
|
92
|
+
typographyStyles.baseLetterSpacing,
|
|
93
|
+
];
|
|
94
|
+
expect(prefixLabel.props.style).toEqual(expectedStyle);
|
|
95
|
+
});
|
|
96
|
+
it("updates the icon", () => {
|
|
97
|
+
setupIcon({
|
|
98
|
+
disabled: true,
|
|
99
|
+
});
|
|
100
|
+
const icon = screen.getByTestId("invoice");
|
|
101
|
+
const path = icon.findByType(Path);
|
|
102
|
+
expect(path.props.fill).toEqual(tokens["color-disabled"]);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe("Custom Label Style", () => {
|
|
106
|
+
it("uses default styling when style override not used", () => {
|
|
107
|
+
const { getByText } = setupLabel({});
|
|
108
|
+
const prefix = getByText(mockLabel);
|
|
109
|
+
const expectedStyle = [
|
|
110
|
+
typographyStyles.baseRegularRegular,
|
|
111
|
+
typographyStyles.base,
|
|
112
|
+
typographyStyles.startAlign,
|
|
113
|
+
typographyStyles.defaultSize,
|
|
114
|
+
typographyStyles.baseLetterSpacing,
|
|
115
|
+
];
|
|
116
|
+
expect(prefix.props.style).toEqual(expectedStyle);
|
|
117
|
+
});
|
|
118
|
+
it("uses style override for label when provided", () => {
|
|
119
|
+
const styleOverride = {
|
|
120
|
+
fontSize: 50,
|
|
121
|
+
color: "purple",
|
|
122
|
+
};
|
|
123
|
+
const { getByText } = setupLabel({ styleOverride });
|
|
124
|
+
const prefix = getByText(mockLabel);
|
|
125
|
+
const flattenedStyle = prefix.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
126
|
+
const expectedStyle = Object.assign(Object.assign(Object.assign({}, styleOverride), typographyStyles.baseRegularRegular), { lineHeight: typographyStyles.defaultSize.lineHeight });
|
|
127
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, renderHook } from "@testing-library/react-native";
|
|
3
|
+
import { SuffixIcon, SuffixLabel } from "./Suffix";
|
|
4
|
+
import { useTypographyStyles } from "../../../Typography";
|
|
5
|
+
const mockLabel = "$";
|
|
6
|
+
function setupLabel({ disabled = false, focused = false, miniLabelActive = false, inputInvalid = false, label = mockLabel, styleOverride, }) {
|
|
7
|
+
return render(React.createElement(SuffixLabel, { disabled: disabled, focused: focused, miniLabelActive: miniLabelActive, inputInvalid: inputInvalid, label: label, styleOverride: styleOverride }));
|
|
8
|
+
}
|
|
9
|
+
function setupIcon({ disabled = false, focused = false, inputInvalid = false, icon = "invoice", }) {
|
|
10
|
+
return render(React.createElement(SuffixIcon, { disabled: disabled, focused: focused, inputInvalid: inputInvalid, icon: icon }));
|
|
11
|
+
}
|
|
12
|
+
let typographyStyles;
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
const typographyStylesHook = renderHook(() => useTypographyStyles());
|
|
15
|
+
typographyStyles = typographyStylesHook.result.current;
|
|
16
|
+
});
|
|
17
|
+
describe("Suffix", () => {
|
|
18
|
+
it("renders a suffix label when specified", () => {
|
|
19
|
+
const { getByText } = setupLabel({});
|
|
20
|
+
expect(getByText(mockLabel)).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
it("renders a suffix icon when specified", () => {
|
|
23
|
+
const { getByTestId } = setupIcon({});
|
|
24
|
+
expect(getByTestId("invoice")).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
describe("Custom Label Style", () => {
|
|
27
|
+
it("uses default styling when no style override is provided", () => {
|
|
28
|
+
const { getByText } = setupLabel({});
|
|
29
|
+
const suffix = getByText(mockLabel);
|
|
30
|
+
const expectedStyle = [
|
|
31
|
+
typographyStyles.baseRegularRegular,
|
|
32
|
+
typographyStyles.base,
|
|
33
|
+
typographyStyles.startAlign,
|
|
34
|
+
typographyStyles.defaultSize,
|
|
35
|
+
typographyStyles.baseLetterSpacing,
|
|
36
|
+
];
|
|
37
|
+
expect(suffix.props.style).toEqual(expectedStyle);
|
|
38
|
+
});
|
|
39
|
+
it("uses style override for label when provided", () => {
|
|
40
|
+
const styleOverride = {
|
|
41
|
+
fontSize: 50,
|
|
42
|
+
color: "purple",
|
|
43
|
+
};
|
|
44
|
+
const { getByText } = setupLabel({ styleOverride });
|
|
45
|
+
const suffix = getByText(mockLabel);
|
|
46
|
+
const flattenedStyle = suffix.props.style.reduce((style, additionalStyles) => (Object.assign(Object.assign({}, style), additionalStyles)), {});
|
|
47
|
+
const expectedStyle = Object.assign(Object.assign(Object.assign({}, typographyStyles.baseRegularRegular), { lineHeight: typographyStyles.defaultSize.lineHeight }), styleOverride);
|
|
48
|
+
expect(flattenedStyle).toEqual(expectedStyle);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|