Skip to content

Commit 3cff486

Browse files
author
Paweł Kata
committed
feat(appbar): remove unnecessary derived testID
1 parent 4a8e6da commit 3cff486

4 files changed

Lines changed: 24 additions & 37 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ You can use the component's color prop where available, or override the correspo
7272

7373
Hardcoded default test IDs have been removed for the components listed below:
7474

75-
- `Appbar`: `${testID}-root-layer`
7675
- `BottomNavigation`: `bottom-navigation`
7776
- `BottomNavigation.Bar`: `bottom-navigation-bar`
7877
- `Button`: `button`
@@ -156,6 +155,10 @@ const MyComponent = () => (
156155

157156
Material Design 3 drops the bottom bar support contained previously in the `Appbar` scope and moves it to `Toolbars`, hence you can't use the component to construct a bottom bar anymore - for these cases please use the `Toolbar` component.
158157

158+
#### Test IDs
159+
160+
`Appbar` no longer derives internal, implementation-only test IDs (e.g. for its surface, content, or search layout wrappers) from the `testID` prop. Only the `testID` prop itself is set on the root element; the `Searchbar` rendered by the `search` variant accepts its own `testID` through `searchBar.testID`.
161+
159162
### Surface
160163

161164
- The `elevation` prop no longer accepts a React Native `Animated.Value`. Any `elevation` changes are animated automatically.

‎src/components/Appbar/Appbar.tsx‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,15 @@ const Appbar = ({
257257
const {
258258
inputStyle: _searchInputStyle,
259259
style: _searchStyle,
260-
testID: searchTestID = `${testID}-search`,
260+
testID: searchTestID,
261261
...searchProps
262262
} = searchBar;
263263

264264
return (
265265
<View style={styles.searchRow}>
266266
{renderLeadingButton()}
267-
<View testID={`${testID}-search-slot`} style={styles.searchSlot}>
268-
<View
269-
testID={`${testID}-search-width-limiter`}
270-
style={styles.searchWidthLimiter}
271-
>
267+
<View style={styles.searchSlot}>
268+
<View style={styles.searchWidthLimiter}>
272269
<Searchbar
273270
{...searchProps}
274271
aria-label={searchProps['aria-label'] ?? searchProps.placeholder}
@@ -302,7 +299,6 @@ const Appbar = ({
302299
onHeadlinePress,
303300
subtitle,
304301
subtitleProps,
305-
testID: `${testID}-content`,
306302
theme,
307303
variant,
308304
}
@@ -311,7 +307,6 @@ const Appbar = ({
311307
const renderFlexibleHeadlineImage = () =>
312308
headlineImage ? (
313309
<View
314-
testID={`${testID}-content-headline-image`}
315310
aria-hidden
316311
importantForAccessibility="no-hide-descendants"
317312
style={styles.flexibleHeadlineImage}
@@ -384,7 +379,6 @@ const Appbar = ({
384379
return (
385380
<Surface
386381
ref={ref}
387-
testID={`${testID}-root-layer`}
388382
elevation={0}
389383
backgroundColor={backgroundColor}
390384
theme={theme}

‎src/components/Appbar/AppbarContent.tsx‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type Props = Pick<
2626
theme: Theme;
2727
variant: AppbarHeadlineVariant;
2828
style?: StyleProp<ViewStyle>;
29-
testID: string;
3029
};
3130

3231
const headlineVariants: Record<AppbarHeadlineVariant, TypescaleKey> = {
@@ -57,7 +56,6 @@ const AppbarContent = ({
5756
onHeadlinePress,
5857
subtitle,
5958
subtitleProps,
60-
testID,
6159
theme,
6260
variant,
6361
style,
@@ -97,11 +95,7 @@ const AppbarContent = ({
9795
);
9896

9997
const content = hasHeadlineImage ? (
100-
<View
101-
testID={`${testID}-headline-image`}
102-
aria-hidden
103-
style={styles.headlineImage}
104-
>
98+
<View aria-hidden style={styles.headlineImage}>
10599
{headlineImage}
106100
</View>
107101
) : (
@@ -132,11 +126,6 @@ const AppbarContent = ({
132126
</>
133127
);
134128

135-
const wrapperProps = {
136-
testID,
137-
style: wrapperStyle,
138-
};
139-
140129
if (onHeadlinePress) {
141130
const {
142131
'aria-label': ariaLabel,
@@ -147,7 +136,7 @@ const AppbarContent = ({
147136

148137
return (
149138
<Pressable
150-
{...wrapperProps}
139+
style={wrapperStyle}
151140
{...restHeadlinePressableProps}
152141
role="button"
153142
aria-label={
@@ -170,7 +159,7 @@ const AppbarContent = ({
170159

171160
return (
172161
<View
173-
{...wrapperProps}
162+
style={wrapperStyle}
174163
accessible={hasHeadlineImage || undefined}
175164
accessibilityLabel={hasHeadlineImage ? headline : undefined}
176165
role={hasHeadlineImage ? 'heading' : undefined}

‎src/components/__tests__/Appbar/Appbar.test.tsx‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('Appbar content', () => {
169169
<Appbar variant="small" headline="Inbox" testID={testIDPrefix} />
170170
);
171171

172-
expect(screen.getByTestId('appbar-content')).toHaveStyle({
172+
expect(screen.getByText('Inbox').parent).toHaveStyle({
173173
marginStart: 12,
174174
});
175175

@@ -182,7 +182,7 @@ describe('Appbar content', () => {
182182
/>
183183
);
184184

185-
expect(screen.getByTestId('appbar-content')).toHaveStyle({
185+
expect(screen.getByText('Inbox').parent).toHaveStyle({
186186
marginStart: 4,
187187
});
188188
});
@@ -199,7 +199,7 @@ describe('Appbar content', () => {
199199
/>
200200
);
201201

202-
expect(screen.getByTestId('appbar-content')).toHaveStyle({
202+
expect(screen.getByText('Inbox').parent).toHaveStyle({
203203
flexBasis: 'auto',
204204
});
205205
}
@@ -213,7 +213,7 @@ describe('Appbar surface', () => {
213213
<Appbar variant="small" headline="Inbox" testID={testIDPrefix} />
214214
);
215215

216-
expect(screen.getByTestId('appbar-root-layer')).toHaveStyle({
216+
expect(screen.getByTestId(testIDPrefix).parent).toHaveStyle({
217217
backgroundColor: LightTheme.colors.surface,
218218
});
219219

@@ -226,7 +226,7 @@ describe('Appbar surface', () => {
226226
/>
227227
);
228228

229-
expect(screen.getByTestId('appbar-root-layer')).toHaveStyle({
229+
expect(screen.getByTestId(testIDPrefix).parent).toHaveStyle({
230230
backgroundColor: LightTheme.colors.surfaceContainer,
231231
});
232232

@@ -240,7 +240,7 @@ describe('Appbar surface', () => {
240240
/>
241241
);
242242

243-
expect(screen.getByTestId('appbar-root-layer')).toHaveStyle({
243+
expect(screen.getByTestId(testIDPrefix).parent).toHaveStyle({
244244
backgroundColor: customBackground,
245245
});
246246
});
@@ -267,7 +267,7 @@ describe('Appbar surface', () => {
267267
</SafeAreaProvider>
268268
);
269269

270-
expect(screen.getByTestId('appbar-root-layer')).toHaveStyle({
270+
expect(screen.getByTestId(testIDPrefix).parent).toHaveStyle({
271271
borderBottomLeftRadius: 16,
272272
borderBottomRightRadius: 16,
273273
paddingTop: 20,
@@ -468,7 +468,9 @@ describe('Appbar search', () => {
468468
expect(
469469
screen.getByRole('searchbox', { name: 'Search messages' })
470470
).toBeOnTheScreen();
471-
expect(screen.getByTestId('appbar-search').parent).toHaveStyle({
471+
expect(
472+
screen.getByRole('searchbox', { name: 'Search messages' }).parent
473+
).toHaveStyle({
472474
backgroundColor: LightTheme.colors.surfaceContainer,
473475
});
474476

@@ -549,7 +551,7 @@ describe('Appbar search', () => {
549551
expect(screen.getByTestId('message-search').parent).toHaveStyle({
550552
width: '100%',
551553
});
552-
expect(screen.getByTestId('appbar-search-width-limiter')).toHaveStyle({
554+
expect(screen.getByTestId('message-search').parent?.parent).toHaveStyle({
553555
width: '100%',
554556
maxWidth: 720,
555557
});
@@ -750,10 +752,9 @@ describe('Appbar accessibility', () => {
750752
)
751753
);
752754

753-
const imageContainer = screen.getByTestId(
754-
'appbar-content-headline-image',
755-
{ includeHiddenElements: true }
756-
);
755+
const imageContainer = screen.getByLabelText('Brand artwork', {
756+
includeHiddenElements: true,
757+
}).parent?.parent;
757758

758759
expect(imageContainer).toHaveProp('aria-hidden', true);
759760
expect(

0 commit comments

Comments
 (0)