Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YoutubeAtom refactors - pass index, extract components and event emitters #12405

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type Props = {
aspectRatio?: AspectRatio;
/** Alows the consumer to use a larger font size group for boost styling*/
boostedFontSizes?: boolean;
index?: number;
};

const starWrapper = (cardHasImage: boolean) => css`
Expand Down Expand Up @@ -255,6 +256,7 @@ export const Card = ({
isTagPage = false,
aspectRatio,
boostedFontSizes,
index = 0,
}: Props) => {
const hasSublinks = supportingContent && supportingContent.length > 0;
const sublinkPosition = decideSublinkPosition(
Expand Down Expand Up @@ -524,6 +526,7 @@ export const Card = ({
assetId={
media.mainMedia.videoId
}
index={index}
duration={
media.mainMedia.duration
}
Expand Down
4 changes: 4 additions & 0 deletions dotcom-rendering/src/components/Carousel.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ const Title = ({
);
type CarouselCardProps = {
isFirst: boolean;
index: number;
format: ArticleFormat;
linkTo: string;
headlineText: string;
Expand Down Expand Up @@ -493,6 +494,7 @@ const CarouselCard = ({
isOnwardContent,
absoluteServerTimes,
starRating,
index,
}: CarouselCardProps) => {
const isVideoContainer = containerType === 'fixed/video';
const cardImagePosition = isOnwardContent ? 'bottom' : 'top';
Expand Down Expand Up @@ -537,6 +539,7 @@ const CarouselCard = ({
imagePositionOnMobile={cardImagePosition}
absoluteServerTimes={absoluteServerTimes}
starRating={starRating}
index={index}
/>
</LI>
);
Expand Down Expand Up @@ -994,6 +997,7 @@ export const Carousel = ({
return (
<CarouselCard
key={`${trail.url}${i}`}
index={i}
isFirst={i === 0}
format={trailFormat}
linkTo={linkTo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ const imagePositionOnMobile: ImagePositionType = 'none';
const imageSize: ImageSizeType = 'large';

const baseConfiguration = {
index: 123,
atomId: 'a2502abd-1373-45a2-b508-3e5a2ec050be',
videoId: '-ZCvZmYlQD8',
uniqueId: '-ZCvZmYlQD8-1',
alt: '',
eventEmitters: [
// eslint-disable-next-line no-console -- check event emitters are called
Expand Down Expand Up @@ -303,7 +304,7 @@ export const DuplicateVideos = {
<>
<YoutubeAtom {...args} />
<br />
<YoutubeAtom {...args} index={345} />
<YoutubeAtom {...args} uniqueId="ZCvZmYlQD8-2" />
</>
),
decorators: [SmallContainer],
Expand Down Expand Up @@ -333,8 +334,16 @@ export const MultipleStickyVideos = {
`}
>
<YoutubeAtom {...args} />
<YoutubeAtom {...args} index={456} videoId="pcMiS6PW8aQ" />
<YoutubeAtom {...args} index={789} videoId="3jpXAMwRSu4" />
<YoutubeAtom
{...args}
uniqueId="pcMiS6PW8aQ-1"
videoId="pcMiS6PW8aQ"
/>
<YoutubeAtom
{...args}
uniqueId="3jpXAMwRSu4-1"
videoId="3jpXAMwRSu4"
/>
</div>
),
parameters: {
Expand Down
63 changes: 36 additions & 27 deletions dotcom-rendering/src/components/YoutubeAtom/YoutubeAtom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -55,7 +56,7 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [playerDiv] = getAllByTestId(/^youtube-player-ZCvZmYlQD8-\d+$/);
const [playerDiv] = getAllByTestId(/^youtube-player-c_xtiZNDgGc-\d+$/);
expect(playerDiv).toBeInTheDocument();
});

Expand All @@ -70,9 +71,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -93,13 +95,13 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [overlay] = getAllByTestId(/^youtube-overlay-ZCvZmYlQD8-\d+$/);
const [overlay] = getAllByTestId(/^youtube-overlay-c_xtiZNDgGc-\d+$/);
expect(overlay).toBeInTheDocument();

overlay && fireEvent.click(overlay);
expect(overlay).not.toBeInTheDocument();

const [playerDiv] = getAllByTestId(/^youtube-player-ZCvZmYlQD8-\d+$/);
const [playerDiv] = getAllByTestId(/^youtube-player-c_xtiZNDgGc-\d+$/);
expect(playerDiv).toBeInTheDocument();
});

Expand All @@ -116,9 +118,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -138,7 +141,7 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [playerDiv] = getAllByTestId(/^youtube-player-ZCvZmYlQD8-\d+$/);
const [playerDiv] = getAllByTestId(/^youtube-player-c_xtiZNDgGc-\d+$/);
expect(playerDiv?.title).toBe(title);
});

Expand All @@ -154,9 +157,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -177,7 +181,7 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [overlay] = getAllByTestId(/^youtube-overlay-ZCvZmYlQD8-\d+$/);
const [overlay] = getAllByTestId(/^youtube-overlay-c_xtiZNDgGc-\d+$/);
const ariaLabel = overlay?.getAttribute('aria-label');

expect(ariaLabel).toBe(`Play video: ${title}`);
Expand All @@ -194,9 +198,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -216,7 +221,7 @@ describe('YoutubeAtom', () => {
);
const { getAllByTestId } = render(atom);
const [placeholder] = getAllByTestId(
/^youtube-placeholder-ZCvZmYlQD8-\d+$/,
/^youtube-placeholder-c_xtiZNDgGc-\d+$/,
);
expect(placeholder).toBeInTheDocument();
});
Expand All @@ -232,9 +237,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -254,7 +260,7 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [overlay] = getAllByTestId(/^youtube-overlay-ZCvZmYlQD8-\d+$/);
const [overlay] = getAllByTestId(/^youtube-overlay-c_xtiZNDgGc-\d+$/);
expect(overlay).toBeInTheDocument();
});

Expand All @@ -269,9 +275,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="2e9e138b-0a23-4b96-a7f6-0258c0bacc8f"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -291,7 +298,7 @@ describe('YoutubeAtom', () => {
</ConfigProvider>
);
const { getAllByTestId } = render(atom);
const [overlay] = getAllByTestId(/^youtube-overlay-ZCvZmYlQD8-\d+$/);
const [overlay] = getAllByTestId(/^youtube-overlay-c_xtiZNDgGc-\d+$/);
expect(overlay).toBeInTheDocument();

overlay && fireEvent.click(overlay);
Expand All @@ -310,9 +317,10 @@ describe('YoutubeAtom', () => {
}}
>
<YoutubeAtom
index={123}
atomId="atom1"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-1"
title="My Youtube video!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -330,9 +338,10 @@ describe('YoutubeAtom', () => {
renderingTarget="Web"
/>
<YoutubeAtom
index={123}
atomId="atom1"
videoId="c_xtiZNDgGc"
uniqueId="c_xtiZNDgGc-2"
title="My Youtube video 2!"
videoId="ZCvZmYlQD8"
alt=""
adTargeting={{ disableAds: true }}
eventEmitters={[]}
Expand All @@ -354,7 +363,7 @@ describe('YoutubeAtom', () => {
);
const { getAllByTestId } = render(atom);
const [overlay1, overlay2] = getAllByTestId(
/^youtube-overlay-ZCvZmYlQD8-\d+$/,
/^youtube-overlay-c_xtiZNDgGc-\d+$/,
);
expect(overlay1).toBeInTheDocument();

Expand Down
Loading
Loading