@times-components/ts-components 1.43.2 → 1.44.2

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.
@@ -1,60 +1,48 @@
1
1
  import React from 'react';
2
-
3
- import { showcaseConverter } from '@times-components/storybook';
2
+ import { storiesOf } from '@storybook/react';
4
3
 
5
4
  import { getArticles } from './helpers';
6
5
  import { FetchProvider } from '../../helpers/fetch/FetchProvider';
6
+ import { TrackingContextProvider } from '../../helpers/tracking/TrackingContextProvider';
7
7
  import previewData from '../../fixtures/preview-data/recommended-articles';
8
8
  import analyticsStream from '../../fixtures/analytics-actions/analytics-actions';
9
9
 
10
10
  import { RecommendedArticles } from './RecommendedArticles';
11
11
 
12
- const recommArticles = {
13
- children: [
14
- {
15
- component: () => (
16
- <FetchProvider previewData={getArticles(previewData, 1)}>
17
- <RecommendedArticles
18
- heading="Today's news"
19
- isVisible
20
- analyticsStream={analyticsStream}
21
- />
22
- </FetchProvider>
23
- ),
24
- name: 'Recommended Articles - 1 Article',
25
- platform: 'web',
26
- type: 'story'
27
- },
28
- {
29
- component: () => (
30
- <FetchProvider previewData={getArticles(previewData, 2)}>
31
- <RecommendedArticles
32
- heading="Today's business"
33
- isVisible
34
- analyticsStream={analyticsStream}
35
- />
36
- </FetchProvider>
37
- ),
38
- name: 'Recommended Articles - 2 Article',
39
- platform: 'web',
40
- type: 'story'
41
- },
42
- {
43
- component: () => (
44
- <FetchProvider previewData={previewData}>
45
- <RecommendedArticles
46
- heading="Today's sport"
47
- isVisible
48
- analyticsStream={analyticsStream}
49
- />
50
- </FetchProvider>
51
- ),
52
- name: 'Recommended Articles - 3 Article',
53
- platform: 'web',
54
- type: 'story'
55
- }
56
- ],
57
- name: 'Typescript Component/Recommended Articles'
58
- };
59
-
60
- showcaseConverter(module, recommArticles);
12
+ storiesOf('Typescript Component/Recommended Articles', module)
13
+ .addDecorator((storyFn: () => React.ReactNode) => (
14
+ <TrackingContextProvider
15
+ context={{
16
+ component: 'ArticleSkeleton',
17
+ object: 'RecommendedArticles',
18
+ attrs: {
19
+ event_navigation_action: 'navigation',
20
+ event_navigation_name: 'widget : relevant article',
21
+ event_navigation_browsing_method: 'click',
22
+ section_details: 'section : <section>',
23
+ article_name: '<headline>',
24
+ widget_headline: '<headline>',
25
+ widget_section: '<section>',
26
+ widget_type: "today's section"
27
+ }
28
+ }}
29
+ analyticsStream={analyticsStream}
30
+ >
31
+ <div>{storyFn()}</div>
32
+ </TrackingContextProvider>
33
+ ))
34
+ .add('Recommended Articles - 1 Article', () => (
35
+ <FetchProvider previewData={getArticles(previewData, 1)}>
36
+ <RecommendedArticles heading="Today's news" isVisible />
37
+ </FetchProvider>
38
+ ))
39
+ .add('Recommended Articles - 2 Article', () => (
40
+ <FetchProvider previewData={getArticles(previewData, 2)}>
41
+ <RecommendedArticles heading="Today's business" isVisible />
42
+ </FetchProvider>
43
+ ))
44
+ .add('Recommended Articles - 3 Article', () => (
45
+ <FetchProvider previewData={previewData}>
46
+ <RecommendedArticles heading="Today's sport" isVisible />
47
+ </FetchProvider>
48
+ ));
@@ -9,8 +9,7 @@ import { getRelatedArticlesSlice } from './formatters';
9
9
  export const RecommendedArticles: React.FC<{
10
10
  heading: string;
11
11
  isVisible?: boolean;
12
- analyticsStream?: (evt: any) => void;
13
- }> = ({ heading, isVisible, analyticsStream }) => {
12
+ }> = ({ heading, isVisible }) => {
14
13
  const { loading, error, data } = useFetch<any>();
15
14
 
16
15
  if (loading || error || data === undefined) {
@@ -29,7 +28,6 @@ export const RecommendedArticles: React.FC<{
29
28
  if (fireAnalyticsEvent) {
30
29
  fireAnalyticsEvent({
31
30
  action: 'Clicked',
32
- object: 'RecommendedArticles',
33
31
  attrs: { article_parent_name: found ? found.article.headline : '' }
34
32
  });
35
33
  }
@@ -45,7 +43,8 @@ export const RecommendedArticles: React.FC<{
45
43
  slice={slice}
46
44
  isVisible
47
45
  onPress={onClickHandler}
48
- analyticsStream={analyticsStream}
46
+ // tslint:disable-next-line: no-empty
47
+ analyticsStream={() => {}}
49
48
  />
50
49
  </div>
51
50
  );
@@ -9,14 +9,7 @@ export const RecommendedFetch: React.FC<{
9
9
  articleHeadline: string;
10
10
  articleSection: string;
11
11
  isVisible?: boolean;
12
- analyticsStream?: (evt: any) => void;
13
- }> = ({
14
- articleId,
15
- articleHeadline,
16
- articleSection,
17
- isVisible,
18
- analyticsStream
19
- }) => {
12
+ }> = ({ articleId, articleHeadline, articleSection, isVisible }) => {
20
13
  const [isClientSide, setIsClientSide] = useState<boolean>(false);
21
14
 
22
15
  useEffect(() => {
@@ -26,7 +19,9 @@ export const RecommendedFetch: React.FC<{
26
19
  const heading = `Today's ${articleSection}`;
27
20
 
28
21
  return isClientSide ? (
29
- <FetchProvider url={`/api/recommended-articles/${articleId}`}>
22
+ <FetchProvider
23
+ url={`/api/recommended-articles/${articleId}/todays_section`}
24
+ >
30
25
  <TrackingContextProvider
31
26
  context={{
32
27
  object: 'RecommendedArticles',
@@ -42,11 +37,7 @@ export const RecommendedFetch: React.FC<{
42
37
  }
43
38
  }}
44
39
  >
45
- <RecommendedArticles
46
- heading={heading}
47
- isVisible={isVisible}
48
- analyticsStream={analyticsStream}
49
- />
40
+ <RecommendedArticles heading={heading} isVisible={isVisible} />
50
41
  </TrackingContextProvider>
51
42
  </FetchProvider>
52
43
  ) : null;
@@ -63,9 +63,7 @@ describe('<RecommendedArticles>', () => {
63
63
  it('should render the initial loading state correctly', () => {
64
64
  (useFetch as jest.Mock).mockReturnValue({ loading: true });
65
65
 
66
- const { asFragment } = render(
67
- <RecommendedArticles heading={heading} analyticsStream={() => ({})} />
68
- );
66
+ const { asFragment } = render(<RecommendedArticles heading={heading} />);
69
67
 
70
68
  expect(asFragment().firstChild).toBeNull();
71
69
  });
@@ -73,9 +71,7 @@ describe('<RecommendedArticles>', () => {
73
71
  it('should render the error state correctly', () => {
74
72
  (useFetch as jest.Mock).mockReturnValue({ error: 'Some error occurred' });
75
73
 
76
- const { asFragment } = render(
77
- <RecommendedArticles heading={heading} analyticsStream={() => ({})} />
78
- );
74
+ const { asFragment } = render(<RecommendedArticles heading={heading} />);
79
75
 
80
76
  expect(asFragment().firstChild).toBeNull();
81
77
  });
@@ -86,11 +82,7 @@ describe('<RecommendedArticles>', () => {
86
82
  });
87
83
 
88
84
  const { asFragment, getByText } = render(
89
- <RecommendedArticles
90
- heading={heading}
91
- isVisible
92
- analyticsStream={() => ({})}
93
- />
85
+ <RecommendedArticles heading={heading} isVisible />
94
86
  );
95
87
 
96
88
  expect(getByText(heading));
@@ -104,7 +96,7 @@ describe('<RecommendedArticles>', () => {
104
96
  });
105
97
 
106
98
  const { asFragment, getByText } = render(
107
- <RecommendedArticles heading={heading} analyticsStream={() => ({})} />
99
+ <RecommendedArticles heading={heading} />
108
100
  );
109
101
 
110
102
  expect(getByText(heading));
@@ -117,11 +109,7 @@ describe('<RecommendedArticles>', () => {
117
109
  (useFetch as jest.Mock).mockReturnValue({ data: previewData });
118
110
 
119
111
  const { asFragment, getByText } = render(
120
- <RecommendedArticles
121
- heading={heading}
122
- isVisible
123
- analyticsStream={() => ({})}
124
- />
112
+ <RecommendedArticles heading={heading} isVisible />
125
113
  );
126
114
 
127
115
  expect(getByText(heading));
@@ -141,11 +129,7 @@ describe('<RecommendedArticles>', () => {
141
129
  context={initialContext}
142
130
  analyticsStream={analyticsStream}
143
131
  >
144
- <RecommendedArticles
145
- heading={heading}
146
- isVisible
147
- analyticsStream={() => ({})}
148
- />
132
+ <RecommendedArticles heading={heading} isVisible />
149
133
  </TrackingContextProvider>
150
134
  );
151
135
 
@@ -23,7 +23,6 @@ describe('<RecommendedFetch>', () => {
23
23
  articleId="1234"
24
24
  articleHeadline="Some headline"
25
25
  articleSection="News"
26
- analyticsStream={() => ({})}
27
26
  />
28
27
  );
29
28