diff --git a/src/__tests__/testid-test.tsx b/src/__tests__/testid-test.tsx index 28617daf5..63c981c76 100644 --- a/src/__tests__/testid-test.tsx +++ b/src/__tests__/testid-test.tsx @@ -4,8 +4,12 @@ import {screen, render, within} from '@testing-library/react'; import { ButtonPrimary, ButtonSecondary, + Callout, DataCard, DateField, + Hero, + Image, + HighlightedCard, IconShopRegular, Meter, Placeholder, @@ -14,6 +18,10 @@ import { SuccessFeedbackScreen, TextField, ThemeContextProvider, + Tag, + CoverHero, + Header, + MainSectionHeader, } from '..'; import {makeTheme} from './test-utils'; @@ -101,6 +109,15 @@ test('Cards test ids', () => { ); }); +test('HighlightedCard test ids', () => { + checkTestIds(, [ + { + componentName: 'HighlightedCard', + internalTestIds: ['title', 'description', 'image'], + }, + ]); +}); + test('FeedbackScreen test ids', () => { checkTestIds( { ); }); +test('Callout test ids', () => { + checkTestIds( + } onClose={() => {}} />, + [ + { + componentName: 'Callout', + internalTestIds: ['title', 'description', 'asset', 'closeButton'], + }, + ] + ); +}); + +test('Hero test ids', () => { + checkTestIds( + } + headline={tag} + pretitle="pretitle" + title="title" + description="description" + button={button} + desktopMediaPosition="right" + extra={} + />, + [ + { + componentName: 'Hero', + internalTestIds: ['headline', 'pretitle', 'title', 'description', 'slot'], + }, + ] + ); +}); + +test('CoverHero test ids', () => { + checkTestIds( + tag} + pretitle="pretitle" + title="title" + description="description" + button={button} + extra={} + sideExtra={} + />, + [ + { + componentName: 'CoverHero', + internalTestIds: ['headline', 'pretitle', 'title', 'description', 'slot', 'sideSlot'], + }, + ] + ); +}); + +test('Header test ids', () => { + checkTestIds( +
tag} + pretitle="pretitle" + title="title" + description="description" + />, + [ + { + componentName: 'Header', + internalTestIds: ['headline', 'pretitle', 'title', 'description'], + }, + ] + ); +}); + +test('MainSectionHeader test ids', () => { + checkTestIds( + Action} + />, + [ + { + componentName: 'MainSectionHeader', + internalTestIds: ['title', 'description'], + }, + ] + ); +}); + test('Meter test ids', () => { checkTestIds(, [ { diff --git a/src/callout.tsx b/src/callout.tsx index 98d470992..f0bf97504 100644 --- a/src/callout.tsx +++ b/src/callout.tsx @@ -63,15 +63,24 @@ const Callout = ({ {...getPrefixedDataAttributes(dataAttributes, 'Callout')} > - {asset && {asset}} + {asset && ( + + {asset} + + )}
- + {title} - + {description} @@ -93,6 +102,7 @@ const Callout = ({ {onClose && (
( const mainContent = (
- {headline && {headline}} + {headline && ( + + {headline} + + )} {pretitle && (
- + {pretitle}
)} - + {title}
@@ -132,13 +149,14 @@ const CoverHero = React.forwardRef( truncate={descriptionLinesMax} color={hasMedia ? vars.colors.textPrimary : vars.colors.textSecondary} textShadow={textShadow} + dataAttributes={{testid: 'description'}} > {description}
)} - {extra} + {extra &&
{extra}
}
); @@ -180,7 +198,11 @@ const CoverHero = React.forwardRef( template="8+4" collapseBreakpoint="mobile" left={mainContent} - right={
{sideExtra}
} + right={ +
+ {sideExtra} +
+ } /> )} : undefined; + const image = imageUrl ? ( + + ) : undefined; const buttons: ButtonGroupProps = { ...(button?.type === ButtonPrimary ? {primaryButton: button} : {secondaryButton: button}), @@ -92,13 +94,21 @@ const EmptyState = ({ largeImageUrl ? styles.contentVariants.largeImage : styles.contentVariants.default } > - {image ?? (asset &&
{asset}
)} + {image ?? + (asset && ( +
+ {asset} +
+ ))} - {title} + + {title} + {description} @@ -115,6 +125,7 @@ const EmptyState = ({ width="100%" >
diff --git a/src/header.tsx b/src/header.tsx index 3c2b3743a..ff6a237eb 100644 --- a/src/header.tsx +++ b/src/header.tsx @@ -45,43 +45,60 @@ export const Header = ({ dataAttributes, small = false, }: HeaderProps): JSX.Element => { - const renderRichText = (richText: RichText, baseProps: Omit) => { - if (typeof richText === 'string') { - return ( - - {richText} - - ); + const renderPretitle = () => { + if (!pretitle) { + return null; } - const {text, ...textProps} = richText; + const baseTextProps = { + regular: true, + color: vars.colors.textPrimary, + as: pretitleAs, + dataAttributes: {testid: 'pretitle'}, + } as const; + + if (typeof pretitle === 'string') { + return {pretitle}; + } + const {text, ...textProps} = pretitle; return ( - - {richText.text} + + {text} ); }; return ( - + {(title || pretitle || description) && ( - {headline} - {pretitle && - renderRichText(pretitle, {color: vars.colors.textPrimary, as: pretitleAs})} + {headline &&
{headline}
} + {renderPretitle()} {title && (small ? ( - {title} + + {title} + ) : ( - {title} + + {title} + ))} {description && (small ? ( - + {description} ) : ( - + {description} ))} @@ -97,6 +114,7 @@ type MainSectionHeaderProps = { titleAs?: HeadingType; description?: string; button?: RendersNullableElement | RendersNullableElement; + dataAttributes?: DataAttributes; }; export const MainSectionHeader = ({ @@ -104,12 +122,23 @@ export const MainSectionHeader = ({ titleAs = 'h1', description, button, + dataAttributes, }: MainSectionHeaderProps): JSX.Element => { return ( - + - {title && {title}} - {description && {description}} + {title && ( + + {title} + + )} + {description && {description}} {button} @@ -154,7 +183,7 @@ export const HeaderLayout = ({ useSetOverscrollColor(isInverse ? {topColor: vars.colors.backgroundBrandTop} : {}); return ( -
+
- {headline && headline} + {headline &&
{headline}
} {pretitle && ( - + {pretitle} )} - {title && {title}} + {title && ( + + {title} + + )} {description && ( {description} )}
- {extra &&
{extra}
} + {extra &&
{extra}
}
{(button || buttonLink) && (
@@ -151,7 +156,7 @@ const Hero = React.forwardRef(
( return (
((props, ref) => { const content = ( @@ -94,6 +98,7 @@ const Content = React.forwardRef((props, ref) => { weight={textPresets.cardTitle.weight} as={titleAs} hyphens="auto" + dataAttributes={{testid: 'title'}} > {title} @@ -105,6 +110,7 @@ const Content = React.forwardRef((props, ref) => { truncate={descriptionLinesMax} as="p" hyphens="auto" + dataAttributes={{testid: 'description'}} > {description} @@ -119,6 +125,7 @@ const Content = React.forwardRef((props, ref) => {
{imageUrl && (