Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions docs/6.x/docs/guides/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,61 @@ You can use the component's color prop where available, or override the correspo

### Test IDs

Some hardcoded and generated test IDs have been removed for the following components:

- `Appbar.Header`: `${testID}-root-layer`
- `Surface`: `surface` and `${testID}-outer-layer`

You can specify a `testID` explicitly and use that value to query the component.
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:

- `Appbar.Content`: `appbar-content`
- `appbar-content-title-text`
- `Appbar.Header`: `appbar-header`
- `appbar-header-root-layer`
- `BottomNavigation`: `bottom-navigation`
- `bottom-navigation-bar`
- `BottomNavigation.Bar`: `bottom-navigation-bar`
- `bottom-navigation-bar-content`
- `bottom-navigation-bar-content-wrapper`
- `Button`: `button`
- `button-container`
- `button-icon-container`
- `button-text`
- `Card`: `card`
- `card-container`
- `card-outline`
- `Chip`: `chip`
- `chip-container`
- `Drawer.CollapsedItem`: `drawer-collapsed-item`
- `drawer-collapsed-item-outline`
- `drawer-collapsed-item-container`
- `FAB`: `floating-action-button`
- `floating-action-button-container`
- `floating-action-button-text`
- `FAB.Extended`: `extended-floating-action-button`
- `extended-floating-action-button-container`
- `extended-floating-action-button-text`
- `FAB.Menu`: `floating-action-button-menu`
- `IconButton`: `icon-button`
- `icon-button-container`
- `icon-button-icon` (and `icon-button-icon-previous` / `icon-button-icon-current` when `animated`)
- `Menu`: `menu`
- `menu-view`
- `menu-surface`
- `Menu.Item`: `menu-item`
- `menu-item-title`
- `Modal`: `modal`
- `modal-backdrop`
- `modal-wrapper`
- `modal-surface`
- `ProgressBar`: `progress-bar`
- `progress-bar-fill`
- `Searchbar`: `search-bar`
- `search-bar-container`
- `search-bar-icon`
- `search-bar-icon-wrapper`
- `search-bar-clear-icon`
- `search-bar-trailering-icon`
- `search-bar-divider`
- `Surface`: `surface`
- `surface-outer-layer`

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.

## Components

