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

Create stories for web ad slots #13143

Merged
merged 6 commits into from
Jan 15, 2025
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
105 changes: 105 additions & 0 deletions dotcom-rendering/src/components/AdSlot.web.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import type { SerializedStyles } from '@emotion/react';
import { css } from '@emotion/react';
import { remSpace, textSans14 } from '@guardian/source/foundations';
import type { Meta, StoryObj } from '@storybook/react';
import { within } from '@storybook/test';
import { createRoot } from 'react-dom/client';
import {
centreColumnDecorator,
rightColumnDecorator,
} from '../../.storybook/decorators/gridDecorators';
import { ArticleDisplay } from '../lib/articleFormat';
import { AdSlot } from './AdSlot.web';

const meta = {
component: AdSlot,
title: 'Components/Ad Slot (web)',
} satisfies Meta<typeof AdSlot>;

export default meta;

type Story = StoryObj<typeof meta>;

const adLabelsStyles = css`
${textSans14}
padding: ${remSpace[3]};
display: flex;
justify-content: center;
width: 100%;
p {
margin: 0;
font-size: 16px;
font-weight: 400;
}
`;

const squareAdStyles = css`
padding-bottom: 250px;
width: 300px;
`;

const bannerAdStyles = css`
padding-bottom: 250px;
width: 100%;
`;

function renderTestAd(
adStyles: SerializedStyles,
slotId = 'slot',
): Story['play'] {
return async ({ canvasElement }) => {
const canvas = within(canvasElement);
const slot = await canvas.findByTestId(slotId);
const root = createRoot(slot);

root.render(
<aside>
<div css={adLabelsStyles}>
<p>Advertisement</p>
</div>
<div css={adStyles}></div>
</aside>,
);
};
}

export const Right = {
args: {
position: 'right',
display: ArticleDisplay.Standard,
},
decorators: [rightColumnDecorator],
play: renderTestAd(squareAdStyles),
} satisfies Story;

export const TopAboveNav = {
args: {
position: 'top-above-nav',
},
play: renderTestAd(bannerAdStyles),
} satisfies Story;

export const FrontsBanner = {
args: {
position: 'fronts-banner',
index: 1,
},
play: renderTestAd(bannerAdStyles),
} satisfies Story;

export const LiveblogInline = {
args: {
position: 'liveblog-inline',
index: 0,
},
decorators: [centreColumnDecorator],
play: renderTestAd(bannerAdStyles, 'liveblog-inline--inline1'),
} satisfies Story;

export const Merchandising = {
args: {
position: 'merchandising',
},
decorators: [centreColumnDecorator],
play: renderTestAd(bannerAdStyles),
} satisfies Story;
14 changes: 14 additions & 0 deletions dotcom-rendering/src/components/AdSlot.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export const AdSlot = ({
].join(' ')}
data-link-name="ad slot right"
data-name="right"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -422,6 +423,7 @@ export const AdSlot = ({
].join(' ')}
data-link-name="ad slot right"
data-name="right"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand Down Expand Up @@ -480,6 +482,7 @@ export const AdSlot = ({
]}
data-link-name="ad slot right"
data-name="right"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -504,6 +507,7 @@ export const AdSlot = ({
].join(' ')}
data-link-name="ad slot comments"
data-name="comments"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -526,6 +530,7 @@ export const AdSlot = ({
].join(' ')}
data-link-name="ad slot top-above-nav"
data-name="top-above-nav"
data-testid="slot"
aria-hidden="true"
></div>
</div>
Expand All @@ -550,6 +555,7 @@ export const AdSlot = ({
css={[mostPopAdStyles]}
data-link-name="ad slot mostpop"
data-name="mostpop"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -573,6 +579,7 @@ export const AdSlot = ({
data-link-name="ad slot merchandising-high"
data-name="merchandising-high"
data-refresh="false"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -594,6 +601,7 @@ export const AdSlot = ({
css={[merchandisingAdStyles]}
data-link-name="ad slot merchandising"
data-name="merchandising"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand Down Expand Up @@ -625,6 +633,7 @@ export const AdSlot = ({
css={[frontsBannerAdStyles]}
data-link-name={`ad slot ${advertId}`}
data-name={`${advertId}`}
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -646,6 +655,7 @@ export const AdSlot = ({
data-label="false"
data-refresh="false"
data-out-of-page="true"
data-testid="slot"
aria-hidden="true"
/>
);
Expand Down Expand Up @@ -717,6 +727,7 @@ export const AdSlot = ({
css={[liveBlogTopAdStyles]}
data-link-name="ad slot liveblog-top"
data-name="liveblog-top"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -740,6 +751,7 @@ export const AdSlot = ({
css={[mobileFrontAdStyles]}
data-link-name={`ad slot ${advertId}`}
data-name={advertId}
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -763,6 +775,7 @@ export const AdSlot = ({
data-refresh="false"
data-out-of-page="true"
data-wide="1,1"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand All @@ -782,6 +795,7 @@ export const AdSlot = ({
css={[articleEndAdStyles]}
data-link-name="ad slot article-end"
data-name="article-end"
data-testid="slot"
aria-hidden="true"
/>
</div>
Expand Down
Loading