@times-components/ts-components 1.32.1 → 1.32.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.
- package/CHANGELOG.md +11 -0
- package/dist/components/article-header/ArticleHeader.d.ts +1 -2
- package/dist/components/article-header/ArticleHeader.js +13 -7
- package/dist/components/article-header/ArticleHeader.stories.js +19 -9
- package/dist/components/article-header/__tests__/ArticleHeader.test.js +161 -18
- package/package.json +14 -14
- package/rnw.js +1 -1
- package/src/components/article-header/ArticleHeader.stories.tsx +17 -10
- package/src/components/article-header/ArticleHeader.tsx +15 -8
- package/src/components/article-header/__tests__/ArticleHeader.test.tsx +143 -0
- package/src/components/article-header/__tests__/__snapshots__/ArticleHeader.test.tsx.snap +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { storiesOf } from '@storybook/react';
|
|
3
3
|
import { select, text } from '@storybook/addon-knobs';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
// format,
|
|
6
|
+
addMinutes
|
|
7
|
+
} from 'date-fns';
|
|
8
|
+
// import { utcToZonedTime } from 'date-fns-tz';
|
|
6
9
|
|
|
7
10
|
import { ArticleHarness } from '../../fixtures/article-harness/ArticleHarness';
|
|
8
11
|
import ArticleHeader from './ArticleHeader';
|
|
@@ -10,17 +13,19 @@ import ArticleHeader from './ArticleHeader';
|
|
|
10
13
|
const getAttributes = () => {
|
|
11
14
|
const id = 'Options';
|
|
12
15
|
|
|
13
|
-
const now =
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const updated = text('Updated', addMinutes(now, -10).toISOString(), id);
|
|
14
18
|
|
|
15
|
-
const
|
|
16
|
-
const
|
|
19
|
+
// const now = utcToZonedTime(new Date(), 'Europe/London');
|
|
20
|
+
// const date = text('Date', format(now, 'dd/MM/yyyy'), id);
|
|
21
|
+
// const time = text('Time', format(addMinutes(now, -10), 'HH:mm'), id);
|
|
17
22
|
|
|
18
23
|
const options = { True: 'true', False: undefined };
|
|
19
24
|
const breaking = select('Breaking', options, 'true', id);
|
|
20
25
|
|
|
21
26
|
const headline = text('Headline', 'This is the headline', id);
|
|
22
27
|
|
|
23
|
-
return {
|
|
28
|
+
return { updated, breaking, headline };
|
|
24
29
|
};
|
|
25
30
|
|
|
26
31
|
storiesOf('Typescript Component/Article Header', module)
|
|
@@ -31,8 +36,9 @@ storiesOf('Typescript Component/Article Header', module)
|
|
|
31
36
|
const props = getAttributes();
|
|
32
37
|
return (
|
|
33
38
|
<ArticleHeader
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
updated={props.updated}
|
|
40
|
+
// date={props.date}
|
|
41
|
+
// time={props.time}
|
|
36
42
|
breaking={props.breaking}
|
|
37
43
|
headline={encodeURIComponent(props.headline)}
|
|
38
44
|
/>
|
|
@@ -42,8 +48,9 @@ storiesOf('Typescript Component/Article Header', module)
|
|
|
42
48
|
const props = getAttributes();
|
|
43
49
|
return (
|
|
44
50
|
<ArticleHeader
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
updated={props.updated}
|
|
52
|
+
// date={props.date}
|
|
53
|
+
// time={props.time}
|
|
47
54
|
breaking={props.breaking}
|
|
48
55
|
/>
|
|
49
56
|
);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {
|
|
3
|
-
parse,
|
|
3
|
+
// parse,
|
|
4
4
|
format,
|
|
5
5
|
differenceInSeconds,
|
|
6
6
|
differenceInCalendarDays,
|
|
7
7
|
formatDistanceStrict
|
|
8
8
|
} from 'date-fns';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
// zonedTimeToUtc,
|
|
11
|
+
utcToZonedTime
|
|
12
|
+
} from 'date-fns-tz';
|
|
10
13
|
|
|
11
14
|
import { BreakingArticleFlag } from '../article-flag/LiveArticleFlag';
|
|
12
15
|
import safeDecodeURIComponent from '../../utils/safeDecodeURIComponent';
|
|
@@ -34,16 +37,20 @@ const anchorString = (updateTxt = '', headlineTxt = '') => {
|
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
const ArticleHeader: React.FC<{
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
updated: string;
|
|
41
|
+
// date: string;
|
|
42
|
+
// time: string;
|
|
39
43
|
breaking?: string;
|
|
40
44
|
headline?: string;
|
|
41
|
-
}> = ({
|
|
45
|
+
}> = ({ updated, breaking, headline }) => {
|
|
42
46
|
const currentDateTime = new Date();
|
|
43
47
|
|
|
44
|
-
const updated = `${date} ${time}`;
|
|
45
|
-
const parsedDate = parse(updated, 'dd/MM/yyyy HH:mm', new Date());
|
|
46
|
-
const updatedDate = zonedTimeToUtc(parsedDate, 'Europe/London');
|
|
48
|
+
// const updated = `${date} ${time}`;
|
|
49
|
+
// const parsedDate = parse(updated, 'dd/MM/yyyy HH:mm', new Date());
|
|
50
|
+
// const updatedDate = zonedTimeToUtc(parsedDate, 'Europe/London');
|
|
51
|
+
|
|
52
|
+
const updatedDate = new Date(updated);
|
|
53
|
+
const parsedDate = utcToZonedTime(updatedDate, 'Europe/London');
|
|
47
54
|
|
|
48
55
|
const timeSincePublishing =
|
|
49
56
|
formatDistanceStrict(updatedDate, currentDateTime, {
|
|
@@ -5,6 +5,148 @@ import MockDate from 'mockdate';
|
|
|
5
5
|
|
|
6
6
|
import ArticleHeader from '../ArticleHeader';
|
|
7
7
|
|
|
8
|
+
describe('ArticleHeader', () => {
|
|
9
|
+
describe('Same calendar day during GMT', () => {
|
|
10
|
+
afterEach(() => MockDate.reset());
|
|
11
|
+
|
|
12
|
+
const updated = '2021-12-31T06:30:00Z';
|
|
13
|
+
|
|
14
|
+
it('Within a minute of updating', () => {
|
|
15
|
+
MockDate.set('2021-12-31T06:30:10Z');
|
|
16
|
+
|
|
17
|
+
const { getByText, queryByTestId } = render(
|
|
18
|
+
<ArticleHeader updated={updated} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
22
|
+
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('Within an hour of updating', () => {
|
|
26
|
+
MockDate.set('2021-12-31T07:00:00Z');
|
|
27
|
+
|
|
28
|
+
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
29
|
+
|
|
30
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
31
|
+
expect(getByText('30 minutes ago')).toBeVisible();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Between 1 and 12 hours after updating', () => {
|
|
35
|
+
MockDate.set('2021-12-31T08:30:00Z');
|
|
36
|
+
|
|
37
|
+
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
38
|
+
|
|
39
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
40
|
+
expect(getByText('2 hours ago')).toBeVisible();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('After 12 hours but same calendar day', () => {
|
|
44
|
+
MockDate.set('2021-12-20T20:30:00Z');
|
|
45
|
+
|
|
46
|
+
const { getByText, queryByTestId } = render(
|
|
47
|
+
<ArticleHeader updated={updated} />
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
51
|
+
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('With breaking flag and headline', () => {
|
|
55
|
+
MockDate.set('2021-12-31T07:00:00Z');
|
|
56
|
+
|
|
57
|
+
const { baseElement, getByText } = render(
|
|
58
|
+
<ArticleHeader
|
|
59
|
+
updated={updated}
|
|
60
|
+
breaking="true"
|
|
61
|
+
headline="This%20is%20the%20headline"
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
66
|
+
expect(getByText('30 minutes ago')).toBeVisible();
|
|
67
|
+
expect(getByText('BREAKING')).toBeVisible();
|
|
68
|
+
expect(getByText('This is the headline')).toBeVisible();
|
|
69
|
+
|
|
70
|
+
expect(baseElement).toMatchSnapshot();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('With breaking flag expired', () => {
|
|
74
|
+
MockDate.set('2021-12-31T08:30:00Z');
|
|
75
|
+
|
|
76
|
+
const { getByText, queryByText } = render(
|
|
77
|
+
<ArticleHeader updated={updated} breaking="true" />
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
81
|
+
expect(getByText('2 hours ago')).toBeVisible();
|
|
82
|
+
expect(queryByText('BREAKING')).toBeFalsy();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('Same calendar day during BST', () => {
|
|
87
|
+
afterEach(() => MockDate.reset());
|
|
88
|
+
|
|
89
|
+
const updated = '2022-04-20T06:30:00+01:00';
|
|
90
|
+
|
|
91
|
+
it('Within a minute of updating', () => {
|
|
92
|
+
MockDate.set('2022-04-20T06:30:10+01:00');
|
|
93
|
+
|
|
94
|
+
const { getByText, queryByTestId } = render(
|
|
95
|
+
<ArticleHeader updated={updated} />
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
99
|
+
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('Within an hour of updating', () => {
|
|
103
|
+
MockDate.set('2022-04-20T07:00:00+01:00');
|
|
104
|
+
|
|
105
|
+
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
106
|
+
|
|
107
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
108
|
+
expect(getByText('30 minutes ago')).toBeVisible();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('Between 1 and 12 hours after updating', () => {
|
|
112
|
+
MockDate.set('2022-04-20T08:30:00+01:00');
|
|
113
|
+
|
|
114
|
+
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
115
|
+
|
|
116
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
117
|
+
expect(getByText('2 hours ago')).toBeVisible();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('After 12 hours but same calendar day', () => {
|
|
121
|
+
MockDate.set('2022-04-20T20:30:00+01:00');
|
|
122
|
+
|
|
123
|
+
const { getByText, queryByTestId } = render(
|
|
124
|
+
<ArticleHeader updated={updated} />
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(getByText('6.30am')).toBeVisible();
|
|
128
|
+
expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('Different calendar days', () => {
|
|
133
|
+
afterEach(() => MockDate.reset());
|
|
134
|
+
|
|
135
|
+
const updated = '2021-12-31T22:30:00Z';
|
|
136
|
+
|
|
137
|
+
it('Between 1 and 12 hours after updating', () => {
|
|
138
|
+
MockDate.set('2022-01-01T02:30:00Z');
|
|
139
|
+
|
|
140
|
+
const { getByText } = render(<ArticleHeader updated={updated} />);
|
|
141
|
+
|
|
142
|
+
expect(getByText('10.30pm')).toBeVisible();
|
|
143
|
+
expect(getByText('4 hours ago')).toBeVisible();
|
|
144
|
+
expect(getByText('December 31 2021')).toBeVisible();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
/*
|
|
8
150
|
describe('ArticleHeader', () => {
|
|
9
151
|
describe('Same calendar day during GMT', () => {
|
|
10
152
|
afterEach(() => MockDate.reset());
|
|
@@ -149,3 +291,4 @@ describe('ArticleHeader', () => {
|
|
|
149
291
|
});
|
|
150
292
|
});
|
|
151
293
|
});
|
|
294
|
+
*/
|