@times-components/ts-components 1.36.2 → 1.38.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 +33 -0
- package/dist/components/article-header/__tests__/ArticleHeader.test.js +12 -12
- package/dist/components/recommended-articles/RecommendedArticles.d.ts +4 -5
- package/dist/components/recommended-articles/RecommendedArticles.js +15 -26
- package/dist/components/recommended-articles/RecommendedArticles.stories.d.ts +5 -1
- package/dist/components/recommended-articles/RecommendedArticles.stories.js +26 -52
- package/dist/components/recommended-articles/RecommendedFetch.d.ts +6 -0
- package/dist/components/recommended-articles/RecommendedFetch.js +12 -0
- package/dist/components/recommended-articles/__tests__/RecommendedArticles.test.js +26 -60
- package/dist/components/recommended-articles/__tests__/RecommendedFetch.test.d.ts +1 -0
- package/dist/components/recommended-articles/__tests__/RecommendedFetch.test.js +14 -0
- package/dist/components/recommended-articles/formatters.d.ts +41 -0
- package/dist/components/recommended-articles/formatters.js +57 -0
- package/dist/fixtures/preview-data/recommended-articles.d.ts +84 -0
- package/dist/fixtures/preview-data/recommended-articles.js +351 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +6 -6
- package/rnw.js +1 -1
- package/src/components/article-header/__tests__/ArticleHeader.test.tsx +11 -11
- package/src/components/recommended-articles/RecommendedArticles.stories.tsx +41 -58
- package/src/components/recommended-articles/RecommendedArticles.tsx +28 -54
- package/src/components/recommended-articles/RecommendedFetch.tsx +25 -0
- package/src/components/recommended-articles/__tests__/RecommendedArticles.test.tsx +45 -75
- package/src/components/recommended-articles/__tests__/RecommendedFetch.test.tsx +23 -0
- package/src/components/recommended-articles/__tests__/__snapshots__/RecommendedArticles.test.tsx.snap +11 -55
- package/src/components/recommended-articles/__tests__/__snapshots__/RecommendedFetch.test.tsx.snap +9 -0
- package/src/components/recommended-articles/formatters.ts +100 -0
- package/src/fixtures/preview-data/recommended-articles.ts +385 -0
- package/src/index.ts +2 -2
- package/src/types/externs.d.ts +0 -7
|
@@ -18,7 +18,7 @@ describe('ArticleHeader', () => {
|
|
|
18
18
|
<ArticleHeader updated={updated} />
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
-
expect(getByText(
|
|
21
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
22
22
|
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ describe('ArticleHeader', () => {
|
|
|
27
27
|
|
|
28
28
|
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
29
29
|
|
|
30
|
-
expect(getByText(
|
|
30
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
31
31
|
expect(getByText('30 minutes ago')).toBeVisible();
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -36,7 +36,7 @@ describe('ArticleHeader', () => {
|
|
|
36
36
|
|
|
37
37
|
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
38
38
|
|
|
39
|
-
expect(getByText(
|
|
39
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
40
40
|
expect(getByText('2 hours ago')).toBeVisible();
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -47,7 +47,7 @@ describe('ArticleHeader', () => {
|
|
|
47
47
|
<ArticleHeader updated={updated} />
|
|
48
48
|
);
|
|
49
49
|
|
|
50
|
-
expect(getByText(
|
|
50
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
51
51
|
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -62,7 +62,7 @@ describe('ArticleHeader', () => {
|
|
|
62
62
|
/>
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
expect(getByText(
|
|
65
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
66
66
|
expect(getByText('30 minutes ago')).toBeVisible();
|
|
67
67
|
expect(getByText('BREAKING')).toBeVisible();
|
|
68
68
|
expect(getByText('This is the headline')).toBeVisible();
|
|
@@ -77,7 +77,7 @@ describe('ArticleHeader', () => {
|
|
|
77
77
|
<ArticleHeader updated={updated} breaking="true" />
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
expect(getByText(
|
|
80
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
81
81
|
expect(getByText('2 hours ago')).toBeVisible();
|
|
82
82
|
expect(queryByText('BREAKING')).toBeFalsy();
|
|
83
83
|
});
|
|
@@ -95,7 +95,7 @@ describe('ArticleHeader', () => {
|
|
|
95
95
|
<ArticleHeader updated={updated} />
|
|
96
96
|
);
|
|
97
97
|
|
|
98
|
-
expect(getByText(
|
|
98
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
99
99
|
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
100
100
|
});
|
|
101
101
|
|
|
@@ -104,7 +104,7 @@ describe('ArticleHeader', () => {
|
|
|
104
104
|
|
|
105
105
|
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
106
106
|
|
|
107
|
-
expect(getByText(
|
|
107
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
108
108
|
expect(getByText('30 minutes ago')).toBeVisible();
|
|
109
109
|
});
|
|
110
110
|
|
|
@@ -113,7 +113,7 @@ describe('ArticleHeader', () => {
|
|
|
113
113
|
|
|
114
114
|
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
115
115
|
|
|
116
|
-
expect(getByText(
|
|
116
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
117
117
|
expect(getByText('2 hours ago')).toBeVisible();
|
|
118
118
|
});
|
|
119
119
|
|
|
@@ -124,7 +124,7 @@ describe('ArticleHeader', () => {
|
|
|
124
124
|
<ArticleHeader updated={updated} />
|
|
125
125
|
);
|
|
126
126
|
|
|
127
|
-
expect(getByText(
|
|
127
|
+
expect(getByText(/6.30am/i)).toBeVisible();
|
|
128
128
|
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
129
129
|
});
|
|
130
130
|
});
|
|
@@ -139,7 +139,7 @@ describe('ArticleHeader', () => {
|
|
|
139
139
|
|
|
140
140
|
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
141
141
|
|
|
142
|
-
expect(getByText(
|
|
142
|
+
expect(getByText(/10.30pm/i)).toBeVisible();
|
|
143
143
|
expect(getByText('4 hours ago')).toBeVisible();
|
|
144
144
|
expect(getByText('December 31')).toBeVisible();
|
|
145
145
|
});
|
|
@@ -1,77 +1,60 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { showcaseConverter } from '@times-components/storybook';
|
|
4
|
-
import { MockedProvider } from '@times-components/provider-test-tools';
|
|
5
|
-
import { recommendations } from '@times-components/provider-queries';
|
|
6
4
|
|
|
5
|
+
import { FetchProvider } from '../../helpers/fetch/FetchProvider';
|
|
6
|
+
import previewData from '../../fixtures/preview-data/recommended-articles';
|
|
7
7
|
import analyticsStream from '../../fixtures/analytics-actions/analytics-actions';
|
|
8
|
+
|
|
8
9
|
import { RecommendedArticles } from './RecommendedArticles';
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
request: {
|
|
14
|
-
query: recommendations,
|
|
15
|
-
variables: {
|
|
16
|
-
publisher: 'TIMES',
|
|
17
|
-
recomArgs: {
|
|
18
|
-
userId: '1234',
|
|
19
|
-
articleId: '94a01926-719a-11ec-aacf-0736e08b15cd'
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
result: {
|
|
24
|
-
data: {
|
|
25
|
-
recommendations: {
|
|
26
|
-
__typename: 'Recommendations',
|
|
27
|
-
leadAsset: 'null',
|
|
28
|
-
articles: [
|
|
29
|
-
{
|
|
30
|
-
__typename: 'UniversalArticle',
|
|
31
|
-
headline:
|
|
32
|
-
'Whole world is against us, says top Russian strategist',
|
|
33
|
-
id: 'a9ffb7cc-d5d1-11ec-bb99-1bcd45646516',
|
|
34
|
-
media: {
|
|
35
|
-
__typename: 'Image'
|
|
36
|
-
},
|
|
37
|
-
slug:
|
|
38
|
-
'were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel',
|
|
39
|
-
url:
|
|
40
|
-
'https://www.staging-thetimes.co.uk/article/were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel-lhnvsfj33'
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
__typename: 'UniversalArticle',
|
|
44
|
-
headline: 'Vardys leave court with swipe at Wayne Rooney',
|
|
45
|
-
id: 'f3d730a0-d5c2-11ec-8585-951ab3afb4d2',
|
|
46
|
-
media: {
|
|
47
|
-
__typename: 'Image'
|
|
48
|
-
},
|
|
49
|
-
slug:
|
|
50
|
-
'wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time',
|
|
51
|
-
url:
|
|
52
|
-
'https://www.staging-thetimes.co.uk/article/wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time-wlzvxklc6'
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
11
|
+
export const getArticles = (data: any, numOfArticles: number) => ({
|
|
12
|
+
recommendations: {
|
|
13
|
+
articles: data.recommendations.articles.slice(0, numOfArticles)
|
|
58
14
|
}
|
|
59
|
-
|
|
15
|
+
});
|
|
60
16
|
|
|
61
|
-
const
|
|
17
|
+
const recommArticles = {
|
|
62
18
|
children: [
|
|
63
19
|
{
|
|
64
20
|
component: () => (
|
|
65
|
-
<
|
|
21
|
+
<FetchProvider previewData={getArticles(previewData, 1)}>
|
|
66
22
|
<RecommendedArticles
|
|
67
|
-
articleId="94a01926-719a-11ec-aacf-0736e08b15cd"
|
|
68
23
|
section="News"
|
|
24
|
+
isVisible
|
|
69
25
|
analyticsStream={analyticsStream}
|
|
70
26
|
/>
|
|
71
|
-
</
|
|
27
|
+
</FetchProvider>
|
|
72
28
|
),
|
|
73
|
-
|
|
74
|
-
|
|
29
|
+
name: 'Recommended Articles - 1 Article',
|
|
30
|
+
platform: 'web',
|
|
31
|
+
type: 'story'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
component: () => (
|
|
35
|
+
<FetchProvider previewData={getArticles(previewData, 2)}>
|
|
36
|
+
<RecommendedArticles
|
|
37
|
+
section="Business"
|
|
38
|
+
isVisible
|
|
39
|
+
analyticsStream={analyticsStream}
|
|
40
|
+
/>
|
|
41
|
+
</FetchProvider>
|
|
42
|
+
),
|
|
43
|
+
name: 'Recommended Articles - 2 Article',
|
|
44
|
+
platform: 'web',
|
|
45
|
+
type: 'story'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
component: () => (
|
|
49
|
+
<FetchProvider previewData={previewData}>
|
|
50
|
+
<RecommendedArticles
|
|
51
|
+
section="Sport"
|
|
52
|
+
isVisible
|
|
53
|
+
analyticsStream={analyticsStream}
|
|
54
|
+
/>
|
|
55
|
+
</FetchProvider>
|
|
56
|
+
),
|
|
57
|
+
name: 'Recommended Articles - 3 Article',
|
|
75
58
|
platform: 'web',
|
|
76
59
|
type: 'story'
|
|
77
60
|
}
|
|
@@ -79,4 +62,4 @@ const recarticles = {
|
|
|
79
62
|
name: 'Typescript Component/Recommended Articles'
|
|
80
63
|
};
|
|
81
64
|
|
|
82
|
-
showcaseConverter(module,
|
|
65
|
+
showcaseConverter(module, recommArticles);
|
|
@@ -1,69 +1,43 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { Placeholder } from '@times-components/image';
|
|
3
4
|
import RelatedArticles from '@times-components/related-articles';
|
|
4
|
-
import { GetRecommendedArticles } from '@times-components/provider';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useFetch } from '../../helpers/fetch/FetchProvider';
|
|
7
|
+
import { getRelatedArticlesSlice } from './formatters';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { PlaceholderContainer } from '../common-styles';
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
articleId: string;
|
|
11
|
+
export const RecommendedArticles: React.FC<{
|
|
12
12
|
section: string;
|
|
13
|
+
isVisible?: boolean;
|
|
13
14
|
analyticsStream?: (evt: any) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
setIsReady(true);
|
|
25
|
-
}, []);
|
|
15
|
+
}> = ({ section, isVisible, analyticsStream }) => {
|
|
16
|
+
const { loading, error, data } = useFetch<any>();
|
|
17
|
+
|
|
18
|
+
if (loading && isVisible) {
|
|
19
|
+
return (
|
|
20
|
+
<PlaceholderContainer>
|
|
21
|
+
<Placeholder />
|
|
22
|
+
</PlaceholderContainer>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
26
25
|
|
|
27
|
-
if (
|
|
26
|
+
if (error || data === undefined) {
|
|
28
27
|
return null;
|
|
29
28
|
}
|
|
30
29
|
|
|
31
30
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
ssr={false}
|
|
36
|
-
debounceTimeMs={0}
|
|
31
|
+
<div
|
|
32
|
+
id="recommended-articles"
|
|
33
|
+
style={{ display: isVisible ? 'block' : 'none' }}
|
|
37
34
|
>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<div className="placeholder">
|
|
46
|
-
<Placeholder />
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const slice: RelatedArticleSliceType = {
|
|
52
|
-
sliceName: 'StandardSlice',
|
|
53
|
-
items: recommendations
|
|
54
|
-
? recommendations.articles.map((article: any) => ({ article }))
|
|
55
|
-
: []
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<RelatedArticles
|
|
60
|
-
heading={`Today's ${section}`}
|
|
61
|
-
slice={slice}
|
|
62
|
-
isVisible
|
|
63
|
-
analyticsStream={analyticsStream}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
66
|
-
}}
|
|
67
|
-
</GetRecommendedArticles>
|
|
35
|
+
<RelatedArticles
|
|
36
|
+
heading={`Today's ${section}`}
|
|
37
|
+
slice={getRelatedArticlesSlice(data.recommendations)}
|
|
38
|
+
isVisible
|
|
39
|
+
analyticsStream={analyticsStream}
|
|
40
|
+
/>
|
|
41
|
+
</div>
|
|
68
42
|
);
|
|
69
43
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FetchProvider } from '../../helpers/fetch/FetchProvider';
|
|
4
|
+
import { RecommendedArticles } from './RecommendedArticles';
|
|
5
|
+
|
|
6
|
+
export const RecommendedFetch: React.FC<{
|
|
7
|
+
articleId: string;
|
|
8
|
+
section: string;
|
|
9
|
+
analyticsStream?: (evt: any) => void;
|
|
10
|
+
}> = ({ articleId, section, analyticsStream }) => {
|
|
11
|
+
const [isClientSide, setIsClientSide] = useState<boolean>(false);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setIsClientSide(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return isClientSide ? (
|
|
18
|
+
<FetchProvider url={`/api/recommended-articles/${articleId}`}>
|
|
19
|
+
<RecommendedArticles
|
|
20
|
+
section={section}
|
|
21
|
+
analyticsStream={analyticsStream}
|
|
22
|
+
/>
|
|
23
|
+
</FetchProvider>
|
|
24
|
+
) : null;
|
|
25
|
+
};
|
|
@@ -1,91 +1,61 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { render
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { useFetch } from '../../../helpers/fetch/FetchProvider';
|
|
5
|
+
import previewData from '../../../fixtures/preview-data/recommended-articles';
|
|
3
6
|
|
|
4
7
|
import { RecommendedArticles } from '../RecommendedArticles';
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
jest.mock('@times-components/image', () => ({
|
|
10
|
+
Placeholder: () => <div>Placeholder</div>
|
|
11
|
+
}));
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
{
|
|
11
|
-
delay: 1000,
|
|
12
|
-
request: {
|
|
13
|
-
query: recommendations,
|
|
14
|
-
variables: {
|
|
15
|
-
publisher: 'TIMES',
|
|
16
|
-
recomArgs: {
|
|
17
|
-
userId: '1234',
|
|
18
|
-
articleId: '94a01926-719a-11ec-aacf-0736e08b15cd'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
result: {
|
|
23
|
-
data: {
|
|
24
|
-
recommendations: {
|
|
25
|
-
__typename: 'Recommendations',
|
|
26
|
-
leadAsset: 'null',
|
|
27
|
-
articles: [
|
|
28
|
-
{
|
|
29
|
-
__typename: 'UniversalArticle',
|
|
30
|
-
headline:
|
|
31
|
-
'Whole world is against us, says top Russian strategist',
|
|
32
|
-
id: 'a9ffb7cc-d5d1-11ec-bb99-1bcd45646516',
|
|
33
|
-
media: {
|
|
34
|
-
__typename: 'Image'
|
|
35
|
-
},
|
|
36
|
-
slug:
|
|
37
|
-
'were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel',
|
|
38
|
-
url:
|
|
39
|
-
'https://www.staging-thetimes.co.uk/article/were-no-match-for-ukrainian-grit-and-firepower-says-retired-russian-colonel-lhnvsfj33'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
__typename: 'UniversalArticle',
|
|
43
|
-
headline: 'Vardys leave court with swipe at Wayne Rooney',
|
|
44
|
-
id: 'f3d730a0-d5c2-11ec-8585-951ab3afb4d2',
|
|
45
|
-
media: {
|
|
46
|
-
__typename: 'Image'
|
|
47
|
-
},
|
|
48
|
-
slug:
|
|
49
|
-
'wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time',
|
|
50
|
-
url:
|
|
51
|
-
'https://www.staging-thetimes.co.uk/article/wayne-rooney-to-give-evidence-in-wagatha-christie-trial-as-jamie-vardy-attends-court-for-first-time-wlzvxklc6'
|
|
52
|
-
}
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
];
|
|
13
|
+
jest.mock('@times-components/related-articles', () => 'RelatedArticles');
|
|
59
14
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
cleanup();
|
|
64
|
-
});
|
|
15
|
+
jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
16
|
+
useFetch: jest.fn()
|
|
17
|
+
}));
|
|
65
18
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
19
|
+
describe('<RecommendedArticles>', () => {
|
|
20
|
+
it('should render the initial loading state correctly', () => {
|
|
21
|
+
(useFetch as jest.Mock).mockReturnValue({ loading: true });
|
|
22
|
+
|
|
23
|
+
const { asFragment, getByText } = render(
|
|
24
|
+
<RecommendedArticles
|
|
25
|
+
section="News"
|
|
26
|
+
isVisible
|
|
27
|
+
analyticsStream={() => ({})}
|
|
28
|
+
/>
|
|
75
29
|
);
|
|
30
|
+
|
|
31
|
+
expect(getByText('Placeholder'));
|
|
76
32
|
expect(asFragment()).toMatchSnapshot();
|
|
77
33
|
});
|
|
78
34
|
|
|
79
|
-
it('
|
|
35
|
+
it('should render the error state correctly', () => {
|
|
36
|
+
(useFetch as jest.Mock).mockReturnValue({ error: 'Some error occurred' });
|
|
37
|
+
|
|
80
38
|
const { asFragment } = render(
|
|
81
|
-
<
|
|
82
|
-
<RecommendedArticles
|
|
83
|
-
articleId=""
|
|
84
|
-
section="News"
|
|
85
|
-
analyticsStream={jest.fn()}
|
|
86
|
-
/>
|
|
87
|
-
</MockedProvider>
|
|
39
|
+
<RecommendedArticles section="News" analyticsStream={() => ({})} />
|
|
88
40
|
);
|
|
41
|
+
|
|
42
|
+
expect(asFragment().firstChild).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should render RelatedArticles correctly', () => {
|
|
46
|
+
(useFetch as jest.Mock).mockReturnValue({ data: previewData });
|
|
47
|
+
|
|
48
|
+
const { container, asFragment } = render(
|
|
49
|
+
<RecommendedArticles
|
|
50
|
+
section="News"
|
|
51
|
+
isVisible
|
|
52
|
+
analyticsStream={() => ({})}
|
|
53
|
+
/>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const related = container.querySelector('relatedarticles') as HTMLElement;
|
|
57
|
+
expect(related.getAttribute('heading')).toEqual("Today's News");
|
|
58
|
+
|
|
89
59
|
expect(asFragment()).toMatchSnapshot();
|
|
90
60
|
});
|
|
91
61
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { RecommendedFetch } from '../RecommendedFetch';
|
|
5
|
+
|
|
6
|
+
jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
7
|
+
FetchProvider: () => <div>FetchProvider</div>
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('<RecommendedFetch>', () => {
|
|
11
|
+
it('should render correctly', () => {
|
|
12
|
+
const { asFragment, getByText } = render(
|
|
13
|
+
<RecommendedFetch
|
|
14
|
+
articleId="1234"
|
|
15
|
+
section="News"
|
|
16
|
+
analyticsStream={() => ({})}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(getByText('FetchProvider'));
|
|
21
|
+
expect(asFragment()).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,70 +1,26 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[
|
|
3
|
+
exports[`<RecommendedArticles> should render RelatedArticles correctly 1`] = `
|
|
4
4
|
<DocumentFragment>
|
|
5
5
|
<div
|
|
6
|
-
|
|
6
|
+
id="recommended-articles"
|
|
7
|
+
style="display: block;"
|
|
7
8
|
>
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
width="100%"
|
|
13
|
-
>
|
|
14
|
-
<svg
|
|
15
|
-
height="auto"
|
|
16
|
-
style="max-width: 25%; max-height: 50%;"
|
|
17
|
-
version="1.1"
|
|
18
|
-
viewBox="145 50 108 120"
|
|
19
|
-
width="100%"
|
|
20
|
-
>
|
|
21
|
-
<g
|
|
22
|
-
fill="none"
|
|
23
|
-
fill-rule="evenodd"
|
|
24
|
-
stroke="none"
|
|
25
|
-
stroke-width="1"
|
|
26
|
-
>
|
|
27
|
-
<path
|
|
28
|
-
d="M211.26076,54 L211.231367,54 L147.67512,54 L145,85.7081465 L146.922096,86.4489102 C146.922096,86.4489102 164.867589,68.1355181 168.301115,65.0001546 C171.728017,61.8689133 174.237132,61.0885763 176.436179,60.3527593 C180.998206,59.169681 185.977937,59.2150255 185.977937,59.2150255 L186.109581,59.2150255 L186.109581,156.560932 L169.259886,164.473953 L169.259886,166 L228.735147,166 L228.735147,164.473953 L211.889177,156.560932 L211.889177,59.2150255 L212.01751,59.2150255 C212.01751,59.2150255 216.992272,59.169681 221.558854,60.3527593 C223.757072,61.0885763 226.266601,61.8689133 229.691848,65.0001546 C233.130341,68.1355181 251.071695,86.4489102 251.071695,86.4489102 L253,85.7081465 L250.317842,54 L211.270695,54 L211.242545,54"
|
|
29
|
-
fill="#FFFFFF"
|
|
30
|
-
/>
|
|
31
|
-
</g>
|
|
32
|
-
</svg>
|
|
33
|
-
</div>
|
|
9
|
+
<relatedarticles
|
|
10
|
+
heading="Today's News"
|
|
11
|
+
slice="[object Object]"
|
|
12
|
+
/>
|
|
34
13
|
</div>
|
|
35
14
|
</DocumentFragment>
|
|
36
15
|
`;
|
|
37
16
|
|
|
38
|
-
exports[
|
|
17
|
+
exports[`<RecommendedArticles> should render the initial loading state correctly 1`] = `
|
|
39
18
|
<DocumentFragment>
|
|
40
19
|
<div
|
|
41
|
-
class="
|
|
20
|
+
class="sc-bdVaJa dwiMsX"
|
|
42
21
|
>
|
|
43
|
-
<div
|
|
44
|
-
|
|
45
|
-
height="100%"
|
|
46
|
-
style="align-items: center; background-color: rgb(237, 237, 237); bottom: 0px; justify-content: center; left: 0px; position: absolute; right: 0px; top: 0px; z-index: 0; border-radius: 0;"
|
|
47
|
-
width="100%"
|
|
48
|
-
>
|
|
49
|
-
<svg
|
|
50
|
-
height="auto"
|
|
51
|
-
style="max-width: 25%; max-height: 50%;"
|
|
52
|
-
version="1.1"
|
|
53
|
-
viewBox="145 50 108 120"
|
|
54
|
-
width="100%"
|
|
55
|
-
>
|
|
56
|
-
<g
|
|
57
|
-
fill="none"
|
|
58
|
-
fill-rule="evenodd"
|
|
59
|
-
stroke="none"
|
|
60
|
-
stroke-width="1"
|
|
61
|
-
>
|
|
62
|
-
<path
|
|
63
|
-
d="M211.26076,54 L211.231367,54 L147.67512,54 L145,85.7081465 L146.922096,86.4489102 C146.922096,86.4489102 164.867589,68.1355181 168.301115,65.0001546 C171.728017,61.8689133 174.237132,61.0885763 176.436179,60.3527593 C180.998206,59.169681 185.977937,59.2150255 185.977937,59.2150255 L186.109581,59.2150255 L186.109581,156.560932 L169.259886,164.473953 L169.259886,166 L228.735147,166 L228.735147,164.473953 L211.889177,156.560932 L211.889177,59.2150255 L212.01751,59.2150255 C212.01751,59.2150255 216.992272,59.169681 221.558854,60.3527593 C223.757072,61.0885763 226.266601,61.8689133 229.691848,65.0001546 C233.130341,68.1355181 251.071695,86.4489102 251.071695,86.4489102 L253,85.7081465 L250.317842,54 L211.270695,54 L211.242545,54"
|
|
64
|
-
fill="#FFFFFF"
|
|
65
|
-
/>
|
|
66
|
-
</g>
|
|
67
|
-
</svg>
|
|
22
|
+
<div>
|
|
23
|
+
Placeholder
|
|
68
24
|
</div>
|
|
69
25
|
</div>
|
|
70
26
|
</DocumentFragment>
|