Skip to content

Commit 8bef7c7

Browse files
authored
Merge pull request #13344 from guardian/mob/video-spike
Display test loop video container when in 0% AB test
2 parents 75fcc40 + 1663c37 commit 8bef7c7

File tree

8 files changed

+135
-10
lines changed

8 files changed

+135
-10
lines changed

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export type Props = {
151151
showKickerImage?: boolean;
152152
galleryCount?: number;
153153
audioDuration?: string;
154+
isInLoopVideoTest?: boolean;
154155
};
155156

156157
const starWrapper = (cardHasImage: boolean) => css`
@@ -408,6 +409,7 @@ export const Card = ({
408409
showKickerImage = false,
409410
galleryCount,
410411
audioDuration,
412+
isInLoopVideoTest = false,
411413
}: Props) => {
412414
const hasSublinks = supportingContent && supportingContent.length > 0;
413415
const sublinkPosition = decideSublinkPosition(
@@ -816,6 +818,7 @@ export const Card = ({
816818
media.type === 'slideshow' && isFlexibleContainer
817819
}
818820
padImage={isMediaCard && isBetaContainer}
821+
isInLoopVideoTest={isInLoopVideoTest}
819822
>
820823
{media.type === 'slideshow' &&
821824
(isFlexibleContainer ? (
@@ -982,6 +985,7 @@ export const Card = ({
982985
loading={imageLoading}
983986
roundedCorners={isOnwardContent}
984987
aspectRatio={aspectRatio}
988+
isInLoopVideoTest={isInLoopVideoTest}
985989
/>
986990
{(isVideoMainMedia ||
987991
(isVideoArticle && !isBetaContainer)) &&

dotcom-rendering/src/components/Card/components/ImageWrapper.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Props = {
4242
*/
4343
hideImageOverlay?: boolean;
4444
padImage?: boolean;
45+
isInLoopVideoTest?: boolean;
4546
};
4647

4748
/**
@@ -128,11 +129,13 @@ export const ImageWrapper = ({
128129
imagePositionOnMobile,
129130
hideImageOverlay,
130131
padImage,
132+
isInLoopVideoTest = false,
131133
}: Props) => {
132134
const isHorizontalOnDesktop =
133135
imagePositionOnDesktop === 'left' || imagePositionOnDesktop === 'right';
134136
const isHorizontalOnMobile =
135137
imagePositionOnMobile === 'left' || imagePositionOnMobile === 'right';
138+
136139
return (
137140
<div
138141
css={[
@@ -179,7 +182,8 @@ export const ImageWrapper = ({
179182
{children}
180183
{/* This image overlay is styled when the CardLink is hovered */}
181184
{(imageType === 'picture' || imageType === 'slideshow') &&
182-
!hideImageOverlay && <div className="image-overlay" />}
185+
!hideImageOverlay &&
186+
!isInLoopVideoTest && <div className="image-overlay" />}
183187
</>
184188
</div>
185189
);

dotcom-rendering/src/components/CardPicture.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { ImgHTMLAttributes } from 'react';
44
import React from 'react';
55
import type { AspectRatio } from '../types/front';
66
import type { ImageSizeType } from './Card/components/ImageWrapper';
7+
import { LoopVideoABTest } from './LoopVideoABTest';
78
import type { ImageWidthType } from './Picture';
89
import { generateSources, getFallbackSource } from './Picture';
910

@@ -17,6 +18,7 @@ type Props = {
1718
roundedCorners?: boolean;
1819
isCircular?: boolean;
1920
aspectRatio?: AspectRatio;
21+
isInLoopVideoTest?: boolean;
2022
};
2123

2224
/**
@@ -155,6 +157,7 @@ export const CardPicture = ({
155157
roundedCorners,
156158
isCircular,
157159
aspectRatio,
160+
isInLoopVideoTest = false,
158161
}: Props) => {
159162
const sources = generateSources(
160163
mainImage,
@@ -164,6 +167,10 @@ export const CardPicture = ({
164167

165168
const fallbackSource = getFallbackSource(sources);
166169

170+
if (isInLoopVideoTest) {
171+
return <LoopVideoABTest />;
172+
}
173+
167174
return (
168175
<picture
169176
data-size={imageSize}

dotcom-rendering/src/components/FrontCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const FrontCard = (props: Props) => {
5858
galleryCount: trail.galleryCount,
5959
podcastImage: trail.podcastImage,
6060
audioDuration: trail.audioDuration,
61+
isInLoopVideoTest: trail.isInLoopVideoTest,
6162
};
6263

6364
return Card({ ...defaultProps, ...cardProps });
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { css } from '@emotion/react';
2+
3+
export const LoopVideoABTest = () => (
4+
<video
5+
id="video1"
6+
autoPlay={true}
7+
loop={true}
8+
muted={true}
9+
playsInline={true}
10+
controls={true}
11+
preload="none"
12+
css={[
13+
css`
14+
position: relative;
15+
z-index: 10;
16+
width: 100%;
17+
height: 100%;
18+
`,
19+
]}
20+
>
21+
Your browser does not support the video tag.
22+
<source
23+
type="video/mp4"
24+
src="https://uploads.guim.co.uk/2024/45/14/TEST+1+FOR+ELLEN--0ee1b132-3a0d-405b-b493-aada74b259b2-2.mp4"
25+
/>
26+
</video>
27+
);

dotcom-rendering/src/layouts/FrontLayout.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
getMobileAdPositions,
4444
} from '../lib/getFrontsAdPositions';
4545
import { hideAge } from '../lib/hideAge';
46+
import { testVideoCollection } from '../lib/loop-video-ab-test-data';
4647
import { ophanComponentId } from '../lib/ophan-helpers';
4748
import type { NavType } from '../model/extract-nav';
4849
import { palette as schemePalette } from '../palette';
@@ -108,7 +109,13 @@ const decideLeftContent = (
108109

109110
export const FrontLayout = ({ front, NAV }: Props) => {
110111
const {
111-
config: { isPaidContent, hasPageSkin: hasPageSkinConfig, pageId },
112+
config: {
113+
abTests,
114+
hasPageSkin: hasPageSkinConfig,
115+
isPaidContent,
116+
isPreview,
117+
pageId,
118+
},
112119
editionId,
113120
} = front;
114121

@@ -118,9 +125,18 @@ export const FrontLayout = ({ front, NAV }: Props) => {
118125

119126
const hasPageSkin = renderAds && hasPageSkinConfig;
120127

121-
const filteredCollections = front.pressedPage.collections.filter(
122-
(collection) => !isHighlights(collection),
123-
);
128+
const isInLoopVideoTest = abTests.loopVideoTestVariant === 'variant';
129+
130+
const filteredCollections = isInLoopVideoTest
131+
? [
132+
testVideoCollection,
133+
...front.pressedPage.collections.filter(
134+
(collection) => !isHighlights(collection),
135+
),
136+
]
137+
: front.pressedPage.collections.filter(
138+
(collection) => !isHighlights(collection),
139+
);
124140

125141
const merchHighAdPosition = getMerchHighPosition(filteredCollections);
126142

@@ -137,8 +153,6 @@ export const FrontLayout = ({ front, NAV }: Props) => {
137153

138154
const contributionsServiceUrl = getContributionsServiceUrl(front);
139155

140-
const { abTests, isPreview } = front.config;
141-
142156
const { absoluteServerTimes = false } = front.config.switches;
143157

144158
const fallbackAspectRatio = (collectionType: DCRContainerType) => {
@@ -272,9 +286,13 @@ export const FrontLayout = ({ front, NAV }: Props) => {
272286
)}
273287
{filteredCollections.map((collection, index) => {
274288
// Backfills should be added to the end of any curated content
275-
const trails = collection.curated.concat(
276-
collection.backfill,
277-
);
289+
const trails = collection.curated
290+
.concat(collection.backfill)
291+
.map((tr) => ({
292+
...tr,
293+
isInLoopVideoTest: isInLoopVideoTest && index === 0,
294+
}));
295+
278296
const [trail] = trails;
279297

280298
// There are some containers that have zero trails. We don't want to render these
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import type { DCRCollectionType, DCRFrontCard } from '../types/front';
2+
3+
const exampleCard: DCRFrontCard = {
4+
format: {
5+
design: 3,
6+
display: 0,
7+
theme: 0,
8+
},
9+
dataLinkName: 'media | group-0 | card-@1',
10+
url: '/science/audio/2024/dec/12/does-googles-mindboggling-new-chip-bring-quantum-computers-any-closer-podcast',
11+
headline: ' Google’s ‘mindboggling’ new quantum chip',
12+
trailText:
13+
'Ian Sample speaks to Winfried Hensinger, professor of quantum technologies at the University of Sussex to find out how quantum computers work, and whether Google’s new chip is an important milestone in their development.',
14+
webPublicationDate: '2024-12-12T05:00:09.000Z',
15+
kickerText: 'Podcast',
16+
supportingContent: [],
17+
discussionApiUrl:
18+
'https://discussion.code.dev-theguardian.com/discussion-api',
19+
byline: 'Presented by Ian Sample, produced by Joshan Chana and Madeleine Finlay, sound design by Tony Onuchukwu, the executive producer is Ellie Bury',
20+
showByline: false,
21+
snapData: {},
22+
isBoosted: false,
23+
boostLevel: 'default',
24+
isCrossword: false,
25+
showQuotedHeadline: false,
26+
showLivePlayable: false,
27+
mainMedia: {
28+
type: 'Audio',
29+
duration: 0,
30+
},
31+
isExternalLink: false,
32+
showMainVideo: false,
33+
image: {
34+
src: 'https://media.guim.co.uk/e8d98902b166c562f0f3283c969c4a02c04129d0/0_364_5461_3277/master/5461.jpg',
35+
altText:
36+
'Inauguration of the first IBM Quantum Data Center in Europe, in Ehningen, Germany<br>epa11635230 A model of the IBM Quantum System Two quantum computer is seen at the inauguration of the first IBM Quantum Data Center in Europe, in Ehningen, Germany, 01 October 2024. The Europe-based quantum data center will facilitate access to cutting-edge quantum computing for companies, research institutions and government agencies. EPA/ANNA SZILAGYI',
37+
},
38+
podcastImage: {
39+
src: 'https://uploads.guim.co.uk/2021/11/17/ScienceWeekly_FINAL_3000.jpeg',
40+
altText: 'Science Weekly',
41+
},
42+
audioDuration: '18:03',
43+
};
44+
45+
export const testVideoCollection: DCRCollectionType = {
46+
id: '2e10eba3-7836-4381-bfc0-07d71a3295f6',
47+
displayName: 'video test',
48+
collectionType: 'fixed/small/slow-V-third',
49+
grouped: {
50+
snap: [],
51+
huge: [],
52+
veryBig: [],
53+
big: [],
54+
standard: [],
55+
splash: [],
56+
},
57+
curated: [exampleCard, exampleCard, exampleCard, exampleCard, exampleCard],
58+
backfill: [],
59+
treats: [],
60+
config: {
61+
showDateHeader: false,
62+
},
63+
};

dotcom-rendering/src/types/front.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export type DCRFrontCard = {
352352
galleryCount?: number;
353353
podcastImage?: PodcastSeriesImage;
354354
audioDuration?: string;
355+
isInLoopVideoTest?: boolean;
355356
};
356357

357358
export type DCRSlideshowImage = {

0 commit comments

Comments
 (0)