Skip to content

Commit 7777f33

Browse files
committed
prevent ad placeholder elements being inserted for articles where shouldHideAds is true
1 parent 3637a88 commit 7777f33

File tree

7 files changed

+52
-9
lines changed

7 files changed

+52
-9
lines changed

dotcom-rendering/src/model/enhance-ad-placeholders.test.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ describe('Enhancing ad placeholders', () => {
9696
const expectedPlaceholders = expectedPositions.length;
9797
const input: FEElement[] = elements;
9898

99-
const output = enhanceAdPlaceholders(exampleFormat, 'Apps')(input);
99+
const output = enhanceAdPlaceholders(
100+
exampleFormat,
101+
'Apps',
102+
false,
103+
)(input);
100104
const placeholderIndices = output.flatMap((el, idx) =>
101105
elementIsAdPlaceholder(el) ? [idx] : [],
102106
);
@@ -115,7 +119,7 @@ describe('Enhancing ad placeholders', () => {
115119
},
116120
);
117121

118-
describe('should not insert an ad placeholder before an inline image element, but can insert it after the image', () => {
122+
it('should not insert an ad placeholder before an inline image element, but can insert it after the image', () => {
119123
const threeParagraphs = getTestParagraphElements(3);
120124

121125
const elements = [
@@ -126,7 +130,11 @@ describe('Enhancing ad placeholders', () => {
126130

127131
const input: FEElement[] = elements;
128132

129-
const output = enhanceAdPlaceholders(exampleFormat, 'Apps')(input);
133+
const output = enhanceAdPlaceholders(
134+
exampleFormat,
135+
'Apps',
136+
false,
137+
)(input);
130138
const outputPlaceholders = output.filter(elementIsAdPlaceholder);
131139

132140
expect(outputPlaceholders.length).toEqual(1);
@@ -139,7 +147,7 @@ describe('Enhancing ad placeholders', () => {
139147
expect(placeholderIndices).toEqual([4]);
140148
});
141149

142-
describe('should not insert an ad placeholder after a thumbnail image element', () => {
150+
it('should not insert an ad placeholder after a thumbnail image element', () => {
143151
const threeParagraphs = getTestParagraphElements(3);
144152

145153
const elements = [
@@ -150,7 +158,11 @@ describe('Enhancing ad placeholders', () => {
150158

151159
const input: FEElement[] = elements;
152160

153-
const output = enhanceAdPlaceholders(exampleFormat, 'Apps')(input);
161+
const output = enhanceAdPlaceholders(
162+
exampleFormat,
163+
'Apps',
164+
false,
165+
)(input);
154166
const outputPlaceholders = output.filter(elementIsAdPlaceholder);
155167

156168
expect(outputPlaceholders.length).toEqual(1);
@@ -163,7 +175,7 @@ describe('Enhancing ad placeholders', () => {
163175
expect(placeholderIndices).toEqual([5]);
164176
});
165177

166-
describe('should not insert an ad placeholder after an element which is not an image or text', () => {
178+
it('should not insert an ad placeholder after an element which is not an image or text', () => {
167179
const threeParagraphs = getTestParagraphElements(3);
168180

169181
const elements = [
@@ -174,7 +186,11 @@ describe('Enhancing ad placeholders', () => {
174186

175187
const input: FEElement[] = elements;
176188

177-
const output = enhanceAdPlaceholders(exampleFormat, 'Apps')(input);
189+
const output = enhanceAdPlaceholders(
190+
exampleFormat,
191+
'Apps',
192+
false,
193+
)(input);
178194
const outputPlaceholders = output.filter(elementIsAdPlaceholder);
179195

180196
expect(outputPlaceholders.length).toEqual(1);
@@ -186,4 +202,17 @@ describe('Enhancing ad placeholders', () => {
186202
// Expect one placeholder to be present after the fifth element only
187203
expect(placeholderIndices).toEqual([5]);
188204
});
205+
206+
it('should not insert ad placeholders if shouldHideAds is true', () => {
207+
const input: FEElement[] = getTestParagraphElements(6);
208+
209+
const output = enhanceAdPlaceholders(
210+
exampleFormat,
211+
'Apps',
212+
true,
213+
)(input);
214+
const outputPlaceholders = output.filter(elementIsAdPlaceholder);
215+
216+
expect(outputPlaceholders.length).toEqual(0);
217+
});
189218
});

dotcom-rendering/src/model/enhance-ad-placeholders.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ const insertAdPlaceholders = (elements: FEElement[]): FEElement[] => {
135135
};
136136

137137
export const enhanceAdPlaceholders =
138-
(format: ArticleFormat, renderingTarget: RenderingTarget) =>
138+
(
139+
format: ArticleFormat,
140+
renderingTarget: RenderingTarget,
141+
shouldHideAds: boolean,
142+
) =>
139143
(elements: FEElement[]): FEElement[] =>
140144
renderingTarget === 'Apps' &&
145+
!shouldHideAds &&
141146
format.design !== ArticleDesign.LiveBlog &&
142147
format.design !== ArticleDesign.DeadBlog
143148
? insertAdPlaceholders(elements)

dotcom-rendering/src/model/enhanceBlocks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Options = {
3232
hasAffiliateLinksDisclaimer: boolean;
3333
audioArticleImage?: ImageBlockElement;
3434
tags?: TagType[];
35+
shouldHideAds: boolean;
3536
};
3637

3738
const enhanceNewsletterSignup =
@@ -76,7 +77,11 @@ export const enhanceElements =
7677
options.promotedNewsletter,
7778
blockId,
7879
),
79-
enhanceAdPlaceholders(format, options.renderingTarget),
80+
enhanceAdPlaceholders(
81+
format,
82+
options.renderingTarget,
83+
options.shouldHideAds,
84+
),
8085
enhanceDisclaimer(options.hasAffiliateLinksDisclaimer),
8186
].reduce(
8287
(enhancedBlocks, enhancer) => enhancer(enhancedBlocks),

dotcom-rendering/src/model/pinnedPost.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ export const enhancePinnedPost = (
1717
imagesForLightbox: [],
1818
promotedNewsletter: undefined,
1919
hasAffiliateLinksDisclaimer: false,
20+
shouldHideAds: false,
2021
})[0];
2122
};

dotcom-rendering/src/server/handler.article.apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const handleAppsBlocks: RequestHandler = ({ body }, res) => {
5959
promotedNewsletter: undefined,
6060
imagesForLightbox: [],
6161
hasAffiliateLinksDisclaimer: false,
62+
shouldHideAds,
6263
});
6364
const html = renderAppsBlocks({
6465
blocks: enhancedBlocks,

dotcom-rendering/src/server/handler.article.web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const handleBlocks: RequestHandler = ({ body }, res) => {
7878
promotedNewsletter: undefined,
7979
imagesForLightbox: [],
8080
hasAffiliateLinksDisclaimer: false,
81+
shouldHideAds,
8182
});
8283
const html = renderBlocks({
8384
blocks: enhancedBlocks,

dotcom-rendering/src/types/article.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export const enhanceArticleType = (
9090
hasAffiliateLinksDisclaimer: !!data.affiliateLinksDisclaimer,
9191
audioArticleImage: data.audioArticleImage,
9292
tags: data.tags,
93+
shouldHideAds: data.shouldHideAds,
9394
});
9495

9596
const crosswordBlock = buildCrosswordBlock(data);

0 commit comments

Comments
 (0)