@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.
@@ -15,7 +15,7 @@ exports[`<InlineDialog> should render the component 1`] = `
15
15
  class="sc-htpNat dBfnu"
16
16
  />
17
17
  <a
18
- class="sc-bxivhb bTkHyz"
18
+ class="sc-bxivhb buzDgg"
19
19
  href="#"
20
20
  >
21
21
  Button
@@ -34,7 +34,7 @@ export const Button = styled.a`
34
34
  align-items: center;
35
35
  justify-content: center;
36
36
  text-decoration: none;
37
-
37
+ cursor: pointer;
38
38
  background-color: #008387;
39
39
  color: white;
40
40
  font-family: ${fonts.supporting};
@@ -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 = { __typename: string; crops: MediaCrop[] };
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 = (media?: Media) =>
47
- media && media.crops
48
- ? media.crops.map(crop => ({ url: crop.url, ratio: crop.aspectRatio }))
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: getImageCrops(article.media)
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
- crops: [
107
- {
108
- url:
109
- 'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Feb05c224-e626-11ec-aa87-2eea7c6e5b01.jpg?crop=1500%2C844%2C0%2C78',
110
- alt: null,
111
- aspectRatio: '16:9'
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
  {