From d620f9fbdbafe48850d76869d40e9f8bff653072 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Fri, 20 Sep 2024 14:43:51 +0100 Subject: [PATCH] fix flexible general stories --- .../src/components/FlexibleGeneral.test.tsx | 13 ++++++ .../src/components/FlexibleGeneral.tsx | 41 ++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/dotcom-rendering/src/components/FlexibleGeneral.test.tsx b/dotcom-rendering/src/components/FlexibleGeneral.test.tsx index 38160153f7..2bac862622 100644 --- a/dotcom-rendering/src/components/FlexibleGeneral.test.tsx +++ b/dotcom-rendering/src/components/FlexibleGeneral.test.tsx @@ -32,6 +32,19 @@ describe('FlexibleGeneral', () => { ]); }); + it('Should return a one card row layout if one card without boost level is provided', () => { + const cardWithoutBoostLevel = { + ...standardCard, + boostLevel: undefined, + }; + expect(decideCardPositions([cardWithoutBoostLevel])).toEqual([ + { + layout: 'oneCard', + cards: [cardWithoutBoostLevel], + }, + ]); + }); + it('Should return two rows of two card row layouts if four standard cards are provided', () => { expect( decideCardPositions([ diff --git a/dotcom-rendering/src/components/FlexibleGeneral.tsx b/dotcom-rendering/src/components/FlexibleGeneral.tsx index 05b7a2f513..c0926ef7e3 100644 --- a/dotcom-rendering/src/components/FlexibleGeneral.tsx +++ b/dotcom-rendering/src/components/FlexibleGeneral.tsx @@ -46,7 +46,7 @@ export const decideCardPositions = (cards: DCRFrontCard[]): GroupedCards => { return cards.reduce((acc, card) => { // Early return if the card is boosted since it takes up a whole row - if (card.boostLevel !== 'default') { + if (card.boostLevel && card.boostLevel !== 'default') { return [...acc, createNewRow('oneCardBoosted', card)]; } @@ -64,11 +64,7 @@ export const decideCardPositions = (cards: DCRFrontCard[]): GroupedCards => { }, []); }; -/** - * Boosting a splash card will affect the layout and style of the card. This function will determine the properties of the card based on the boost level. - */ - -type boostedSplashProperties = { +type BoostedSplashProperties = { headlineSize: SmallHeadlineSize; headlineSizeOnMobile: SmallHeadlineSize; headlineSizeOnTablet: SmallHeadlineSize; @@ -76,10 +72,13 @@ type boostedSplashProperties = { imagePositionOnMobile: ImagePositionType; supportingContentAlignment: Alignment; }; + +/** + * Boosting a splash card will affect the layout and style of the card. This function will determine the properties of the card based on the boost level. + */ const decideSplashCardProperties = ( boostLevel: BoostLevel = 'default', - supportingContentLength: number, -): boostedSplashProperties => { +): BoostedSplashProperties => { switch (boostLevel) { // The default boost level is equal to no boost. It is the same as the default card layout. case 'default': @@ -89,8 +88,7 @@ const decideSplashCardProperties = ( headlineSizeOnTablet: 'tiny', imagePositionOnDesktop: 'right', imagePositionOnMobile: 'bottom', - supportingContentAlignment: - supportingContentLength >= 4 ? 'horizontal' : 'vertical', + supportingContentAlignment: 'horizontal', }; case 'boost': return { @@ -99,8 +97,7 @@ const decideSplashCardProperties = ( headlineSizeOnTablet: 'small', imagePositionOnDesktop: 'right', imagePositionOnMobile: 'bottom', - supportingContentAlignment: - supportingContentLength >= 4 ? 'horizontal' : 'vertical', + supportingContentAlignment: 'horizontal', }; case 'megaboost': return { @@ -146,10 +143,8 @@ export const SplashCardLayout = ({ imagePositionOnDesktop, imagePositionOnMobile, supportingContentAlignment, - } = decideSplashCardProperties( - card.boostLevel, - card?.supportingContent?.length ?? 0, - ); + } = decideSplashCardProperties(card.boostLevel); + return (