From d46648f30361244ea48c0c046d6d8d7c2f8c4f45 Mon Sep 17 00:00:00 2001 From: marcoskolodny Date: Thu, 17 Oct 2024 16:40:14 +0200 Subject: [PATCH 1/5] add some test ids --- src/button.tsx | 30 ++++++-- src/card.tsx | 132 ++++++++++++++++++++++++++++-------- src/feedback.tsx | 33 +++++++-- src/fixed-footer-layout.tsx | 1 + src/icon-button.tsx | 8 ++- src/list.tsx | 34 ++++++++-- src/utils/dom.tsx | 5 +- 7 files changed, 190 insertions(+), 53 deletions(-) diff --git a/src/button.tsx b/src/button.tsx index b3ae0b294a..f7fa2b9a52 100644 --- a/src/button.tsx +++ b/src/button.tsx @@ -176,6 +176,7 @@ const renderButtonContent = ({ alignItems: 'center', marginRight: styles.iconMargin, }} + data-testid="startIcon" > @@ -201,6 +202,7 @@ const renderButtonContent = ({ alignItems: 'center', marginLeft: styles.iconMargin, }} + data-testid="endIcon" > @@ -249,7 +251,11 @@ const renderButtonContent = ({ }} /> )} - {loadingText ? {loadingButtonElement} : null} + {loadingText ? ( + + {loadingButtonElement} + + ) : null} ); @@ -513,7 +519,7 @@ export const ButtonLink = React.forwardRef< >(({dataAttributes, className, ...props}, ref) => { return ( { return ( ( ({dataAttributes, ...props}, ref) => { return ( ( ({dataAttributes, ...props}, ref) => { return ( ( ({dataAttributes, ...props}, ref) => { return ( - + {finalActions.map((action, index) => { if ('Icon' in action || 'checkedProps' in action) { // action is a CardAction object @@ -406,7 +406,7 @@ const CardContent = ({ {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
{title && ( -
+
+
{typeof headline === 'string' ? {headline} : headline}
)} {pretitle && ( -
+
{pretitle}
)} {subtitle && ( -
+
{subtitle} @@ -445,6 +445,7 @@ const CardContent = ({ style={{ paddingTop: pretitle || title || subtitle ? 4 : 0, }} + data-testid="description" >
)} - {extra &&
{extra}
} + {extra && ( +
+ {extra} +
+ )}
{(button || buttonLink) && ( @@ -560,7 +565,7 @@ export const MediaCard = React.forwardRef( return ( ( style={applyCssVars({ [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > {asset}
@@ -659,7 +665,7 @@ export const NakedCard = React.forwardRef( return ( @@ -705,6 +711,7 @@ export const NakedCard = React.forwardRef( style={applyCssVars({ [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > {asset}
@@ -765,7 +772,11 @@ export const SmallNakedCard = React.forwardRef @@ -796,12 +807,19 @@ export const SmallNakedCard = React.forwardRef {title} )} {subtitle && ( - + {subtitle} )} @@ -812,13 +830,18 @@ export const SmallNakedCard = React.forwardRef {description} )}
- {extra &&
{extra}
} + {extra && ( +
+ {extra} +
+ )}
@@ -902,7 +925,7 @@ export const DataCard = React.forwardRef( return ( ( [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > {asset} @@ -954,7 +978,11 @@ export const DataCard = React.forwardRef( )}
- {extra &&
{extra}
} + {extra && ( +
+ {extra} +
+ )} {(button || buttonLink) && (
@@ -1023,13 +1051,18 @@ export const SnapCard = React.forwardRef( return ( - + ( style={applyCssVars({ [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > {asset}
@@ -1056,6 +1090,7 @@ export const SnapCard = React.forwardRef( weight={textPresets.cardTitle.weight} as={titleAs} hyphens="auto" + dataAttributes={{testid: 'title'}} > {title} @@ -1067,6 +1102,7 @@ export const SnapCard = React.forwardRef( color={vars.colors.textPrimary} as="p" hyphens="auto" + dataAttributes={{testid: 'subtitle'}} > {subtitle} @@ -1078,13 +1114,18 @@ export const SnapCard = React.forwardRef( color={vars.colors.textSecondary} as="p" hyphens="auto" + dataAttributes={{testid: 'description'}} > {description} )} - {extra &&
{extra}
} + {extra && ( +
+ {extra} +
+ )} @@ -1117,16 +1158,28 @@ const DisplayCardContent = ({ // using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users return (
- {title &&
{title}
} + {title && ( +
+ {title} +
+ )} {headline && ( // assuming that the headline will always be followed by one of: pretitle, title, subtitle, description -
+
{headline}
)} - {pretitle &&
{pretitle}
} + {pretitle && ( +
+ {pretitle} +
+ )} - {subtitle &&
{subtitle}
} + {subtitle && ( +
+ {subtitle} +
+ )} {description && ( // this is tricky, the padding between a headline and a description is 16px // but the padding between a title|pretitle|subtitle and a description is 8px (4px + 4px) @@ -1134,11 +1187,16 @@ const DisplayCardContent = ({ style={{ paddingTop: pretitle || title || subtitle ? 4 : 0, }} + data-testid="description" > {description}
)} - {extra &&
{extra}
} + {extra && ( +
+ {extra} +
+ )}
); }; @@ -1282,7 +1340,6 @@ const DisplayCard = React.forwardRef( className={styles.boxed} width="100%" minHeight="100%" - isInverse={isInverse} background={ hasImage || hasVideo ? isExternalInverse @@ -1290,7 +1347,7 @@ const DisplayCard = React.forwardRef( : vars.colors.backgroundContainer : undefined } - variant={hasImage || hasVideo ? 'media' : undefined} + variant={hasImage || hasVideo ? 'media' : isInverse ? 'inverse' : 'default'} > (
{(hasImage || hasVideo) && ( - +
{hasVideo ? video : image}
@@ -1321,6 +1378,7 @@ const DisplayCard = React.forwardRef( style={applyCssVars({ [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > {asset} @@ -1421,7 +1479,11 @@ export const DisplayMediaCard = React.forwardRef ) ); @@ -1431,7 +1493,11 @@ export const DisplayDataCard = React.forwardRef ) ); @@ -1573,7 +1639,7 @@ export const PosterCard = React.forwardRef( ( className={styles.boxed} width="100%" minHeight="100%" - isInverse={hasImage || hasVideo || normalizedVariant === 'inverse'} background={calcBackgroundColor()} - variant={hasImage || hasVideo ? 'media' : undefined} + variant={ + hasImage || hasVideo + ? 'media' + : hasImage || hasVideo || normalizedVariant === 'inverse' + ? 'inverse' + : 'default' + } > (
{(hasImage || hasVideo) && ( - +
{hasVideo ? video : image}
@@ -1619,6 +1690,7 @@ export const PosterCard = React.forwardRef( style={applyCssVars({ [mediaStyles.vars.mediaBorderRadius]: vars.borderRadii.mediaSmall, })} + data-testid="asset" > -
{asset}
+
+ {asset} +
-
+
{title}
{normalizedDescription && ( -
+
{normalizedDescription && ( {normalizedDescription} @@ -104,6 +109,7 @@ const renderFeedbackBody = ( ? styles.feedbackTextAppearSlow : styles.feedbackTextAppearMedium) )} + data-testid="slot" > {extra}
@@ -151,6 +157,7 @@ const renderFeedback = ({ {imageUrl && (
); }; @@ -321,7 +332,11 @@ export const ErrorFeedbackScreen = ({ hapticFeedback="error" asset={} animateText - dataAttributes={{'component-name': 'ErrorFeedbackScreen', ...dataAttributes}} + dataAttributes={{ + 'component-name': 'ErrorFeedbackScreen', + testid: 'ErrorFeedbackScreen', + ...dataAttributes, + }} extra={ {errorReference && ( @@ -346,7 +361,11 @@ export const InfoFeedbackScreen = ({ }: InfoFeedbackScreenProps): JSX.Element => { return ( } {...props} /> @@ -398,6 +417,6 @@ export const SuccessFeedback = ({ ), imageFit, imageUrl, - dataAttributes: {'component-name': 'SuccessFeedback', ...dataAttributes}, + dataAttributes: {'component-name': 'SuccessFeedback', testid: 'SuccessFeedback', ...dataAttributes}, }); }; diff --git a/src/fixed-footer-layout.tsx b/src/fixed-footer-layout.tsx index 62c1ad2df6..cda3ba1989 100644 --- a/src/fixed-footer-layout.tsx +++ b/src/fixed-footer-layout.tsx @@ -188,6 +188,7 @@ const FixedFooterLayout = ({