Expand Down
4 changes: 2 additions & 2 deletions src/components/Appbar/AppbarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const AppbarContent = ({
titleMaxFontSizeMultiplier,
mode = 'small',
theme: themeOverrides,
testID = 'appbar-content',
testID,
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
Expand Down Expand Up @@ -135,7 +135,7 @@ const AppbarContent = ({
numberOfLines={1}
accessible
role={onPress ? 'none' : 'heading'}
testID={`${testID}-title-text`}
testID={testID ? `${testID}-title-text` : undefined}
maxFontSizeMultiplier={titleMaxFontSizeMultiplier}
>
{title}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Appbar/AppbarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const AppbarHeader = ({
mode = Platform.OS === 'ios' ? 'center-aligned' : 'small',
elevated = false,
theme: themeOverrides,
testID = 'appbar-header',
testID,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removed defaults need a bullet in the migration guide's "Test IDs" section (docs/6.x/docs/guides/migration.md) —- it already lists the ones Surface and Appbar.Header lost. Otherwise anyone selecting button, card or search-bar in their e2e tests loses those matches silently.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Added information to migration guide.

...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
Expand Down
4 changes: 2 additions & 2 deletions src/components/BottomNavigation/BottomNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const BottomNavigation = <Route extends BaseRoute>({
safeAreaInsets,
labelMaxFontSizeMultiplier = 1,
compact: compactProp,
testID = 'bottom-navigation',
testID,
theme: themeOverrides,
getLazy = ({ route }: { route: Route }) => route.lazy,
}: Props<Route>) => {
Expand Down Expand Up @@ -579,7 +579,7 @@ const BottomNavigation = <Route extends BaseRoute>({
safeAreaInsets={safeAreaInsets}
labelMaxFontSizeMultiplier={labelMaxFontSizeMultiplier}
compact={compact}
testID={`${testID}-bar`}
testID={testID ? `${testID}-bar` : undefined}
theme={theme}
/>
</View>
Expand Down
6 changes: 3 additions & 3 deletions src/components/BottomNavigation/BottomNavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
safeAreaInsets,
labelMaxFontSizeMultiplier = 1,
compact: compactProp,
testID = 'bottom-navigation-bar',
testID,
theme: themeOverrides,
}: Props<Route>) => {
const theme = useInternalTheme(themeOverrides);
Expand Down Expand Up @@ -495,7 +495,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
>
<Animated.View
style={[styles.barContent, { backgroundColor }]}
testID={`${testID}-content`}
testID={testID ? `${testID}-content` : undefined}
>
<View
style={[
Expand All @@ -509,7 +509,7 @@ const BottomNavigationBar = <Route extends BaseRoute>({
},
]}
role={'tablist'}
testID={`${testID}-content-wrapper`}
testID={testID ? `${testID}-content-wrapper` : undefined}
>
{routes.map((route, index) => {
const focused = navigationState.index === index;
Expand Down
11 changes: 7 additions & 4 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const Button = ({
uppercase: uppercaseProp,
contentStyle,
labelStyle,
testID = 'button',
testID,
accessible,
background,
maxFontSizeMultiplier,
Expand Down Expand Up @@ -292,7 +292,7 @@ const Button = ({
<Surface
{...rest}
ref={ref}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}
backgroundColor={backgroundOpacity < 1 ? 'transparent' : backgroundColor}
{...touchableStyle}
style={[
Expand Down Expand Up @@ -342,7 +342,10 @@ const Button = ({
>
<View style={[styles.content, { opacity: textOpacity }, contentStyle]}>
{icon && loading !== true ? (
<View style={iconStyle} testID={`${testID}-icon-container`}>
<View
style={iconStyle}
testID={testID ? `${testID}-icon-container` : undefined}
>
<Icon
source={icon}
size={customLabelSize ?? iconSize}
Expand All @@ -369,7 +372,7 @@ const Button = ({
variant="labelLarge"
selectable={false}
numberOfLines={1}
testID={`${testID}-text`}
testID={testID ? `${testID}-text` : undefined}
style={[
styles.label,
isMode('text')
Expand Down
6 changes: 3 additions & 3 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const Card = ({
style,
contentStyle,
theme: themeOverrides,
testID = 'card',
testID,
accessible,
disabled,
ref,
Expand Down Expand Up @@ -225,13 +225,13 @@ const Card = ({
style={[{ borderColor }, style]}
theme={theme}
elevation={elevation}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Five other components build child testIDs without this guard, so they render a literal
undefined-text - visible in the committed snapshots today. Checkbox/CheckboxItem.tsx:177, DataTable/DataTableCell.tsx:111, List/ListItem.tsx:245, SegmentedButtons/SegmentedButtonItem.tsx:227 and Snackbar.tsx:341. Worth including them?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed them, included in the new commit.

{...rest}
>
{isMode('outlined') && (
<View
pointerEvents="none"
testID={`${testID}-outline`}
testID={testID ? `${testID}-outline` : undefined}
style={[
{
borderColor,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Checkbox/CheckboxItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const CheckboxItem = ({
{isLeading && checkbox}
<Text
variant={labelVariant}
testID={`${testID}-text`}
testID={testID ? `${testID}-text` : undefined}
maxFontSizeMultiplier={labelMaxFontSizeMultiplier}
style={[styles.label, computedStyle, labelStyle]}
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const Chip = ({
textStyle,
style,
theme: themeOverrides,
testID = 'chip',
testID,
selectedColor,
showSelectedCheck = true,
ellipsizeMode,
Expand Down Expand Up @@ -280,7 +280,7 @@ const Chip = ({
elevation={elevation}
transitionDuration={elevationTransitionDuration}
{...rest}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}
theme={theme}
>
<TouchableRipple
Expand Down
6 changes: 3 additions & 3 deletions src/components/CrossFadeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CrossFadeIcon = ({
size,
source,
theme: themeOverrides,
testID = 'cross-fade-icon',
testID,
}: Props) => {
const theme = useInternalTheme(themeOverrides);

Expand Down Expand Up @@ -109,14 +109,14 @@ const CrossFadeIcon = ({
{hasPreviousIcon ? (
<Animated.View
style={[styles.icon, previousIconStyle]}
testID={`${testID}-previous`}
testID={testID ? `${testID}-previous` : undefined}
>
<Icon source={previousIcon} size={size} color={color} theme={theme} />
</Animated.View>
) : null}
<Animated.View
style={[styles.icon, currentIconStyle]}
testID={`${testID}-current`}
testID={testID ? `${testID}-current` : undefined}
>
<Icon source={currentIcon} size={size} color={color} theme={theme} />
</Animated.View>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataTable/DataTableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const CellContent = ({
style={textStyle}
numberOfLines={1}
maxFontSizeMultiplier={maxFontSizeMultiplier}
testID={`${testID}-text-container`}
testID={testID ? `${testID}-text-container` : undefined}
>
{children}
</Text>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Drawer/DrawerCollapsedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const DrawerCollapsedItem = ({
disabled,
'aria-label': ariaLabel,
badge = false,
testID = 'drawer-collapsed-item',
testID,
labelMaxFontSizeMultiplier,
...rest
}: Props) => {
Expand Down Expand Up @@ -195,12 +195,12 @@ const DrawerCollapsedItem = ({
style,
animatedOutlineStyle,
]}
testID={`${testID}-outline`}
testID={testID ? `${testID}-outline` : undefined}
/>

<View
style={[styles.icon, { top: iconPadding }]}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}
>
{badge !== false && (
<View style={styles.badgeContainer}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FAB/Extended.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const Extended = ({
labelMaxFontSizeMultiplier,
background,
style,
testID = 'extended-floating-action-button',
testID,
theme: themeOverrides,
ref,
}: Props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FAB/FAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const FAB = ({
'aria-expanded': ariaExpanded,
background,
style,
testID = 'floating-action-button',
testID,
theme,
ref,
}: Props) => (
Expand Down
4 changes: 2 additions & 2 deletions src/components/FAB/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ const MorphingTrigger = ({
},
visible ? styles.pointerEventsBoxNone : styles.pointerEventsNone,
]}
testID={testID}
>
<Shell
size={size}
Expand All @@ -456,6 +455,7 @@ const MorphingTrigger = ({
visible={visible}
onPress={onPress}
aria-label={ariaLabel}
testID={testID}
widthShared={widthShared}
heightShared={heightShared}
borderRadiusShared={borderRadiusShared}
Expand Down Expand Up @@ -537,7 +537,7 @@ const Menu = ({
alignment = 'end',
closeIcon = 'close',
items,
testID = 'floating-action-button-menu',
testID,
theme: themeOverrides,
}: MenuProps) => {
const theme = useInternalTheme(themeOverrides);
Expand Down
4 changes: 2 additions & 2 deletions src/components/FAB/Shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const Shell = ({
overlay,
children,
style,
testID = 'fab-shell',
testID,
theme: themeOverrides,
ref,
}: ShellProps) => {
Expand Down Expand Up @@ -319,7 +319,7 @@ const Shell = ({
visible ? styles.pointerEventsAuto : styles.pointerEventsNone,
]}
elevation={elevation}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}
theme={theme}
>
<Animated.View style={[styles.clip, clipStyle]}>
Expand Down
11 changes: 8 additions & 3 deletions src/components/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const IconButton = ({
mode,
style,
theme: themeOverrides,
testID = 'icon-button',
testID,
loading = false,
contentStyle,
ref,
Expand Down Expand Up @@ -157,7 +157,7 @@ const IconButton = ({
return (
<Animated.View
ref={ref}
testID={`${testID}-container`}
testID={testID ? `${testID}-container` : undefined}
style={[
styles.container,
{
Expand Down Expand Up @@ -199,7 +199,12 @@ const IconButton = ({
{loading ? (
<ActivityIndicator size={size} color={iconColor} />
) : (
<IconComponent color={iconColor} source={icon} size={size} />
<IconComponent
color={iconColor}
source={icon}
size={size}
testID={testID ? `${testID}-icon` : undefined}
/>
)}
</View>
</TouchableRipple>
Expand Down
2 changes: 1 addition & 1 deletion src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const ListItem = ({
: null}
<View
style={[styles.item, styles.content, contentStyle]}
testID={`${testID}-content`}
testID={testID ? `${testID}-content` : undefined}
>
{renderTitle()}

Expand Down
Loading