Skip to content

Commit d80ffe5

Browse files
remove html from primary heading for carousel and horizontal cards
1 parent 2a5b440 commit d80ffe5

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

dotcom-rendering/src/components/ProductCarouselCard.stories.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { css } from '@emotion/react';
22
import type { Meta, StoryObj } from '@storybook/react-webpack5';
33
import { productImage } from '../../fixtures/manual/productImage';
44
import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
5+
import { extractHeadingText } from '../model/enhanceProductElement';
56
import type { ProductBlockElement } from '../types/content';
67
import { ProductCarouselCard } from './ProductCarouselCard';
78

89
const product = {
910
_type: 'model.dotcomrendering.pageElements.ProductBlockElement',
1011
elementId: 'b1f6e8e2-3f3a-4f0c-8d1e-5f3e3e3e3e3e',
11-
primaryHeadingHtml: 'Best Kettle overall',
12+
primaryHeadingHtml: '<em>Best Kettle overall:<em/>',
13+
primaryHeadingText: extractHeadingText('<em>Best Kettle overall:</em>'),
1214
secondaryHeadingHtml: 'Bosch Sky Kettle',
1315
brandName: 'Bosch',
1416
productName: 'Sky Kettle',
@@ -277,7 +279,9 @@ export const WithLongHeadingProductNameAndCTA = {
277279
args: {
278280
product: {
279281
...product,
280-
primaryHeadingHtml: 'Super long product category review name',
282+
primaryHeadingText: extractHeadingText(
283+
'<em>Super long product: category review name:</em>',
284+
),
281285
productName:
282286
'Sky Kettle with a super duper long name that goes on and on',
283287
productCtas: [

dotcom-rendering/src/components/ProductCarouselCard.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,9 @@ export const ProductCarouselCard = ({
8484
<div css={baseCard}>
8585
{hasHeading && (
8686
<>
87-
<div
88-
css={productCarouselCardHeading}
89-
dangerouslySetInnerHTML={{
90-
__html: product.primaryHeadingHtml,
91-
}}
92-
/>
87+
<div css={productCarouselCardHeading}>
88+
{product.primaryHeadingText}
89+
</div>
9390
<div css={brandAndProductNameRow}>
9491
<span css={brandAndProductNameInline}>
9592
{product.brandName}{' '}

dotcom-rendering/src/model/enhanceProductElement.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// typescript
21
import type { ArticleFormat } from '../lib/articleFormat';
32
import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
43
import type {
@@ -26,8 +25,8 @@ const productBlockElement: ProductBlockElement = {
2625
starRating: '5',
2726
productName: 'Sky Kettle',
2827
image: productImage,
29-
secondaryHeadingHtml: 'Best Kettle Overall',
30-
primaryHeadingHtml: 'Bosch Sky Kettle',
28+
primaryHeadingHtml: '<em>Best Kettle: Overall:</em>',
29+
secondaryHeadingHtml: 'Bosch Sky Kettle',
3130
customAttributes: [
3231
{ name: 'What we love', value: 'It packs away pretty small' },
3332
{
@@ -167,4 +166,11 @@ describe('enhanceProductBlockElements', () => {
167166

168167
expect(enhancedElementWithNaN.lowestPrice).toEqual('£29.99');
169168
});
169+
170+
it('extracts all html from primary heading and removes trailing `:` only', () => {
171+
enhanceProductElement(elementsEnhancer)(inputElements);
172+
expect(enhancedElements.primaryHeadingText).toEqual(
173+
'Best Kettle: Overall',
174+
);
175+
});
170176
});

dotcom-rendering/src/model/enhanceProductElement.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const enhanceProductBlockElement = (
1414
...element,
1515
content: elementsEnhancer(element.content),
1616
lowestPrice: getLowestPrice(element.productCtas),
17-
primaryHeadingText: getHeadingText(element.primaryHeadingHtml),
17+
primaryHeadingText: extractHeadingText(element.primaryHeadingHtml),
1818
});
1919

2020
/**
@@ -75,7 +75,7 @@ export const enhanceProductElement =
7575
(elements: FEElement[]): FEElement[] =>
7676
elements.flatMap(enhance(elementsEnhancer));
7777

78-
const getHeadingText = (headingHtml: string): string => {
78+
export const extractHeadingText = (headingHtml: string): string => {
7979
return removeTrailingColon(extractText(headingHtml));
8080
};
8181

0 commit comments

Comments
 (0)