@times-components/ts-components 1.49.5 → 1.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/components/inline-dialog/styles.js +1 -1
- package/dist/components/recommended-articles/__tests__/formatters.test.d.ts +1 -0
- package/dist/components/recommended-articles/__tests__/formatters.test.js +92 -0
- package/dist/components/recommended-articles/formatters.d.ts +3 -0
- package/dist/components/recommended-articles/formatters.js +14 -5
- package/dist/fixtures/preview-data/recommended-articles.d.ts +10 -5
- package/dist/fixtures/preview-data/recommended-articles.js +10 -8
- package/package.json +5 -5
- package/rnw.js +1 -1
- package/src/components/inline-dialog/__tests__/__snapshots__/InlineDialog.test.tsx.snap +1 -1
- package/src/components/inline-dialog/styles.ts +1 -1
- package/src/components/recommended-articles/__tests__/formatters.test.tsx +109 -0
- package/src/components/recommended-articles/formatters.ts +20 -6
- package/src/fixtures/preview-data/recommended-articles.ts +10 -8
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { getArticles } from '../helpers';
|
|
2
|
+
import previewData from '../../../fixtures/preview-data/recommended-articles';
|
|
3
|
+
|
|
4
|
+
import { getRecommendedArticlesSlice } from '../formatters';
|
|
5
|
+
|
|
6
|
+
const expectedArticles = [
|
|
7
|
+
{
|
|
8
|
+
byline:
|
|
9
|
+
'Rosie Green | Frankie Graddon | Tony Turnbull | Charlie Gowans-Eglinton',
|
|
10
|
+
datePublished: '2022-07-26T23:01:00.000Z',
|
|
11
|
+
headline: 'Save or splurge: what experts spend their own money on',
|
|
12
|
+
images: {
|
|
13
|
+
alt: 'Save or splurge: what experts spend their own money on',
|
|
14
|
+
crops: [
|
|
15
|
+
{
|
|
16
|
+
ratio: '16:9',
|
|
17
|
+
url:
|
|
18
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2F831e0f3c-e5b7-11ec-9b02-3f136f233710.jpg?crop=1600%2C900%2C0%2C0'
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
label: null,
|
|
23
|
+
summary:
|
|
24
|
+
'How is your bank balance? Even if the cost of living crisis doesn’t constitute a crisis for you, you’ll have noticed that you’re suddenly paying more for and what felt reasonable may now...',
|
|
25
|
+
url:
|
|
26
|
+
'https://www.thetimes.co.uk/article/save-or-splurge-what-experts-spend-their-own-money-on-tdd65qlj6'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
byline: '',
|
|
30
|
+
datePublished: '2022-07-27T16:00:00.000Z',
|
|
31
|
+
headline: 'Lieutenant Colonel Ian Crooke',
|
|
32
|
+
images: {
|
|
33
|
+
alt: 'Lieutenant Colonel Ian Crooke',
|
|
34
|
+
crops: [
|
|
35
|
+
{
|
|
36
|
+
ratio: '16:9',
|
|
37
|
+
url:
|
|
38
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2F5ecb5d44-e650-11ec-9b02-3f136f233710.jpg?crop=5616%2C3159%2C0%2C293'
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
label: 'Obituary',
|
|
43
|
+
summary:
|
|
44
|
+
'On August 1, 1981, Major Ian Crooke, the operations officer of 22 Special Air Service in Hereford, received a telephone call from London. A Marxist coup d’état was taking place in the former British...',
|
|
45
|
+
url:
|
|
46
|
+
'https://www.thetimes.co.uk/article/lieutenant-colonel-ian-crooke-obituary-t0b890wgp'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
byline: 'Patrick Maguire',
|
|
50
|
+
datePublished: '2022-07-27T08:00:00.000Z',
|
|
51
|
+
headline: 'Is the party over for Johnson?',
|
|
52
|
+
images: {
|
|
53
|
+
alt: 'Is the party over for Johnson?',
|
|
54
|
+
crops: [
|
|
55
|
+
{
|
|
56
|
+
ratio: '16:9',
|
|
57
|
+
url:
|
|
58
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Feb05c224-e626-11ec-aa87-2eea7c6e5b01.jpg?crop=1500%2C844%2C0%2C78'
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
label: 'RED BOX | PATRICK MAGUIRE',
|
|
63
|
+
summary:
|
|
64
|
+
'Worse than May. Worse than Major. As bad as Thatcher. of his own MPs, far more than even the most pessimistic whip predicted this time yesterday. Can Boris...',
|
|
65
|
+
url:
|
|
66
|
+
'https://www.thetimes.co.uk/article/is-the-party-over-for-boris-johnson-k8s0jxv6r'
|
|
67
|
+
}
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
describe('getRecommendedArticlesSlice()', () => {
|
|
71
|
+
it('should return the correctly formattted slice including 1 article', () => {
|
|
72
|
+
const data = getArticles(previewData, 1);
|
|
73
|
+
const articles = data.recommendations.articles;
|
|
74
|
+
const slice = getRecommendedArticlesSlice(articles);
|
|
75
|
+
|
|
76
|
+
expect(slice).toStrictEqual({
|
|
77
|
+
children: [{ article: expectedArticles[0] }],
|
|
78
|
+
name: 'RELATED_ARTICLE_1'
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should return the correctly formattted slice including 2 articles', () => {
|
|
83
|
+
const data = getArticles(previewData, 2);
|
|
84
|
+
const articles = data.recommendations.articles;
|
|
85
|
+
const slice = getRecommendedArticlesSlice(articles);
|
|
86
|
+
|
|
87
|
+
expect(slice).toStrictEqual({
|
|
88
|
+
children: [
|
|
89
|
+
{ article: expectedArticles[0] },
|
|
90
|
+
{ article: expectedArticles[1] }
|
|
91
|
+
],
|
|
92
|
+
name: 'RELATED_ARTICLE_2'
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should return the correctly formattted slice including 3 articles', () => {
|
|
97
|
+
const articles = previewData.recommendations.articles;
|
|
98
|
+
const slice = getRecommendedArticlesSlice(articles as any);
|
|
99
|
+
|
|
100
|
+
expect(slice).toStrictEqual({
|
|
101
|
+
children: [
|
|
102
|
+
{ article: expectedArticles[0] },
|
|
103
|
+
{ article: expectedArticles[1] },
|
|
104
|
+
{ article: expectedArticles[2] }
|
|
105
|
+
],
|
|
106
|
+
name: 'RELATED_ARTICLE_3'
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -12,7 +12,11 @@ type MediaCrop = {
|
|
|
12
12
|
alt?: string;
|
|
13
13
|
aspectRatio: string;
|
|
14
14
|
};
|
|
15
|
-
type Media = {
|
|
15
|
+
type Media = {
|
|
16
|
+
__typename: string;
|
|
17
|
+
crops: MediaCrop[];
|
|
18
|
+
posterImage: { crops: MediaCrop[] };
|
|
19
|
+
};
|
|
16
20
|
|
|
17
21
|
type SummaryText = { __typename: string; text: string };
|
|
18
22
|
type Summary = { __typename: string; children: SummaryText[] };
|
|
@@ -43,10 +47,20 @@ const getSummary = (summary?: Summary) =>
|
|
|
43
47
|
? summary.children.map(child => child.text).join('') + '...'
|
|
44
48
|
: undefined;
|
|
45
49
|
|
|
46
|
-
const getImageCrops = (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const getImageCrops = (crops: MediaCrop[]) =>
|
|
51
|
+
crops.map(crop => ({ url: crop.url, ratio: crop.aspectRatio }));
|
|
52
|
+
|
|
53
|
+
const getImage = (media?: Media) => {
|
|
54
|
+
if (media) {
|
|
55
|
+
if (media.crops) {
|
|
56
|
+
return getImageCrops(media.crops);
|
|
57
|
+
}
|
|
58
|
+
if (media.posterImage && media.posterImage.crops) {
|
|
59
|
+
return getImageCrops(media.posterImage.crops);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [];
|
|
63
|
+
};
|
|
50
64
|
|
|
51
65
|
// MAIN
|
|
52
66
|
|
|
@@ -60,7 +74,7 @@ const formatArticle = (article: Article): SliceArticle => {
|
|
|
60
74
|
datePublished: article.publishedDateTime,
|
|
61
75
|
images: {
|
|
62
76
|
alt: article.headline,
|
|
63
|
-
crops:
|
|
77
|
+
crops: getImage(article.media)
|
|
64
78
|
}
|
|
65
79
|
};
|
|
66
80
|
};
|
|
@@ -103,14 +103,16 @@ export default {
|
|
|
103
103
|
]
|
|
104
104
|
},
|
|
105
105
|
media: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
posterImage: {
|
|
107
|
+
crops: [
|
|
108
|
+
{
|
|
109
|
+
url:
|
|
110
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Feb05c224-e626-11ec-aa87-2eea7c6e5b01.jpg?crop=1500%2C844%2C0%2C78',
|
|
111
|
+
alt: null,
|
|
112
|
+
aspectRatio: '16:9'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
114
116
|
}
|
|
115
117
|
},
|
|
116
118
|
{
|