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

WSTEAM1-1300 - Article election banner #12024

Merged
merged 91 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
add88d8
WSTEAM1-931 - Article election banner iframe
amoore108 Apr 5, 2024
38f1eb4
Update index.styles.ts
amoore108 Apr 5, 2024
6435289
Add AMP version
amoore108 Apr 5, 2024
2a7940d
Service restriction
amoore108 Apr 5, 2024
c0c0edd
Update index.tsx
amoore108 Apr 5, 2024
4bf885d
Use rem for height
amoore108 Apr 5, 2024
19118e2
Update index.styles.ts
amoore108 Apr 5, 2024
cad805c
Fix storybook to show banner
amoore108 Apr 5, 2024
33f0169
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 8, 2024
d442927
Set height on container rather than iframe
amoore108 Apr 8, 2024
0dd94ca
Update index.styles.ts
amoore108 Apr 8, 2024
3bc0cc0
Find `thingLabel` from `aboutTags`
amoore108 Apr 8, 2024
2f5946f
Update index.tsx
amoore108 Apr 8, 2024
325951b
Make height configurable
amoore108 Apr 8, 2024
046ae8f
Move config into separate file
amoore108 Apr 8, 2024
fc29cd5
Add Storybook story
amoore108 Apr 8, 2024
8a555e2
Update index.tsx
amoore108 Apr 8, 2024
2cef306
Rename to `iframeSrc`
amoore108 Apr 8, 2024
1c047b0
Bail out if toggle returns false/null first
amoore108 Apr 8, 2024
f3b3a40
Update index.styles.ts
amoore108 Apr 8, 2024
e86a109
Construct iframe base url
amoore108 Apr 8, 2024
2242ae1
Disable chromatic snapshot for story
amoore108 Apr 8, 2024
eba6067
Check for service in config rather than `iframeSrc`
amoore108 Apr 8, 2024
3778a78
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 8, 2024
8834e30
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 8, 2024
8d18ff8
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
b1eaba8
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
d13411f
Add tests and `isLive` check
amoore108 Apr 9, 2024
af7e7a3
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
8498358
Fix tests
amoore108 Apr 9, 2024
e500705
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
3549229
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
4e8d613
Use `indianElectionBanner` toggle from iSite
amoore108 Apr 9, 2024
2a1bacb
Update index.stories.jsx
amoore108 Apr 9, 2024
164eb7e
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 9, 2024
4c18a3d
Update index.tsx
amoore108 Apr 9, 2024
618147d
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 10, 2024
a5be99d
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 10, 2024
19b094f
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 10, 2024
a4c8dda
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 23, 2024
a51e7f7
cache
amoore108 Apr 23, 2024
b718f9c
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 29, 2024
fc63409
Update config.ts
amoore108 Apr 29, 2024
0b7633d
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Apr 30, 2024
aef193c
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 May 1, 2024
b6f8ad9
Update config.ts
amoore108 May 1, 2024
87be629
Fix AMP height
amoore108 May 1, 2024
c14788b
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 May 1, 2024
9e027b9
Update bundleSizeConfig.js
amoore108 May 1, 2024
7d7407e
Update config.ts
amoore108 May 1, 2024
8fe471c
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 May 13, 2024
b859d84
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 May 23, 2024
375beef
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Sep 24, 2024
224490f
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 2, 2024
e54ba88
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 14, 2024
b9b566a
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 17, 2024
f0e51ab
logic updates
amoore108 Oct 17, 2024
c7c18c6
Update config.ts
amoore108 Oct 17, 2024
5de698a
storybook updates
amoore108 Oct 17, 2024
b2e06f5
test fix
amoore108 Oct 17, 2024
04c744e
delete unneeded fixture json
amoore108 Oct 17, 2024
d687597
delete features fixture data
amoore108 Oct 17, 2024
ba9cb74
Update index.tsx
amoore108 Oct 17, 2024
afc838d
Add dev source
amoore108 Oct 18, 2024
c0e5e5f
Temp - disable toggle check
amoore108 Oct 18, 2024
427058e
Spacing and `aside`
amoore108 Oct 18, 2024
fe25420
Consolidate iframe styles
amoore108 Oct 18, 2024
fe8dcad
Include USA `about.tag`
amoore108 Oct 18, 2024
99c2a42
Set height on iframe for noCSS
amoore108 Oct 18, 2024
b85992a
Add separate AMP iframe src
amoore108 Oct 18, 2024
0ec2f5c
Pass title to AMP iframe
amoore108 Oct 18, 2024
aba9511
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 18, 2024
ea2a3e7
Update config.ts
amoore108 Oct 18, 2024
5f840ab
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 18, 2024
f083446
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 18, 2024
9c2e949
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 21, 2024
9225118
Re-enable toggle for reviews
amoore108 Oct 21, 2024
e98b4f9
Update index.tsx
amoore108 Oct 21, 2024
33687b8
Add local toggle config for `articleElectionBanner`
amoore108 Oct 21, 2024
c740567
Update iframe title - remove `aside` and role` attr
amoore108 Oct 21, 2024
e9b11c0
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 23, 2024
14e971c
Remove `United Status` thingId
amoore108 Oct 23, 2024
65d32eb
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 23, 2024
d6bd7cb
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 23, 2024
4eb5a30
Use `thingLabel` for iframe title - Use same `testid` for AMP and can…
amoore108 Oct 23, 2024
dcdb593
Remove width restriction
amoore108 Oct 23, 2024
cb47e10
Simplify styling
amoore108 Oct 23, 2024
56a9d6a
Revert "Simplify styling"
amoore108 Oct 23, 2024
1fef085
Revert "Remove width restriction"
amoore108 Oct 23, 2024
9b9bae8
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 23, 2024
859ce6d
Merge branch 'latest' into WSTEAM1-931-article-election-banner
amoore108 Oct 24, 2024
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
2,763 changes: 2,763 additions & 0 deletions data/mundo/articles/c206j730722o.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/app/components/AmpIframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {
width: number;
height: number;
src: string;
title?: string;
};

type ampMetadata = {
Expand All @@ -19,6 +20,7 @@ type ampMetadata = {
imageHeight: number;
image: string;
src: string;
title?: string;
};
};

Expand All @@ -38,6 +40,7 @@ const AmpIframeElement = ({
width,
height,
src,
title,
}: PropsWithChildren<Props>) => (
<amp-iframe
class={className}
Expand All @@ -47,19 +50,25 @@ const AmpIframeElement = ({
sandbox="allow-scripts allow-same-origin allow-top-navigation-by-user-activation allow-forms"
resizable=""
src={src}
title={title}
>
{children}
</amp-iframe>
);

const AmpIframe = ({
ampMetadata: { imageWidth, imageHeight, image, src },
ampMetadata: { imageWidth, imageHeight, image, src, title },
}: ampMetadata) => {
return (
<>
<AmpHead />
<GridItemMedium gridColumnStart={undefined} gridSpan={undefined}>
<AmpIframeElement width={imageWidth} height={imageHeight} src={src}>
<AmpIframeElement
width={imageWidth}
height={imageHeight}
src={src}
title={title}
>
{/* @ts-expect-error Property 'overflow' does not exist on type 'DivProps & { css?: Interpolation<Theme>; }'. */}
<div overflow="" css={styles.overflow}>
<button type="button" css={styles.button}>
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/react-testing-library-with-providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Props extends PropsWithChildren {
id?: string | null;
isAmp?: boolean;
isApp?: boolean;
isLite?: boolean;
pageData?: object;
atiData?: ATIData;
bbcOrigin?: string | null;
Expand All @@ -40,6 +41,7 @@ const AllTheProviders: FC<Props> = ({
id = null,
isAmp = false,
isApp = false,
isLite = false,
bbcOrigin = 'https://www.test.bbc.com',
pageType = 'article',
derivedPageType,
Expand Down Expand Up @@ -67,6 +69,7 @@ const AllTheProviders: FC<Props> = ({
pageType={pageType}
isAmp={isAmp}
isApp={isApp}
isLite={isLite}
isNextJs={isNextJs}
service={service}
pathname={pathname}
Expand Down Expand Up @@ -97,6 +100,7 @@ const customRender = (
id,
isAmp,
isApp,
isLite,
bbcOrigin,
pageData,
pageType,
Expand All @@ -120,6 +124,7 @@ const customRender = (
id={id}
isAmp={isAmp}
isApp={isApp}
isLite={isLite}
bbcOrigin={bbcOrigin}
pageData={pageData}
atiData={atiData}
Expand Down
3 changes: 3 additions & 0 deletions src/app/lib/config/toggles/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ exports[`Toggles Config when application environment is local should contain cor
"ads": {
"enabled": false,
},
"articleElectionBanner": {
"enabled": true,
},
"chartbeatAnalytics": {
"enabled": true,
},
Expand Down
3 changes: 3 additions & 0 deletions src/app/lib/config/toggles/localConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export default {
ads: {
enabled: false,
},
articleElectionBanner: {
enabled: true,
},
chartbeatAnalytics: {
enabled: true,
},
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/ArticlePage/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import CpsRecommendations from '#containers/CpsRecommendations';
import InlinePodcastPromo from '#containers/PodcastPromo/Inline';
import { Article, OptimoBylineBlock } from '#app/models/types/optimo';
import ScrollablePromo from '#components/ScrollablePromo';
import ElectionBanner from './ElectionBanner';

import ImageWithCaption from '../../components/ImageWithCaption';
import AdContainer from '../../components/Ad';
import EmbedImages from '../../components/Embeds/EmbedImages';
Expand Down Expand Up @@ -99,7 +101,7 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
const aboutTags = getAboutTags(pageData);
const topics = pageData?.metadata?.topics ?? [];
const blocks = pageData?.content?.model?.blocks ?? [];
const startsWithHeading = blocks?.[0]?.type === 'headline' ?? false;
const startsWithHeading = blocks?.[0]?.type === 'headline' || false;

const bylineBlock = blocks.find(
block => block.type === 'byline',
Expand Down Expand Up @@ -271,6 +273,7 @@ const ArticlePage = ({ pageData }: { pageData: Article }) => {
{allowAdvertising && (
<AdContainer slotType="leaderboard" adcampaign={adcampaign} />
)}
<ElectionBanner aboutTags={aboutTags} />
<div css={styles.grid}>
<div css={!isPGL ? styles.primaryColumn : styles.pglColumn}>
<main css={styles.mainContent} role="main">
Expand Down
14 changes: 14 additions & 0 deletions src/app/pages/ArticlePage/ElectionBanner/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';

const IFRAME_BASE_URL = getEnvConfig().SIMORGH_INCLUDES_BASE_URL;

export default {
iframeHeight: 324,
iframeSrc: `${IFRAME_BASE_URL}/include/vjafwest/1365-2024-us-presidential-election-banner/develop/{service}/app`,
iframeSrcAmp: `${IFRAME_BASE_URL}/include/vjafwest/1365-2024-us-presidential-election-banner/develop/{service}/app/amp`,
iframeTitle: 'US Election results',
amoore108 marked this conversation as resolved.
Show resolved Hide resolved
thingIds: [
'647d5613-e0e2-4ef5-b0ce-b491de38bdbd', // https://www.bbc.co.uk/things/647d5613-e0e2-4ef5-b0ce-b491de38bdbd
'82857f8e-8134-462a-bb32-b7b14f4eab75', // https://www.bbc.co.uk/things/82857f8e-8134-462a-bb32-b7b14f4eab75
],
};
40 changes: 40 additions & 0 deletions src/app/pages/ArticlePage/ElectionBanner/index.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { css, Theme } from '@emotion/react';
import pixelsToRem from '#app/utilities/pixelsToRem';
import BANNER_CONFIG from './config';

const IFRAME_STYLES = css({
border: 'none',
width: '100%',
height: `${pixelsToRem(BANNER_CONFIG.iframeHeight)}rem`,
});

export default {
electionBannerWrapper: ({ mq, spacings }: Theme) =>
css({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
maxWidth: '63rem',
margin: '0 auto',

[mq.GROUP_3_MIN_WIDTH]: {
paddingTop: `${spacings.QUINTUPLE}rem`,
},
}),

electionBannerIframe: () => IFRAME_STYLES,

electionBannerWrapperAmp: ({ mq, spacings }: Theme) =>
css({
overflow: 'hidden',
maxWidth: '63rem',
margin: '0 auto',

[mq.GROUP_3_MIN_WIDTH]: {
paddingTop: `${spacings.QUINTUPLE}rem`,
},

'> div': { padding: '0' },
'& amp-iframe': IFRAME_STYLES,
}),
};
100 changes: 100 additions & 0 deletions src/app/pages/ArticlePage/ElectionBanner/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react';
import { render } from '#app/components/react-testing-library-with-providers';
import { Tag } from '#app/components/Metadata/types';
import isLive from '#app/lib/utilities/isLive';
import BANNER_CONFIG from './config';
import ElectionBanner from '.';

jest.mock('#app/lib/utilities/isLive', () =>
jest.fn().mockImplementation(() => false),
);

const mockAboutTags = [
{ thingId: 'thing1' },
{ thingId: BANNER_CONFIG.thingIds[0] },
{ thingId: 'thing3' },
{ thingId: BANNER_CONFIG.thingIds[1] },
] as Tag[];

const AMP_ELEMENT = 'election-banner-amp';
const CANONICAL_ELEMENT = 'election-banner';

describe('ElectionBanner', () => {
it('should not render ElectionBanner when isLite is true', () => {
const { queryByTestId } = render(
<ElectionBanner aboutTags={mockAboutTags} />,
{ isLite: true },
);

expect(queryByTestId(CANONICAL_ELEMENT)).not.toBeInTheDocument();
});

describe.each(['canonical', 'amp'])('%s', platform => {
const isAmp = platform === 'amp';
const bannerElement = isAmp ? AMP_ELEMENT : CANONICAL_ELEMENT;

it('should render ElectionBanner when aboutTags contain the correct thingLabel', () => {
const { getByTestId } = render(
<ElectionBanner aboutTags={mockAboutTags} />,
{
toggles: { articleElectionBanner: { enabled: true } },
isAmp,
},
);

expect(getByTestId(bannerElement)).toBeInTheDocument();

const iframe = getByTestId(bannerElement).querySelector(
isAmp ? 'amp-iframe' : 'iframe',
);

expect(iframe).toHaveAttribute(
'src',
BANNER_CONFIG[isAmp ? 'iframeSrcAmp' : 'iframeSrc'].replace(
'{service}',
'news',
),
);
});

it('should not render ElectionBanner when aboutTags do not contain the correct thingLabel', () => {
const { queryByTestId } = render(
<ElectionBanner aboutTags={[{ thingLabel: 'thing1' }] as Tag[]} />,
{ isAmp },
);

expect(queryByTestId(bannerElement)).not.toBeInTheDocument();
});

it('should not render ElectionBanner when aboutTags is empty', () => {
const { queryByTestId } = render(<ElectionBanner aboutTags={[]} />, {
isAmp,
});

expect(queryByTestId(bannerElement)).not.toBeInTheDocument();
});

it('should not render ElectionBanner when toggle is disabled', () => {
const { queryByTestId } = render(
<ElectionBanner aboutTags={mockAboutTags} />,
{
toggles: { articleElectionBanner: { enabled: false } },
isAmp,
},
);

expect(queryByTestId(bannerElement)).not.toBeInTheDocument();
});

it('should not render ElectionBanner when isLive is true', () => {
(isLive as jest.Mock).mockImplementationOnce(() => true);

const { queryByTestId } = render(
<ElectionBanner aboutTags={mockAboutTags} />,
{ isAmp },
);

expect(queryByTestId(bannerElement)).not.toBeInTheDocument();
});
});
});
68 changes: 68 additions & 0 deletions src/app/pages/ArticlePage/ElectionBanner/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/** @jsx jsx */

import { jsx } from '@emotion/react';
import { useContext } from 'react';
import { RequestContext } from '#app/contexts/RequestContext';
import AmpIframe from '#app/components/AmpIframe';
import useToggle from '#app/hooks/useToggle';
import { Tag } from '#app/components/Metadata/types';
import isLive from '#app/lib/utilities/isLive';
import { ServiceContext } from '#app/contexts/ServiceContext';
import styles from './index.styles';
import BANNER_CONFIG from './config';

export default function ElectionBanner({ aboutTags }: { aboutTags: Tag[] }) {
const { service } = useContext(ServiceContext);
const { isAmp, isLite } = useContext(RequestContext);
const { enabled: electionBannerEnabled }: { enabled: boolean | null } =
useToggle('articleElectionBanner');

if (isLive()) return null; // TODO: Remove once going Live
if (isLite) return null;

const { iframeHeight, iframeSrc, iframeSrcAmp, iframeTitle, thingIds } =
BANNER_CONFIG;

const validAboutTag = aboutTags?.some(tag => thingIds.includes(tag.thingId));

const showBanner = validAboutTag && electionBannerEnabled;

if (!showBanner) return null;

if (isAmp) {
return (
<aside
amoore108 marked this conversation as resolved.
Show resolved Hide resolved
role="complementary"
data-testid="election-banner-amp"
amoore108 marked this conversation as resolved.
Show resolved Hide resolved
css={styles.electionBannerWrapperAmp}
>
<AmpIframe
ampMetadata={{
imageWidth: 1,
imageHeight: iframeHeight,
src: iframeSrcAmp.replace('{service}', service),
image:
'https://news.files.bbci.co.uk/include/vjassets/img/app-launcher.png',
title: iframeTitle,
}}
/>
</aside>
);
}

return (
<aside
amoore108 marked this conversation as resolved.
Show resolved Hide resolved
role="complementary"
data-testid="election-banner"
css={styles.electionBannerWrapper}
>
<iframe
title={iframeTitle}
src={iframeSrc.replace('{service}', service)}
scrolling="no"
css={styles.electionBannerIframe}
height={iframeHeight}
/>
</aside>
);
}
Loading
Loading