@hero-design/rn 7.20.1 → 7.22.0
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/.eslintrc.js +11 -0
- package/.turbo/turbo-build.log +9 -9
- package/babel.config.js +1 -1
- package/es/index.js +714 -471
- package/lib/index.js +720 -474
- package/package.json +9 -15
- package/rollup.config.js +1 -0
- package/src/components/BottomNavigation/__tests__/index.spec.tsx +1 -1
- package/src/components/BottomNavigation/index.tsx +3 -3
- package/src/components/BottomSheet/index.tsx +6 -1
- package/src/components/Box/helpers.ts +1 -1
- package/src/components/Calendar/index.tsx +9 -9
- package/src/components/Checkbox/__tests__/__snapshots__/StyledCheckbox.spec.tsx.snap +4 -4
- package/src/components/Checkbox/__tests__/__snapshots__/index.spec.tsx.snap +13 -13
- package/src/components/Collapse/index.tsx +1 -1
- package/src/components/Drawer/DragableDrawer/helpers.ts +7 -3
- package/src/components/Empty/StyledEmpty.tsx +1 -9
- package/src/components/Empty/__tests__/__snapshots__/index.spec.tsx.snap +58 -5
- package/src/components/Empty/__tests__/index.spec.tsx +13 -0
- package/src/components/Empty/index.tsx +38 -18
- package/src/components/FAB/ActionGroup/index.tsx +1 -1
- package/src/components/Icon/HeroIcon/selection.json +7029 -1
- package/src/components/Image/__tests__/__snapshots__/index.spec.tsx.snap +81 -0
- package/src/components/Image/__tests__/index.spec.tsx +29 -0
- package/src/components/Image/index.tsx +46 -0
- package/src/components/List/__tests__/__snapshots__/ListItem.spec.tsx.snap +5 -5
- package/src/components/PinInput/index.tsx +1 -1
- package/src/components/Progress/__tests__/__snapshots__/index.spec.js.snap +60 -60
- package/src/components/RichTextEditor/EditorToolbar.tsx +3 -3
- package/src/components/RichTextEditor/RichTextEditor.tsx +5 -5
- package/src/components/RichTextEditor/__tests__/EditorToolbar.spec.tsx +2 -2
- package/src/components/RichTextEditor/__tests__/MentionList.spec.tsx +1 -1
- package/src/components/RichTextEditor/__tests__/__snapshots__/EditorToolbar.spec.tsx.snap +2 -2
- package/src/components/RichTextEditor/__tests__/__snapshots__/RichTextEditor.spec.tsx.snap +2 -2
- package/src/components/Select/MultiSelect/OptionList.tsx +5 -7
- package/src/components/Select/MultiSelect/__tests__/index.spec.tsx +21 -0
- package/src/components/Select/MultiSelect/index.tsx +35 -5
- package/src/components/Select/SingleSelect/OptionList.tsx +4 -5
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +16 -0
- package/src/components/Select/SingleSelect/index.tsx +36 -6
- package/src/components/Select/StyledOptionList.tsx +3 -9
- package/src/components/Select/helpers.tsx +4 -4
- package/src/components/Slider/__tests__/__snapshots__/index.spec.tsx.snap +43 -0
- package/src/components/Slider/__tests__/index.spec.tsx +33 -0
- package/src/components/Slider/index.tsx +89 -0
- package/src/components/Switch/SelectorSwitch/Option.tsx +67 -0
- package/src/components/Switch/SelectorSwitch/StyledSelectorSwitch.tsx +25 -0
- package/src/components/Switch/SelectorSwitch/__tests__/Option.spec.tsx +61 -0
- package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/Option.spec.tsx.snap +195 -0
- package/src/components/Switch/SelectorSwitch/__tests__/__snapshots__/index.spec.tsx.snap +121 -0
- package/src/components/Switch/SelectorSwitch/__tests__/index.spec.tsx +62 -0
- package/src/components/Switch/SelectorSwitch/index.tsx +60 -0
- package/src/components/Switch/StyledSwitch.tsx +4 -4
- package/src/components/Switch/__tests__/__snapshots__/StyledSwitch.spec.tsx.snap +10 -10
- package/src/components/Switch/__tests__/__snapshots__/index.spec.tsx.snap +8 -8
- package/src/components/Switch/index.tsx +9 -5
- package/src/components/Tabs/ScrollableTabs.tsx +12 -5
- package/src/components/Tabs/__tests__/ScrollableTabs.spec.tsx +1 -1
- package/src/components/Tabs/__tests__/index.spec.tsx +1 -1
- package/src/components/Tabs/index.tsx +13 -6
- package/src/components/TextInput/__tests__/__snapshots__/index.spec.tsx.snap +3 -1
- package/src/components/TextInput/__tests__/index.spec.tsx +114 -112
- package/src/components/TextInput/index.tsx +64 -59
- package/src/components/Toast/ToastContainer.tsx +6 -6
- package/src/index.ts +4 -0
- package/src/theme/__tests__/__snapshots__/index.spec.ts.snap +70 -23
- package/src/theme/components/alert.ts +1 -2
- package/src/theme/components/avatar.ts +8 -8
- package/src/theme/components/badge.ts +4 -4
- package/src/theme/components/bottomNavigation.ts +1 -1
- package/src/theme/components/bottomSheet.ts +2 -3
- package/src/theme/components/calendar.ts +9 -7
- package/src/theme/components/card.ts +1 -1
- package/src/theme/components/checkbox.ts +2 -5
- package/src/theme/components/datePicker.ts +3 -3
- package/src/theme/components/drawer.ts +2 -3
- package/src/theme/components/empty.ts +3 -8
- package/src/theme/components/fab.ts +2 -2
- package/src/theme/components/image.ts +12 -0
- package/src/theme/components/pinInput.ts +3 -3
- package/src/theme/components/progress.ts +2 -3
- package/src/theme/components/radio.ts +7 -3
- package/src/theme/components/richTextEditor.ts +4 -4
- package/src/theme/components/slider.ts +13 -0
- package/src/theme/components/switch.ts +28 -17
- package/src/theme/components/tabs.ts +1 -1
- package/src/theme/components/timePicker.ts +3 -3
- package/src/theme/components/toast.ts +1 -2
- package/src/theme/getTheme.ts +9 -2
- package/src/theme/global/colors/swag.ts +2 -0
- package/src/theme/global/colors/types.ts +2 -0
- package/src/theme/global/index.ts +3 -0
- package/src/theme/global/scale.ts +3 -0
- package/src/theme/global/sizes.ts +29 -0
- package/testUtils/setup.tsx +15 -1
- package/tsconfig.json +1 -1
- package/types/components/BottomSheet/index.d.ts +5 -1
- package/types/components/Empty/StyledEmpty.d.ts +1 -7
- package/types/components/Empty/index.d.ts +8 -2
- package/types/components/Image/__tests__/index.spec.d.ts +1 -0
- package/types/components/Image/index.d.ts +17 -0
- package/types/components/Select/MultiSelect/OptionList.d.ts +5 -2
- package/types/components/Select/MultiSelect/index.d.ts +7 -1
- package/types/components/Select/SingleSelect/OptionList.d.ts +5 -2
- package/types/components/Select/SingleSelect/index.d.ts +8 -2
- package/types/components/Select/StyledOptionList.d.ts +4 -3
- package/types/components/Select/index.d.ts +1 -1
- package/types/components/Slider/__tests__/index.spec.d.ts +1 -0
- package/types/components/Slider/index.d.ts +52 -0
- package/types/components/Switch/SelectorSwitch/Option.d.ts +10 -0
- package/types/components/Switch/SelectorSwitch/StyledSelectorSwitch.d.ts +19 -0
- package/types/components/Switch/SelectorSwitch/__tests__/Option.spec.d.ts +1 -0
- package/types/components/Switch/SelectorSwitch/__tests__/index.spec.d.ts +1 -0
- package/types/components/Switch/SelectorSwitch/index.d.ts +37 -0
- package/types/components/Switch/index.d.ts +5 -3
- package/types/components/Tabs/ScrollableTabs.d.ts +1 -1
- package/types/components/Tabs/index.d.ts +2 -2
- package/types/components/TextInput/index.d.ts +6 -5
- package/types/index.d.ts +3 -1
- package/types/theme/components/datePicker.d.ts +2 -1
- package/types/theme/components/empty.d.ts +2 -5
- package/types/theme/components/image.d.ts +8 -0
- package/types/theme/components/slider.d.ts +9 -0
- package/types/theme/components/switch.d.ts +27 -12
- package/types/theme/components/timePicker.d.ts +2 -1
- package/types/theme/getTheme.d.ts +4 -0
- package/types/theme/global/colors/types.d.ts +2 -0
- package/types/theme/global/index.d.ts +3 -0
- package/types/theme/global/scale.d.ts +1 -0
- package/types/theme/global/sizes.d.ts +14 -0
- package/.eslintrc.json +0 -61
- package/.prettierrc.json +0 -8
|
@@ -63,12 +63,15 @@ const ScrollableTab = ({
|
|
|
63
63
|
barStyle,
|
|
64
64
|
lazy = false,
|
|
65
65
|
lazyPreloadDistance = 1,
|
|
66
|
+
testID: componentTestID,
|
|
66
67
|
}: TabsProps) => {
|
|
67
68
|
const flatListRef = React.useRef<FlatList>(null);
|
|
68
69
|
const pagerViewRef = React.useRef<PagerView>(null);
|
|
69
70
|
const insets = useSafeAreaInsets();
|
|
70
71
|
const theme = useTheme();
|
|
71
|
-
const selectedTabIndex = tabs.findIndex(
|
|
72
|
+
const selectedTabIndex = tabs.findIndex(
|
|
73
|
+
(item) => item.key === selectedTabKey
|
|
74
|
+
);
|
|
72
75
|
const tabsAnims = useAnimatedValueArray(
|
|
73
76
|
tabs.map((_, i) => (i === selectedTabIndex ? 1 : 0))
|
|
74
77
|
);
|
|
@@ -97,13 +100,17 @@ const ScrollableTab = ({
|
|
|
97
100
|
}, [selectedTabIndex]);
|
|
98
101
|
|
|
99
102
|
return (
|
|
100
|
-
<TabContainer style={containerStyle}>
|
|
101
|
-
<HeaderTabWrapper
|
|
103
|
+
<TabContainer style={containerStyle} testID={componentTestID}>
|
|
104
|
+
<HeaderTabWrapper
|
|
105
|
+
themeInsets={insets}
|
|
106
|
+
style={barStyle}
|
|
107
|
+
testID={componentTestID ? `${componentTestID}-tab-bar` : undefined}
|
|
108
|
+
>
|
|
102
109
|
<FlatList<TabType>
|
|
103
110
|
ref={flatListRef}
|
|
104
111
|
horizontal
|
|
105
112
|
data={tabs}
|
|
106
|
-
keyExtractor={tab => String(tab.key)}
|
|
113
|
+
keyExtractor={(tab) => String(tab.key)}
|
|
107
114
|
showsHorizontalScrollIndicator={false}
|
|
108
115
|
onScrollToIndexFailed={({ index }) => {
|
|
109
116
|
setTimeout(
|
|
@@ -184,7 +191,7 @@ const ScrollableTab = ({
|
|
|
184
191
|
<ContentWrapper
|
|
185
192
|
initialPage={selectedTabIndex}
|
|
186
193
|
ref={pagerViewRef}
|
|
187
|
-
onPageSelected={e => {
|
|
194
|
+
onPageSelected={(e) => {
|
|
188
195
|
const index = e.nativeEvent.position;
|
|
189
196
|
const selectedItem = tabs[index];
|
|
190
197
|
if (selectedItem) {
|
|
@@ -105,11 +105,14 @@ const Tabs = ({
|
|
|
105
105
|
barStyle,
|
|
106
106
|
lazy = false,
|
|
107
107
|
lazyPreloadDistance = 1,
|
|
108
|
+
testID: componentTestID,
|
|
108
109
|
}: TabsProps): JSX.Element => {
|
|
109
110
|
const theme = useTheme();
|
|
110
111
|
const insets = useSafeAreaInsets();
|
|
111
112
|
const pagerViewRef = React.useRef<PagerView>(null);
|
|
112
|
-
const selectedTabIndex = tabs.findIndex(
|
|
113
|
+
const selectedTabIndex = tabs.findIndex(
|
|
114
|
+
(item) => item.key === selectedTabKey
|
|
115
|
+
);
|
|
113
116
|
const scrollOffsetAnimatedValue = React.useRef(new Animated.Value(0)).current;
|
|
114
117
|
const positionAnimatedValue = React.useRef(new Animated.Value(0)).current;
|
|
115
118
|
const [tabsWidth, setTabsWidth] = React.useState<number>(0);
|
|
@@ -121,18 +124,22 @@ const Tabs = ({
|
|
|
121
124
|
}, [selectedTabIndex]);
|
|
122
125
|
|
|
123
126
|
return (
|
|
124
|
-
<TabContainer style={containerStyle}>
|
|
125
|
-
<HeaderTabWrapper
|
|
127
|
+
<TabContainer style={containerStyle} testID={componentTestID}>
|
|
128
|
+
<HeaderTabWrapper
|
|
129
|
+
themeInsets={insets}
|
|
130
|
+
style={barStyle}
|
|
131
|
+
testID={componentTestID ? `${componentTestID}-tab-bar` : undefined}
|
|
132
|
+
>
|
|
126
133
|
<View>
|
|
127
134
|
<HeaderTab
|
|
128
|
-
onLayout={e => {
|
|
135
|
+
onLayout={(e) => {
|
|
129
136
|
const { width } = e.nativeEvent.layout;
|
|
130
137
|
if (tabsWidth !== width) {
|
|
131
138
|
setTabsWidth(width);
|
|
132
139
|
}
|
|
133
140
|
}}
|
|
134
141
|
>
|
|
135
|
-
{tabs.map(tab => {
|
|
142
|
+
{tabs.map((tab) => {
|
|
136
143
|
const {
|
|
137
144
|
key,
|
|
138
145
|
testID,
|
|
@@ -180,7 +187,7 @@ const Tabs = ({
|
|
|
180
187
|
<ContentWrapper
|
|
181
188
|
initialPage={selectedTabIndex}
|
|
182
189
|
ref={pagerViewRef}
|
|
183
|
-
onPageSelected={e => {
|
|
190
|
+
onPageSelected={(e) => {
|
|
184
191
|
const index = e.nativeEvent.position;
|
|
185
192
|
const selectedItem = tabs[index];
|
|
186
193
|
if (selectedItem) {
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { fireEvent, within } from
|
|
2
|
-
import React from
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { fireEvent, within } from "@testing-library/react-native";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { theme } from "../../..";
|
|
4
|
+
import renderWithTheme from "../../../testHelpers/renderWithTheme";
|
|
5
|
+
import Icon from "../../Icon";
|
|
6
|
+
import TextInput, { getVariant } from "../index";
|
|
7
|
+
|
|
8
|
+
describe("getVariant", () => {
|
|
8
9
|
it.each`
|
|
9
10
|
disabled | error | editable | loading | isFocused | isEmptyValue | expected
|
|
10
|
-
${false} | ${undefined} | ${true} | ${false} | ${false} | ${true} | ${
|
|
11
|
-
${false} | ${undefined} | ${true} | ${false} | ${false} | ${false} | ${
|
|
12
|
-
${false} | ${undefined} | ${true} | ${false} | ${true} | ${true} | ${
|
|
13
|
-
${false} | ${undefined} | ${false} | ${true} | ${true} | ${true} | ${
|
|
14
|
-
${false} | ${
|
|
15
|
-
${true} | ${
|
|
11
|
+
${false} | ${undefined} | ${true} | ${false} | ${false} | ${true} | ${"default"}
|
|
12
|
+
${false} | ${undefined} | ${true} | ${false} | ${false} | ${false} | ${"filled"}
|
|
13
|
+
${false} | ${undefined} | ${true} | ${false} | ${true} | ${true} | ${"focused"}
|
|
14
|
+
${false} | ${undefined} | ${false} | ${true} | ${true} | ${true} | ${"readonly"}
|
|
15
|
+
${false} | ${"This field is required"} | ${false} | ${false} | ${true} | ${true} | ${"error"}
|
|
16
|
+
${true} | ${"This field is required"} | ${false} | ${false} | ${true} | ${true} | ${"disabled"}
|
|
16
17
|
`(
|
|
17
|
-
|
|
18
|
+
"should return the correct variant when disabled $disabled, errorMessage $errorMessage, editable $false, isFocused $isFocused, isEmptyValue $isEmptyValue",
|
|
18
19
|
({
|
|
19
20
|
disabled,
|
|
20
21
|
error,
|
|
@@ -38,38 +39,39 @@ describe('getVariant', () => {
|
|
|
38
39
|
);
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
describe(
|
|
42
|
-
describe(
|
|
43
|
-
it(
|
|
42
|
+
describe("TextInput", () => {
|
|
43
|
+
describe("idle", () => {
|
|
44
|
+
it("renders correctly", () => {
|
|
44
45
|
const { getByTestId, toJSON } = renderWithTheme(
|
|
45
46
|
<TextInput
|
|
46
47
|
label="Amount (AUD)"
|
|
47
48
|
prefix="dollar-sign"
|
|
48
49
|
suffix="arrow-down"
|
|
49
50
|
testID="idle-text-input"
|
|
51
|
+
style={{ borderColor: theme.colors.danger }}
|
|
50
52
|
/>
|
|
51
53
|
);
|
|
52
54
|
|
|
53
55
|
expect(toJSON()).toMatchSnapshot();
|
|
54
|
-
expect(getByTestId(
|
|
56
|
+
expect(getByTestId("idle-text-input")).toBeTruthy();
|
|
55
57
|
expect(
|
|
56
|
-
within(getByTestId(
|
|
58
|
+
within(getByTestId("idle-text-input")).queryAllByTestId("text-input")
|
|
57
59
|
).toHaveLength(1);
|
|
58
60
|
expect(
|
|
59
|
-
within(getByTestId(
|
|
61
|
+
within(getByTestId("idle-text-input")).queryAllByText("Amount (AUD)")
|
|
60
62
|
).toHaveLength(1);
|
|
61
63
|
expect(
|
|
62
|
-
within(getByTestId(
|
|
64
|
+
within(getByTestId("idle-text-input")).queryAllByTestId("input-label")
|
|
63
65
|
).toHaveLength(1);
|
|
64
66
|
expect(
|
|
65
|
-
within(getByTestId(
|
|
67
|
+
within(getByTestId("idle-text-input")).queryAllByTestId("input-prefix")
|
|
66
68
|
).toHaveLength(1);
|
|
67
69
|
expect(
|
|
68
|
-
within(getByTestId(
|
|
70
|
+
within(getByTestId("idle-text-input")).queryAllByTestId("input-suffix")
|
|
69
71
|
).toHaveLength(1);
|
|
70
72
|
});
|
|
71
73
|
|
|
72
|
-
it(
|
|
74
|
+
it("should not render input-label if label is empty", () => {
|
|
73
75
|
const { getByTestId } = renderWithTheme(
|
|
74
76
|
<TextInput
|
|
75
77
|
prefix="dollar-sign"
|
|
@@ -78,13 +80,13 @@ describe('TextInput', () => {
|
|
|
78
80
|
/>
|
|
79
81
|
);
|
|
80
82
|
|
|
81
|
-
expect(getByTestId(
|
|
83
|
+
expect(getByTestId("idle-text-input")).toBeTruthy();
|
|
82
84
|
expect(
|
|
83
|
-
within(getByTestId(
|
|
85
|
+
within(getByTestId("idle-text-input")).queryAllByTestId("input-label")
|
|
84
86
|
).toHaveLength(0);
|
|
85
87
|
});
|
|
86
88
|
|
|
87
|
-
it(
|
|
89
|
+
it("onChangeText, onBlur, onFocus", () => {
|
|
88
90
|
const onChangeText = jest.fn();
|
|
89
91
|
const onBlur = jest.fn();
|
|
90
92
|
const onFocus = jest.fn();
|
|
@@ -100,23 +102,23 @@ describe('TextInput', () => {
|
|
|
100
102
|
/>
|
|
101
103
|
);
|
|
102
104
|
|
|
103
|
-
const testInput = within(getByTestId(
|
|
104
|
-
|
|
105
|
+
const testInput = within(getByTestId("idle-text-input")).getByTestId(
|
|
106
|
+
"text-input"
|
|
105
107
|
);
|
|
106
108
|
|
|
107
|
-
fireEvent.changeText(testInput,
|
|
108
|
-
expect(onChangeText).toHaveBeenCalledWith(
|
|
109
|
+
fireEvent.changeText(testInput, "Thong Quach");
|
|
110
|
+
expect(onChangeText).toHaveBeenCalledWith("Thong Quach");
|
|
109
111
|
|
|
110
|
-
fireEvent(testInput,
|
|
112
|
+
fireEvent(testInput, "blur");
|
|
111
113
|
expect(onBlur).toHaveBeenCalledTimes(1);
|
|
112
114
|
|
|
113
|
-
fireEvent(testInput,
|
|
115
|
+
fireEvent(testInput, "focus");
|
|
114
116
|
expect(onFocus).toHaveBeenCalledTimes(1);
|
|
115
117
|
});
|
|
116
118
|
});
|
|
117
119
|
|
|
118
|
-
describe(
|
|
119
|
-
it(
|
|
120
|
+
describe("idle with suffix and prefix are React Element", () => {
|
|
121
|
+
it("renders correctly", () => {
|
|
120
122
|
const { toJSON, queryAllByTestId, queryAllByText } = renderWithTheme(
|
|
121
123
|
<TextInput
|
|
122
124
|
label="Amount (AUD)"
|
|
@@ -127,16 +129,16 @@ describe('TextInput', () => {
|
|
|
127
129
|
);
|
|
128
130
|
|
|
129
131
|
expect(toJSON()).toMatchSnapshot();
|
|
130
|
-
expect(queryAllByText(
|
|
131
|
-
expect(queryAllByText(
|
|
132
|
-
expect(queryAllByTestId(
|
|
133
|
-
expect(queryAllByTestId(
|
|
134
|
-
expect(queryAllByTestId(
|
|
135
|
-
expect(queryAllByTestId(
|
|
132
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
133
|
+
expect(queryAllByText("*")).toHaveLength(1);
|
|
134
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
135
|
+
expect(queryAllByTestId("prefix-element")).toHaveLength(1);
|
|
136
|
+
expect(queryAllByTestId("suffix-element")).toHaveLength(1);
|
|
137
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
136
138
|
});
|
|
137
139
|
});
|
|
138
|
-
describe(
|
|
139
|
-
it(
|
|
140
|
+
describe("required", () => {
|
|
141
|
+
it("renders correctly", () => {
|
|
140
142
|
const { toJSON, queryAllByTestId, queryAllByText } = renderWithTheme(
|
|
141
143
|
<TextInput
|
|
142
144
|
label="Amount (AUD)"
|
|
@@ -147,17 +149,17 @@ describe('TextInput', () => {
|
|
|
147
149
|
);
|
|
148
150
|
|
|
149
151
|
expect(toJSON()).toMatchSnapshot();
|
|
150
|
-
expect(queryAllByText(
|
|
151
|
-
expect(queryAllByText(
|
|
152
|
-
expect(queryAllByTestId(
|
|
153
|
-
expect(queryAllByTestId(
|
|
154
|
-
expect(queryAllByTestId(
|
|
155
|
-
expect(queryAllByTestId(
|
|
152
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
153
|
+
expect(queryAllByText("*")).toHaveLength(1);
|
|
154
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
155
|
+
expect(queryAllByTestId("input-prefix")).toHaveLength(1);
|
|
156
|
+
expect(queryAllByTestId("input-suffix")).toHaveLength(1);
|
|
157
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
156
158
|
});
|
|
157
159
|
});
|
|
158
160
|
|
|
159
|
-
describe(
|
|
160
|
-
it(
|
|
161
|
+
describe("filled", () => {
|
|
162
|
+
it("renders correctly", () => {
|
|
161
163
|
const {
|
|
162
164
|
toJSON,
|
|
163
165
|
queryAllByTestId,
|
|
@@ -173,17 +175,17 @@ describe('TextInput', () => {
|
|
|
173
175
|
);
|
|
174
176
|
|
|
175
177
|
expect(toJSON()).toMatchSnapshot();
|
|
176
|
-
expect(queryAllByText(
|
|
177
|
-
expect(queryAllByDisplayValue(
|
|
178
|
-
expect(queryAllByTestId(
|
|
179
|
-
expect(queryAllByTestId(
|
|
180
|
-
expect(queryAllByTestId(
|
|
181
|
-
expect(queryAllByTestId(
|
|
178
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
179
|
+
expect(queryAllByDisplayValue("100")).toHaveLength(1);
|
|
180
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
181
|
+
expect(queryAllByTestId("input-prefix")).toHaveLength(1);
|
|
182
|
+
expect(queryAllByTestId("input-suffix")).toHaveLength(1);
|
|
183
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
182
184
|
});
|
|
183
185
|
});
|
|
184
186
|
|
|
185
|
-
describe(
|
|
186
|
-
it(
|
|
187
|
+
describe("readonly", () => {
|
|
188
|
+
it("renders correctly", () => {
|
|
187
189
|
const onChangeText = jest.fn();
|
|
188
190
|
const {
|
|
189
191
|
toJSON,
|
|
@@ -204,31 +206,31 @@ describe('TextInput', () => {
|
|
|
204
206
|
);
|
|
205
207
|
|
|
206
208
|
expect(toJSON()).toMatchSnapshot();
|
|
207
|
-
expect(queryAllByText(
|
|
208
|
-
expect(queryAllByDisplayValue(
|
|
209
|
-
expect(queryAllByTestId(
|
|
210
|
-
expect(queryAllByTestId(
|
|
211
|
-
expect(queryAllByTestId(
|
|
212
|
-
expect(queryAllByTestId(
|
|
213
|
-
|
|
214
|
-
expect(getByTestId(
|
|
209
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
210
|
+
expect(queryAllByDisplayValue("100")).toHaveLength(1);
|
|
211
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
212
|
+
expect(queryAllByTestId("input-prefix")).toHaveLength(1);
|
|
213
|
+
expect(queryAllByTestId("input-suffix")).toHaveLength(1);
|
|
214
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
215
|
+
|
|
216
|
+
expect(getByTestId("text-input")).not.toHaveProp("editable", "false");
|
|
215
217
|
});
|
|
216
218
|
});
|
|
217
219
|
|
|
218
|
-
describe(
|
|
219
|
-
it(
|
|
220
|
+
describe("loading", () => {
|
|
221
|
+
it("renders correctly", () => {
|
|
220
222
|
const { toJSON, queryAllByTestId, getByTestId } = renderWithTheme(
|
|
221
223
|
<TextInput suffix="arrow-down" loading />
|
|
222
224
|
);
|
|
223
225
|
|
|
224
226
|
expect(toJSON()).toMatchSnapshot();
|
|
225
|
-
expect(queryAllByTestId(
|
|
226
|
-
expect(getByTestId(
|
|
227
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
228
|
+
expect(getByTestId("input-suffix")).toHaveProp("name", "loading");
|
|
227
229
|
});
|
|
228
230
|
});
|
|
229
231
|
|
|
230
|
-
describe(
|
|
231
|
-
it(
|
|
232
|
+
describe("max length", () => {
|
|
233
|
+
it("renders correctly", () => {
|
|
232
234
|
const {
|
|
233
235
|
toJSON,
|
|
234
236
|
queryAllByTestId,
|
|
@@ -247,18 +249,18 @@ describe('TextInput', () => {
|
|
|
247
249
|
);
|
|
248
250
|
|
|
249
251
|
expect(toJSON()).toMatchSnapshot();
|
|
250
|
-
expect(queryAllByText(
|
|
251
|
-
expect(queryAllByDisplayValue(
|
|
252
|
-
expect(queryAllByText(
|
|
253
|
-
expect(queryAllByTestId(
|
|
254
|
-
expect(queryAllByTestId(
|
|
252
|
+
expect(queryAllByText("Shout out")).toHaveLength(1);
|
|
253
|
+
expect(queryAllByDisplayValue("shout out Tung Van")).toHaveLength(1);
|
|
254
|
+
expect(queryAllByText("18/255")).toHaveLength(1);
|
|
255
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
256
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
255
257
|
|
|
256
|
-
expect(getByTestId(
|
|
258
|
+
expect(getByTestId("text-input")).not.toHaveProp("multiline", "true");
|
|
257
259
|
});
|
|
258
260
|
});
|
|
259
261
|
|
|
260
|
-
describe(
|
|
261
|
-
it(
|
|
262
|
+
describe("disabled", () => {
|
|
263
|
+
it("renders correctly", () => {
|
|
262
264
|
const { toJSON, queryAllByTestId, queryAllByText, getByTestId } =
|
|
263
265
|
renderWithTheme(
|
|
264
266
|
<TextInput
|
|
@@ -271,17 +273,17 @@ describe('TextInput', () => {
|
|
|
271
273
|
);
|
|
272
274
|
|
|
273
275
|
expect(toJSON()).toMatchSnapshot();
|
|
274
|
-
expect(queryAllByText(
|
|
275
|
-
expect(queryAllByTestId(
|
|
276
|
-
expect(queryAllByTestId(
|
|
277
|
-
expect(getByTestId(
|
|
276
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
277
|
+
expect(queryAllByTestId("input-label")).toHaveLength(1);
|
|
278
|
+
expect(queryAllByTestId("text-input")).toHaveLength(1);
|
|
279
|
+
expect(getByTestId("disabled-text-input")).toBeDisabled();
|
|
278
280
|
|
|
279
|
-
expect(getByTestId(
|
|
281
|
+
expect(getByTestId("text-input")).not.toHaveProp("multiline", "true");
|
|
280
282
|
});
|
|
281
283
|
});
|
|
282
284
|
|
|
283
|
-
describe(
|
|
284
|
-
it(
|
|
285
|
+
describe("error", () => {
|
|
286
|
+
it("renders correctly", () => {
|
|
285
287
|
const { toJSON, queryAllByText } = renderWithTheme(
|
|
286
288
|
<TextInput
|
|
287
289
|
label="Amount (AUD)"
|
|
@@ -292,12 +294,12 @@ describe('TextInput', () => {
|
|
|
292
294
|
);
|
|
293
295
|
|
|
294
296
|
expect(toJSON()).toMatchSnapshot();
|
|
295
|
-
expect(queryAllByText(
|
|
296
|
-
expect(queryAllByText(
|
|
297
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
298
|
+
expect(queryAllByText("This field is required")).toHaveLength(1);
|
|
297
299
|
});
|
|
298
300
|
});
|
|
299
|
-
describe(
|
|
300
|
-
it(
|
|
301
|
+
describe("helper text", () => {
|
|
302
|
+
it("renders correctly", () => {
|
|
301
303
|
const { toJSON, queryAllByText } = renderWithTheme(
|
|
302
304
|
<TextInput
|
|
303
305
|
label="Amount (AUD)"
|
|
@@ -308,14 +310,14 @@ describe('TextInput', () => {
|
|
|
308
310
|
);
|
|
309
311
|
|
|
310
312
|
expect(toJSON()).toMatchSnapshot();
|
|
311
|
-
expect(queryAllByText(
|
|
312
|
-
expect(queryAllByText(
|
|
313
|
+
expect(queryAllByText("Amount (AUD)")).toHaveLength(1);
|
|
314
|
+
expect(queryAllByText("This is helper text")).toHaveLength(1);
|
|
313
315
|
});
|
|
314
316
|
});
|
|
315
317
|
|
|
316
|
-
describe(
|
|
317
|
-
describe(
|
|
318
|
-
it(
|
|
318
|
+
describe("placeholder", () => {
|
|
319
|
+
describe("TextInput is idle", () => {
|
|
320
|
+
it("renders correctly", () => {
|
|
319
321
|
const wrapper = renderWithTheme(
|
|
320
322
|
<TextInput
|
|
321
323
|
label="Amount (AUD)"
|
|
@@ -327,20 +329,20 @@ describe('TextInput', () => {
|
|
|
327
329
|
);
|
|
328
330
|
|
|
329
331
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
330
|
-
expect(wrapper.queryByPlaceholderText(
|
|
332
|
+
expect(wrapper.queryByPlaceholderText("Enter Amount")).toBeFalsy();
|
|
331
333
|
|
|
332
|
-
fireEvent(wrapper.getByTestId(
|
|
333
|
-
expect(wrapper.queryByPlaceholderText(
|
|
334
|
+
fireEvent(wrapper.getByTestId("text-input"), "focus");
|
|
335
|
+
expect(wrapper.queryByPlaceholderText("Enter Amount")).toBeTruthy();
|
|
334
336
|
|
|
335
|
-
fireEvent(wrapper.getByTestId(
|
|
336
|
-
expect(wrapper.queryByPlaceholderText(
|
|
337
|
+
fireEvent(wrapper.getByTestId("text-input"), "blur");
|
|
338
|
+
expect(wrapper.queryByPlaceholderText("Enter Amount")).toBeFalsy();
|
|
337
339
|
});
|
|
338
340
|
});
|
|
339
341
|
});
|
|
340
342
|
|
|
341
|
-
describe(
|
|
342
|
-
describe(
|
|
343
|
-
it(
|
|
343
|
+
describe("defaultValue", () => {
|
|
344
|
+
describe("TextInput is idle", () => {
|
|
345
|
+
it("renders correctly", () => {
|
|
344
346
|
const wrapper = renderWithTheme(
|
|
345
347
|
<TextInput
|
|
346
348
|
label="Amount (AUD)"
|
|
@@ -354,13 +356,13 @@ describe('TextInput', () => {
|
|
|
354
356
|
);
|
|
355
357
|
|
|
356
358
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
357
|
-
expect(wrapper.queryByDisplayValue(
|
|
358
|
-
expect(wrapper.queryByText(
|
|
359
|
+
expect(wrapper.queryByDisplayValue("1000")).toBeTruthy();
|
|
360
|
+
expect(wrapper.queryByText("4/255")).toBeTruthy();
|
|
359
361
|
});
|
|
360
362
|
});
|
|
361
363
|
|
|
362
|
-
describe(
|
|
363
|
-
it(
|
|
364
|
+
describe("default Value and Value", () => {
|
|
365
|
+
it("renders correctly with 2000", () => {
|
|
364
366
|
const wrapper = renderWithTheme(
|
|
365
367
|
<TextInput
|
|
366
368
|
label="Amount (AUD)"
|
|
@@ -375,9 +377,9 @@ describe('TextInput', () => {
|
|
|
375
377
|
);
|
|
376
378
|
|
|
377
379
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
378
|
-
expect(wrapper.queryByDisplayValue(
|
|
379
|
-
expect(wrapper.queryByDisplayValue(
|
|
380
|
-
expect(wrapper.queryByText(
|
|
380
|
+
expect(wrapper.queryByDisplayValue("2000")).toBeTruthy();
|
|
381
|
+
expect(wrapper.queryByDisplayValue("1000")).toBeFalsy();
|
|
382
|
+
expect(wrapper.queryByText("4/255")).toBeTruthy();
|
|
381
383
|
});
|
|
382
384
|
});
|
|
383
385
|
});
|