Skip to content

Commit

Permalink
NEWSWORLDSERVICE-2062: put zhongwen on CPS front page temporarily (#1…
Browse files Browse the repository at this point in the history
…2051)

* CHG: put zhongwen on CPS front page temporarily

* FIX: unit tests

* FIX: linting

* FIX: handle homepages better

* FIX: data transform

* FIX: snapshot

* Update src/app/routes/utils/regex/utils/index.js

Co-authored-by: Karina Thomas <[email protected]>

* Update src/app/routes/utils/regex/index.test.js

Co-authored-by: Karina Thomas <[email protected]>

* Update src/app/routes/utils/regex/utils/index.js

Co-authored-by: Karina Thomas <[email protected]>

* Update src/app/routes/utils/regex/utils/index.js

Co-authored-by: Karina Thomas <[email protected]>

* Update src/server/local/index.test.js

Co-authored-by: Karina Thomas <[email protected]>

* ENH: all variants

* FIX: snapshots

* ENH: add tests

* FIX: lint

* FIX: remove extra arg

---------

Co-authored-by: Karina Thomas <[email protected]>
  • Loading branch information
eagerterrier and karinathomasbbc authored Oct 17, 2024
1 parent a27e51c commit d129612
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
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

0 comments on commit d129612

Please sign in to comment.