Skip to content

Commit

Permalink
Election banner - Handle Turkce service URL (#12126)
Browse files Browse the repository at this point in the history
  • Loading branch information
amoore108 authored Nov 1, 2024
1 parent 171d349 commit a98a734
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/app/pages/ArticlePage/ElectionBanner/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ describe('ElectionBanner', () => {
expect(getByTestId(ELEMENT_ID)).toBeInTheDocument();
});

it('should render the correct VJ URL for Turkce service', () => {
const { getByTestId } = render(
<ElectionBanner aboutTags={mockAboutTags} taggings={mockTaggings} />,
{
toggles: { electionBanner: { enabled: true } },
isAmp,
service: 'turkce',
},
);

const wrappingEl = getByTestId(ELEMENT_ID);

const iframe = wrappingEl.querySelector('iframe, amp-iframe');
const iframeSrc = iframe?.getAttribute('src');

expect(iframeSrc).not.toContain('turkce');
expect(iframeSrc).toContain('turkish');
});

it('should not render ElectionBanner when taggings contain the editorialSensitivityId', () => {
const { queryByTestId } = render(
<ElectionBanner
Expand Down
15 changes: 14 additions & 1 deletion src/app/pages/ArticlePage/ElectionBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Tag } from '#app/components/Metadata/types';
import { ServiceContext } from '#app/contexts/ServiceContext';
import { getEnvConfig } from '#app/lib/utilities/getEnvConfig';
import { MetadataTaggings } from '#app/models/types/metadata';
import { Services } from '#app/models/types/global';
import styles from './index.styles';
import BANNER_CONFIG from './config';

Expand All @@ -17,6 +18,15 @@ type Props = {
taggings: MetadataTaggings;
};

const handleUrlServiceTransform = (url: string, service: Services) => {
switch (service) {
case 'turkce':
return url.replace('{service}', 'turkish');
default:
return url.replace('{service}', service);
}
};

export default function ElectionBanner({ aboutTags, taggings }: Props) {
const { service } = useContext(ServiceContext);
const { isAmp, isLite } = useContext(RequestContext);
Expand Down Expand Up @@ -53,7 +63,10 @@ export default function ElectionBanner({ aboutTags, taggings }: Props) {
} = getEnvConfig();

const iframeSrcToUse = SIMORGH_APP_ENV === 'live' ? iframeSrc : iframeDevSrc;
const iframeSrcWithService = iframeSrcToUse.replace('{service}', service);
const iframeSrcWithService = handleUrlServiceTransform(
iframeSrcToUse,
service,
);

if (isAmp) {
return (
Expand Down

0 comments on commit a98a734

Please sign in to comment.