Skip to content

Commit cbcd52f

Browse files
authored
fix: remove hardcoded default testIDs from components (#5088)
1 parent 1e7082b commit cbcd52f

54 files changed

Lines changed: 164 additions & 399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/6.x/docs/guides/migration.md‎

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,61 @@ You can use the component's color prop where available, or override the correspo
7171

7272
### Test IDs
7373

74-
Some hardcoded and generated test IDs have been removed for the following components:
75-
76-
- `Appbar.Header`: `${testID}-root-layer`
77-
- `Surface`: `surface` and `${testID}-outer-layer`
78-
79-
You can specify a `testID` explicitly and use that value to query the component.
74+
Hardcoded default test IDs have been removed for the components listed below. Many of these components also derive test IDs for their internal parts by appending a suffix to the `testID` prop (e.g. `${testID}-container`). Since `testID` is no longer defaulted to a hardcoded value, none of these derived test IDs are set either unless you pass a `testID` explicitly — so all queries by the IDs below will stop matching:
75+
76+
- `Appbar.Content`: `appbar-content`
77+
- `appbar-content-title-text`
78+
- `Appbar.Header`: `appbar-header`
79+
- `appbar-header-root-layer`
80+
- `BottomNavigation`: `bottom-navigation`
81+
- `bottom-navigation-bar`
82+
- `BottomNavigation.Bar`: `bottom-navigation-bar`
83+
- `bottom-navigation-bar-content`
84+
- `bottom-navigation-bar-content-wrapper`
85+
- `Button`: `button`
86+
- `button-container`
87+
- `button-icon-container`
88+
- `button-text`
89+
- `Card`: `card`
90+
- `card-container`
91+
- `card-outline`
92+
- `Chip`: `chip`
93+
- `chip-container`
94+
- `Drawer.CollapsedItem`: `drawer-collapsed-item`
95+
- `drawer-collapsed-item-outline`
96+
- `drawer-collapsed-item-container`
97+
- `FAB`: `floating-action-button`
98+
- `floating-action-button-container`
99+
- `floating-action-button-text`
100+
- `FAB.Extended`: `extended-floating-action-button`
101+
- `extended-floating-action-button-container`
102+
- `extended-floating-action-button-text`
103+
- `FAB.Menu`: `floating-action-button-menu`
104+
- `IconButton`: `icon-button`
105+
- `icon-button-container`
106+
- `icon-button-icon` (and `icon-button-icon-previous` / `icon-button-icon-current` when `animated`)
107+
- `Menu`: `menu`
108+
- `menu-view`
109+
- `menu-surface`
110+
- `Menu.Item`: `menu-item`
111+
- `menu-item-title`
112+
- `Modal`: `modal`
113+
- `modal-backdrop`
114+
- `modal-wrapper`
115+
- `modal-surface`
116+
- `ProgressBar`: `progress-bar`
117+
- `progress-bar-fill`
118+
- `Searchbar`: `search-bar`
119+
- `search-bar-container`
120+
- `search-bar-icon`
121+
- `search-bar-icon-wrapper`
122+
- `search-bar-clear-icon`
123+
- `search-bar-trailering-icon`
124+
- `search-bar-divider`
125+
- `Surface`: `surface`
126+
- `surface-outer-layer`
127+
128+
You can specify a `testID` explicitly to restore both the component's own test ID and all of its derived test IDs above, using the same suffixes.
80129

81130
## Components
82131

‎src/components/Appbar/AppbarContent.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const AppbarContent = ({
9595
titleMaxFontSizeMultiplier,
9696
mode = 'small',
9797
theme: themeOverrides,
98-
testID = 'appbar-content',
98+
testID,
9999
...rest
100100
}: Props) => {
101101
const theme = useInternalTheme(themeOverrides);
@@ -135,7 +135,7 @@ const AppbarContent = ({
135135
numberOfLines={1}
136136
accessible
137137
role={onPress ? 'none' : 'heading'}
138-
testID={`${testID}-title-text`}
138+
testID={testID ? `${testID}-title-text` : undefined}
139139
maxFontSizeMultiplier={titleMaxFontSizeMultiplier}
140140
>
141141
{title}

‎src/components/Appbar/AppbarHeader.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const AppbarHeader = ({
8585
mode = Platform.OS === 'ios' ? 'center-aligned' : 'small',
8686
elevated = false,
8787
theme: themeOverrides,
88-
testID = 'appbar-header',
88+
testID,
8989
...rest
9090
}: Props) => {
9191
const theme = useInternalTheme(themeOverrides);

‎src/components/BottomNavigation/BottomNavigation.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ const BottomNavigation = <Route extends BaseRoute>({
335335
safeAreaInsets,
336336
labelMaxFontSizeMultiplier = 1,
337337
compact: compactProp,
338-
testID = 'bottom-navigation',
338+
testID,
339339
theme: themeOverrides,
340340
getLazy = ({ route }: { route: Route }) => route.lazy,
341341
}: Props<Route>) => {
@@ -579,7 +579,7 @@ const BottomNavigation = <Route extends BaseRoute>({
579579
safeAreaInsets={safeAreaInsets}
580580
labelMaxFontSizeMultiplier={labelMaxFontSizeMultiplier}
581581
compact={compact}
582-
testID={`${testID}-bar`}
582+
testID={testID ? `${testID}-bar` : undefined}
583583
theme={theme}
584584
/>
585585
</View>

‎src/components/BottomNavigation/BottomNavigationBar.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
323323
safeAreaInsets,
324324
labelMaxFontSizeMultiplier = 1,
325325
compact: compactProp,
326-
testID = 'bottom-navigation-bar',
326+
testID,
327327
theme: themeOverrides,
328328
}: Props<Route>) => {
329329
const theme = useInternalTheme(themeOverrides);
@@ -495,7 +495,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
495495
>
496496
<Animated.View
497497
style={[styles.barContent, { backgroundColor }]}
498-
testID={`${testID}-content`}
498+
testID={testID ? `${testID}-content` : undefined}
499499
>
500500
<View
501501
style={[
@@ -509,7 +509,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
509509
},
510510
]}
511511
role={'tablist'}
512-
testID={`${testID}-content-wrapper`}
512+
testID={testID ? `${testID}-content-wrapper` : undefined}
513513
>
514514
{routes.map((route, index) => {
515515
const focused = navigationState.index === index;

‎src/components/Button/Button.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const Button = ({
184184
uppercase: uppercaseProp,
185185
contentStyle,
186186
labelStyle,
187-
testID = 'button',
187+
testID,
188188
accessible,
189189
background,
190190
maxFontSizeMultiplier,
@@ -292,7 +292,7 @@ const Button = ({
292292
<Surface
293293
{...rest}
294294
ref={ref}
295-
testID={`${testID}-container`}
295+
testID={testID ? `${testID}-container` : undefined}
296296
backgroundColor={backgroundOpacity < 1 ? 'transparent' : backgroundColor}
297297
{...touchableStyle}
298298
style={[
@@ -342,7 +342,10 @@ const Button = ({
342342
>
343343
<View style={[styles.content, { opacity: textOpacity }, contentStyle]}>
344344
{icon && loading !== true ? (
345-
<View style={iconStyle} testID={`${testID}-icon-container`}>
345+
<View
346+
style={iconStyle}
347+
testID={testID ? `${testID}-icon-container` : undefined}
348+
>
346349
<Icon
347350
source={icon}
348351
size={customLabelSize ?? iconSize}
@@ -369,7 +372,7 @@ const Button = ({
369372
variant="labelLarge"
370373
selectable={false}
371374
numberOfLines={1}
372-
testID={`${testID}-text`}
375+
testID={testID ? `${testID}-text` : undefined}
373376
style={[
374377
styles.label,
375378
isMode('text')

‎src/components/Card/Card.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const Card = ({
141141
style,
142142
contentStyle,
143143
theme: themeOverrides,
144-
testID = 'card',
144+
testID,
145145
accessible,
146146
disabled,
147147
ref,
@@ -225,13 +225,13 @@ const Card = ({
225225
style={[{ borderColor }, style]}
226226
theme={theme}
227227
elevation={elevation}
228-
testID={`${testID}-container`}
228+
testID={testID ? `${testID}-container` : undefined}
229229
{...rest}
230230
>
231231
{isMode('outlined') && (
232232
<View
233233
pointerEvents="none"
234-
testID={`${testID}-outline`}
234+
testID={testID ? `${testID}-outline` : undefined}
235235
style={[
236236
{
237237
borderColor,

‎src/components/Checkbox/CheckboxItem.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const CheckboxItem = ({
174174
{isLeading && checkbox}
175175
<Text
176176
variant={labelVariant}
177-
testID={`${testID}-text`}
177+
testID={testID ? `${testID}-text` : undefined}
178178
maxFontSizeMultiplier={labelMaxFontSizeMultiplier}
179179
style={[styles.label, computedStyle, labelStyle]}
180180
>

‎src/components/Chip/Chip.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const Chip = ({
196196
textStyle,
197197
style,
198198
theme: themeOverrides,
199-
testID = 'chip',
199+
testID,
200200
selectedColor,
201201
showSelectedCheck = true,
202202
ellipsizeMode,
@@ -281,7 +281,7 @@ const Chip = ({
281281
elevation={elevation}
282282
transitionDuration={elevationTransitionDuration}
283283
{...rest}
284-
testID={`${testID}-container`}
284+
testID={testID ? `${testID}-container` : undefined}
285285
theme={theme}
286286
>
287287
<TouchableRipple

‎src/components/CrossFadeIcon.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const CrossFadeIcon = ({
4444
size,
4545
source,
4646
theme: themeOverrides,
47-
testID = 'cross-fade-icon',
47+
testID,
4848
}: Props) => {
4949
const theme = useInternalTheme(themeOverrides);
5050

@@ -109,14 +109,14 @@ const CrossFadeIcon = ({
109109
{hasPreviousIcon ? (
110110
<Animated.View
111111
style={[styles.icon, previousIconStyle]}
112-
testID={`${testID}-previous`}
112+
testID={testID ? `${testID}-previous` : undefined}
113113
>
114114
<Icon source={previousIcon} size={size} color={color} theme={theme} />
115115
</Animated.View>
116116
) : null}
117117
<Animated.View
118118
style={[styles.icon, currentIconStyle]}
119-
testID={`${testID}-current`}
119+
testID={testID ? `${testID}-current` : undefined}
120120
>
121121
<Icon source={currentIcon} size={size} color={color} theme={theme} />
122122
</Animated.View>

0 commit comments

Comments
 (0)