Skip to content

Commit 1d87623

Browse files
authored
Merge pull request #15460 from guardian/jm/fix-top-article-text
fix restrict designable banner v2 article count to >= 5 articles
2 parents 24ff0a5 + 89cae6e commit 1d87623

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

dotcom-rendering/src/components/marketing/banners/designableBanner/v2/bannerSelectors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type BuildBannerSelectorsArgs = {
1414
tickerSettings?: BannerRenderProps['tickerSettings'];
1515
separateArticleCount?: boolean;
1616
separateArticleCountSettings?: BannerRenderProps['separateArticleCountSettings'];
17+
articleCounts: BannerRenderProps['articleCounts'];
1718
};
1819

1920
export const buildBannerSelectors = ({
@@ -26,6 +27,7 @@ export const buildBannerSelectors = ({
2627
tickerSettings,
2728
separateArticleCount,
2829
separateArticleCountSettings,
30+
articleCounts,
2931
}: BuildBannerSelectorsArgs): BannerSelectors => {
3032
const copyForViewport = isTabletOrAbove
3133
? content.mainContent
@@ -60,7 +62,8 @@ export const buildBannerSelectors = ({
6062
!!settings.tickerStylingSettings;
6163
const showArticleCount =
6264
!isCollapsed &&
63-
Boolean(separateArticleCountSettings ?? separateArticleCount);
65+
Boolean(separateArticleCountSettings ?? separateArticleCount) &&
66+
articleCounts.forTargetedWeeks >= 5;
6467
const showBodyVisual = !!settings.imageSettings && !isCollapsed;
6568
const showHeaderImage = !!settings.headerSettings?.headerImage;
6669

dotcom-rendering/src/components/marketing/banners/designableBanner/v2/tests/Banner.test.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ describe('DesignableBanner V2', () => {
233233
expect(screen.getByText('£20')).toBeInTheDocument();
234234
});
235235

236-
it('renders article count when separateArticleCount is true', () => {
236+
it('renders article count when separateArticleCount is true and >= 5 articles', () => {
237237
const articleCountProps: BannerRenderProps = {
238238
...mockProps,
239239
separateArticleCount: true,
@@ -250,4 +250,21 @@ describe('DesignableBanner V2', () => {
250250
expect(screen.getByText(/You've read/)).toBeInTheDocument();
251251
expect(screen.getByText(/5/)).toBeInTheDocument();
252252
});
253+
254+
it('does not render article count when separateArticleCount is true but user has read < 5 articles', () => {
255+
const articleCountProps: BannerRenderProps = {
256+
...mockProps,
257+
separateArticleCount: true,
258+
articleCounts: {
259+
forTargetedWeeks: 4,
260+
for52Weeks: 10,
261+
},
262+
};
263+
264+
render(<BannerComponent {...articleCountProps} />);
265+
266+
// Should not be in the document
267+
expect(screen.queryByText(/You've read/)).not.toBeInTheDocument();
268+
expect(screen.queryByText(/4/)).not.toBeInTheDocument();
269+
});
253270
});

dotcom-rendering/src/components/marketing/banners/designableBanner/v2/useDesignableBannerModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ export const useDesignableBannerModel = ({
346346
tickerSettings,
347347
separateArticleCount,
348348
separateArticleCountSettings,
349+
articleCounts,
349350
});
350351

351352
return {

0 commit comments

Comments
 (0)