-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Rows, Cards, FeedbackScreen, FormFields, Buttons): add test ids for components and their internal elements #1270
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import * as React from 'react'; | ||
import {RowList, Row} from '../list'; | ||
import {screen, render, within} from '@testing-library/react'; | ||
import { | ||
ButtonPrimary, | ||
ButtonSecondary, | ||
DataCard, | ||
DateField, | ||
IconShopRegular, | ||
Placeholder, | ||
SearchField, | ||
Stack, | ||
SuccessFeedbackScreen, | ||
TextField, | ||
ThemeContextProvider, | ||
} from '..'; | ||
import {makeTheme} from './test-utils'; | ||
|
||
const checkTestIds = ( | ||
content: React.ReactElement, | ||
elements: ReadonlyArray<{componentName: string; internalTestIds: ReadonlyArray<string>}> | ||
) => { | ||
render(<ThemeContextProvider theme={makeTheme()}>{content}</ThemeContextProvider>); | ||
|
||
elements.forEach(({componentName, internalTestIds}) => { | ||
const element = screen.getByTestId(componentName); | ||
expect(element).toBeInTheDocument(); | ||
|
||
internalTestIds.forEach((id) => expect(within(element).getByTestId(id)).toBeInTheDocument()); | ||
}); | ||
}; | ||
|
||
test('Row test ids', () => { | ||
checkTestIds( | ||
<RowList> | ||
<Row | ||
title="Title" | ||
headline="Headline" | ||
subtitle="Subtitle" | ||
description="Description" | ||
detail="Detail" | ||
asset={<IconShopRegular />} | ||
extra={<Placeholder />} | ||
right="right" | ||
href="#" | ||
/> | ||
</RowList>, | ||
[ | ||
{ | ||
componentName: 'Row', | ||
internalTestIds: [ | ||
'headline', | ||
'title', | ||
'subtitle', | ||
'description', | ||
'detail', | ||
'asset', | ||
'slot', | ||
'chevron', | ||
'endSlot', | ||
], | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
test('Cards test ids', () => { | ||
checkTestIds( | ||
<DataCard | ||
headline="Headline" | ||
pretitle="Pretitle" | ||
title="Title" | ||
subtitle="Subtitle" | ||
description="Description" | ||
extra={<Placeholder />} | ||
asset={<IconShopRegular />} | ||
actions={[ | ||
{ | ||
Icon: IconShopRegular, | ||
onPress: () => {}, | ||
label: 'Lightning', | ||
}, | ||
]} | ||
/>, | ||
[ | ||
{ | ||
componentName: 'DataCard', | ||
internalTestIds: [ | ||
'headline', | ||
'pretitle', | ||
'title', | ||
'subtitle', | ||
'description', | ||
'asset', | ||
'topActions', | ||
'slot', | ||
], | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
test('FeedbackScreen test ids', () => { | ||
checkTestIds( | ||
<SuccessFeedbackScreen | ||
title="Title" | ||
description="Description" | ||
extra={<Placeholder />} | ||
primaryButton={<ButtonPrimary onPress={() => {}}>Action</ButtonPrimary>} | ||
imageUrl="https://picsum.photos/1200/1200" | ||
/>, | ||
[ | ||
{ | ||
componentName: 'SuccessFeedbackScreen', | ||
internalTestIds: ['icon', 'title', 'description', 'image', 'slot'], | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
test('InputFields test ids', () => { | ||
checkTestIds( | ||
<Stack space={16}> | ||
<TextField | ||
name="textField" | ||
label="Label 1" | ||
helperText="Helper" | ||
multiline | ||
maxLength={200} | ||
endIcon={<IconShopRegular />} | ||
/> | ||
<SearchField name="searchField" label="Label 2" helperText="helperText" error /> | ||
<DateField name="dateField" label="Label 3" /> | ||
</Stack>, | ||
|
||
[ | ||
{ | ||
componentName: 'TextField', | ||
internalTestIds: ['label', 'helperText', 'endHelperText', 'endIcon'], | ||
}, | ||
{ | ||
componentName: 'SearchField', | ||
internalTestIds: ['startIcon', 'errorText'], | ||
}, | ||
// In DateField/MonthField/DatetimeField, we use endIconOverlay for setting the endIcon | ||
{ | ||
componentName: 'DateField', | ||
internalTestIds: ['endIcon'], | ||
}, | ||
] | ||
); | ||
}); | ||
|
||
test('Buttons test ids', () => { | ||
checkTestIds( | ||
<Stack space={16}> | ||
<ButtonPrimary StartIcon={IconShopRegular} EndIcon={IconShopRegular} onPress={() => {}}> | ||
Action | ||
</ButtonPrimary> | ||
<ButtonSecondary loadingText="Loading text" showSpinner onPress={() => {}}> | ||
Action 2 | ||
</ButtonSecondary> | ||
</Stack>, | ||
[ | ||
{ | ||
componentName: 'ButtonPrimary', | ||
internalTestIds: ['startIcon', 'endIcon'], | ||
}, | ||
{ | ||
componentName: 'ButtonSecondary', | ||
internalTestIds: ['loadingText'], | ||
}, | ||
] | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ export const InternalBoxed = React.forwardRef<HTMLDivElement, Props & InternalPr | |
( | ||
{ | ||
children, | ||
isInverse: isInverseInside = false, | ||
isInverse = false, | ||
className, | ||
role, | ||
dataAttributes, | ||
|
@@ -90,6 +90,7 @@ export const InternalBoxed = React.forwardRef<HTMLDivElement, Props & InternalPr | |
ref | ||
) => { | ||
const isInverseOutside = useIsInverseOrMediaVariant(); | ||
const isInverseInside = isInverse || variant === 'inverse' || variant === 'media'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated, but Boxed was not working properly when using media variant |
||
|
||
return ( | ||
<div | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, but camelCase is not correct here