Skip to content

Commit

Permalink
Fix pathing to Optimo image blocks in FrostedGlassPromo (#10892)
Browse files Browse the repository at this point in the history
* Fix pathing to Optimo image blocks in FrostedGlassPromo

* Try wait-on on Cypress E2E
  • Loading branch information
amoore108 authored Jun 14, 2023
1 parent 9dfe8b9 commit f763672
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/simorgh-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ jobs:
working-directory: ws-nextjs-app
build: yarn build
start: yarn start
wait-on: 'http://localhost:7081'
39 changes: 15 additions & 24 deletions src/app/components/FrostedGlassPromo/withData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { RequestContext } from '../../contexts/RequestContext';

import styles from './styles';
import { FormattedPromo, ImageProps, PromoProps } from './types';
import { OptimoBlock } from '../../models/types/optimo';

const buildImageProperties = (image?: ImageProps) => {
if (!image) return null;
Expand Down Expand Up @@ -82,30 +83,21 @@ const TimestampFooterWithAmp = (props: PromoProps) => {
};

const optimoPromoFormatter = (props: PromoProps): FormattedPromo => {
const altText = pathOr<string>(
'',
[
'item',
'images',
'defaultPromoImage',
'blocks',
0,
'model',
'blocks',
0,
'model',
'blocks',
0,
'model',
'text',
],
const defaultPromoImage = pathOr<OptimoBlock[]>(
[],
['item', 'images', 'defaultPromoImage', 'blocks'],
props,
);

const imageProps = path<ImageProps>(
['item', 'images', 'defaultPromoImage', 'blocks', 1, 'model'],
props,
);
const altText: string = defaultPromoImage?.find(
block => block.type === 'altText',
// @ts-expect-error - Optimo nested block structure
)?.model?.blocks?.[0]?.model?.blocks?.[0]?.model?.text;

// @ts-expect-error - We don't have types for specific Optimo blocks yet
const imageMetadata: ImageProps = defaultPromoImage.find(
block => block.type === 'rawImage',
).model;

return {
children: path<string>(
Expand All @@ -126,10 +118,9 @@ const optimoPromoFormatter = (props: PromoProps): FormattedPromo => {
footer: <TimestampFooterWithAmp {...props} />,
url: props?.item?.locators?.canonicalUrl,
image: buildImageProperties({
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
...imageProps!,
...imageMetadata,
altText,
copyright: imageProps?.copyrightHolder,
copyright: imageMetadata?.copyrightHolder,
}),
eventTrackingData: props?.eventTrackingData?.block,
};
Expand Down

0 comments on commit f763672

Please sign in to comment.