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

NEWSWORLDSERVICE-2062: put zhongwen on CPS front page temporarily #12051

Merged
merged 16 commits into from
Oct 17, 2024
Merged
5 changes: 3 additions & 2 deletions src/app/legacy/containers/StoryPromo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const StoryPromoContainer = ({
sectionType = '',
}) => {
const { script, service } = useContext(ServiceContext);
const { isAmp, isLite, pageType } = useContext(RequestContext);
const { isAmp, isLite, pageType, variant } = useContext(RequestContext);
const handleClickTracking = useCombinedClickTrackerHandler(eventTrackingData);

const linkId = buildUniquePromoId({
Expand All @@ -167,7 +167,8 @@ const StoryPromoContainer = ({
isAssetTypeCode === 'PRO' &&
pathOr(null, ['contentType'], item) === 'Guide';
const headline = getHeadline(item);
const url = getUrl(item);

const url = getUrl(item, variant);
const isLive = getIsLive(item);

const overtypedSummary = pathOr(null, ['overtypedSummary'], item);
Expand Down
9 changes: 7 additions & 2 deletions src/app/lib/utilities/getStoryPromoInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ export const getHeadline = item => {
return headline;
};

export const getUrl = item => {
export const getUrl = (item, variant = null) => {
const assetUri = pathOr(null, ['locators', 'assetUri'], item);
const canonicalUrl = pathOr(null, ['locators', 'canonicalUrl'], item);
const uri = pathOr(null, ['uri'], item);
let uri = pathOr(null, ['uri'], item);
if (uri && variant) {
if (uri.indexOf('/articles/') !== -1 && uri.indexOf(`/${variant}`) === -1) {
uri = uri.substr(0, uri.length - variant.length) + variant;
}
}

return assetUri || makeRelativeUrlPath(uri) || canonicalUrl;
};
Expand Down
37 changes: 37 additions & 0 deletions src/app/lib/utilities/getStoryPromoInfo/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ const assetTypeCode = {
type: 'link',
};

const optimoPromoItem = {
name: '以色列哈马斯战争一周年:当地人的生活改变——受伤、成为孤儿、精神创伤',
summary: 'abc',
indexImage: {
id: '64061011',
subType: 'index',
href: 'http://b.files.bbci.co.uk/2B08/test/_64061011_3d193a51-62c9-4853-a403-cafa9f26cee3.jpg',
path: '/cpsdevpb/2B08/test/_64061011_3d193a51-62c9-4853-a403-cafa9f26cee3.jpg',
height: 288,
width: 512,
altText: '一個男子在烤披薩。',
caption: '從左到右: 阿卜杜拉, 巴特舍瓦,阿卜杜勒拉赫曼, 克里斯蒂娜',
copyrightHolder: 'Stanley Leung',
allowSyndication: true,
type: 'image',
},
uri: 'https://www.bbc.com/zhongwen/articles/cl01rmr1d8po/trad',
aresUrl:
'https://ares-api.test.api.bbci.co.uk/api/asset/zhongwen/articles/cl01rmr1d8po/trad',
contentType: 'Text',
assetTypeCode: 'PRO',
timestamp: 1728290963000,
type: 'link',
};

const noAssetTypeCode = {
headlines: {
headline:
Expand Down Expand Up @@ -109,6 +134,18 @@ describe('getStoryPromoInfo', () => {
);
});

it('should return the correct url for optimoPromoItem', () => {
expect(getUrl(optimoPromoItem, 'trad')).toEqual(
'/zhongwen/articles/cl01rmr1d8po/trad',
);
expect(getUrl(optimoPromoItem, 'simp')).toEqual(
'/zhongwen/articles/cl01rmr1d8po/simp',
);
expect(getUrl(optimoPromoItem)).toEqual(
'/zhongwen/articles/cl01rmr1d8po/trad',
);
});

it('should return the correct url for live asset', () => {
const liveAsset = { ...noAssetTypeCode, cpsType: 'LIV' };
expect(getUrl(liveAsset)).toEqual('/turkce/haberler-dunya-48735662');
Expand Down
Loading