@times-components/ts-components 1.32.0 → 1.32.3

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,50 +1,57 @@
1
1
  import React from 'react';
2
2
  import { storiesOf } from '@storybook/react';
3
- import { date, select, text } from '@storybook/addon-knobs';
3
+ import { select, text } from '@storybook/addon-knobs';
4
+ import {
5
+ // format,
6
+ addMinutes
7
+ } from 'date-fns';
8
+ // import { utcToZonedTime } from 'date-fns-tz';
4
9
 
5
10
  import { ArticleHarness } from '../../fixtures/article-harness/ArticleHarness';
6
11
  import ArticleHeader from './ArticleHeader';
7
12
 
13
+ const getAttributes = () => {
14
+ const id = 'Options';
15
+
16
+ const now = new Date();
17
+ const updated = text('Updated', addMinutes(now, -10).toISOString(), id);
18
+
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);
22
+
23
+ const options = { True: 'true', False: undefined };
24
+ const breaking = select('Breaking', options, 'true', id);
25
+
26
+ const headline = text('Headline', 'This is the headline', id);
27
+
28
+ return { updated, breaking, headline };
29
+ };
30
+
8
31
  storiesOf('Typescript Component/Article Header', module)
9
32
  .addDecorator((storyFn: () => React.ReactNode) => (
10
33
  <ArticleHarness>{storyFn()}</ArticleHarness>
11
34
  ))
12
35
  .add('Article Header with headline', () => {
13
- const label = 'Updated Date/Time';
14
- const defaultValue = new Date();
15
- const groupId = 'Options';
16
- const value = date(label, defaultValue, groupId);
17
- const breakingOptions = {
18
- True: 'true',
19
- False: undefined
20
- };
21
- const updated = new Date(value).toISOString();
22
-
23
- const headline = text('Headline', 'This is the headline', groupId);
24
-
36
+ const props = getAttributes();
25
37
  return (
26
38
  <ArticleHeader
27
- updated={updated}
28
- breaking={select('Breaking', breakingOptions, undefined, groupId)}
29
- headline={encodeURIComponent(headline)}
39
+ updated={props.updated}
40
+ // date={props.date}
41
+ // time={props.time}
42
+ breaking={props.breaking}
43
+ headline={encodeURIComponent(props.headline)}
30
44
  />
31
45
  );
32
46
  })
33
47
  .add('Article Header without headline', () => {
34
- const label = 'Updated Date/Time';
35
- const defaultValue = new Date();
36
- const groupId = 'Options';
37
- const value = date(label, defaultValue, groupId);
38
- const breakingOptions = {
39
- True: 'true',
40
- False: undefined
41
- };
42
- const updated = new Date(value).toISOString();
43
-
48
+ const props = getAttributes();
44
49
  return (
45
50
  <ArticleHeader
46
- updated={updated}
47
- breaking={select('Breaking', breakingOptions, undefined, groupId)}
51
+ updated={props.updated}
52
+ // date={props.date}
53
+ // time={props.time}
54
+ breaking={props.breaking}
48
55
  />
49
56
  );
50
57
  });
@@ -1,10 +1,18 @@
1
1
  import React from 'react';
2
2
  import {
3
+ // parse,
3
4
  format,
4
5
  differenceInSeconds,
5
6
  differenceInCalendarDays,
6
7
  formatDistanceStrict
7
8
  } from 'date-fns';
9
+ import {
10
+ // zonedTimeToUtc,
11
+ utcToZonedTime
12
+ } from 'date-fns-tz';
13
+
14
+ import { BreakingArticleFlag } from '../article-flag/LiveArticleFlag';
15
+ import safeDecodeURIComponent from '../../utils/safeDecodeURIComponent';
8
16
 
9
17
  import {
10
18
  Container,
@@ -18,39 +26,50 @@ import {
18
26
  UpdatesContainer,
19
27
  FlagContainer
20
28
  } from './styles';
21
- import { BreakingArticleFlag } from '../article-flag/LiveArticleFlag';
22
- import safeDecodeURIComponent from '../../utils/safeDecodeURIComponent';
29
+
30
+ const anchorString = (updateTxt = '', headlineTxt = '') => {
31
+ const onlyNumbersReg = /\D+/g;
32
+ const onlyNumbers = updateTxt.replace(onlyNumbersReg, '');
33
+ const acronymReg = /\b(\w)/g;
34
+ const acronymMatch = headlineTxt.match(acronymReg);
35
+ const acronym = acronymMatch === null ? '' : acronymMatch.join('');
36
+ return `u_${onlyNumbers}${acronym}`;
37
+ };
23
38
 
24
39
  const ArticleHeader: React.FC<{
25
40
  updated: string;
41
+ // date: string;
42
+ // time: string;
26
43
  breaking?: string;
27
44
  headline?: string;
28
45
  }> = ({ updated, breaking, headline }) => {
29
46
  const currentDateTime = new Date();
47
+
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
+
30
52
  const updatedDate = new Date(updated);
53
+ const parsedDate = utcToZonedTime(updatedDate, 'Europe/London');
54
+
31
55
  const timeSincePublishing =
32
56
  formatDistanceStrict(updatedDate, currentDateTime, {
33
57
  roundingMethod: 'floor'
34
58
  }) + ' ago';
35
- const diffInSeconds = differenceInSeconds(currentDateTime, updatedDate);
36
- const anchorString = (updateTxt = '', headlineTxt = '') => {
37
- const onlyNumbersReg = /\D+/g;
38
- const onlyNumbers = updateTxt.replace(onlyNumbersReg, '');
39
- const acronymReg = /\b(\w)/g;
40
- const acronymMatch = headlineTxt.match(acronymReg);
41
- const acronym = acronymMatch === null ? '' : acronymMatch.join('');
42
- return `u_${onlyNumbers}${acronym}`;
43
- };
44
59
 
60
+ const diffInSeconds = differenceInSeconds(currentDateTime, updatedDate);
45
61
  const isLessThan1Minute = diffInSeconds < 60;
46
62
  const isLessThan1Hour = diffInSeconds < 60 * 60;
47
63
  const isLessThan13Hours = diffInSeconds < 60 * 60 * 13;
48
- const isDaysAgo = differenceInCalendarDays(currentDateTime, updatedDate) >= 1;
49
- const anchorPoint = anchorString(updated, headline);
64
+
65
+ const isDaysAgo = differenceInCalendarDays(currentDateTime, parsedDate) >= 1;
66
+
50
67
  const isBreaking = breaking
51
68
  ? Boolean(breaking.toLowerCase() === 'true')
52
69
  : false;
53
70
 
71
+ const anchorPoint = anchorString(updated, headline);
72
+
54
73
  return (
55
74
  <Container isBreaking={isBreaking && isLessThan1Hour} id={anchorPoint}>
56
75
  <UpdatesContainer>
@@ -60,30 +79,28 @@ const ArticleHeader: React.FC<{
60
79
  <BreakingArticleFlag />
61
80
  </FlagContainer>
62
81
  ) : null}
82
+
63
83
  {!isLessThan1Minute && isLessThan13Hours ? (
64
84
  <TimeSincePublishingContainer>
65
- <TimeSincePublishing
66
- isBreaking={isBreaking}
67
- data-testId="TimeSincePublishing"
68
- >
85
+ <TimeSincePublishing data-testId="TimeSincePublishing">
69
86
  {timeSincePublishing}
70
87
  </TimeSincePublishing>
71
88
  <Divider />
72
89
  </TimeSincePublishingContainer>
73
90
  ) : null}
91
+
74
92
  <UpdatedTime
75
93
  isLessThan13Hours={!isLessThan1Minute && isLessThan13Hours}
76
- data-testId="UpdatedTime"
77
94
  >
78
- {format(updatedDate, 'h.mmaaa')}
95
+ {format(parsedDate, 'h.mmaaa')}
79
96
  </UpdatedTime>
80
97
  </UpdatedTimeItems>
98
+
81
99
  {isDaysAgo ? (
82
- <UpdatedDate data-testid="UpdatedDate">
83
- {format(updatedDate, 'MMMM d yyyy')}
84
- </UpdatedDate>
100
+ <UpdatedDate>{format(parsedDate, 'MMMM d yyyy')}</UpdatedDate>
85
101
  ) : null}
86
102
  </UpdatesContainer>
103
+
87
104
  {headline && <Headline>{safeDecodeURIComponent(headline)}</Headline>}
88
105
  </Container>
89
106
  );
@@ -1,183 +1,294 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
  import '@testing-library/jest-dom';
4
+ import MockDate from 'mockdate';
4
5
 
5
6
  import ArticleHeader from '../ArticleHeader';
6
- import MockDate from 'mockdate';
7
7
 
8
8
  describe('ArticleHeader', () => {
9
- describe('In one calendar day', () => {
10
- const updated = '2021-12-31T06:30:00Z';
9
+ describe('Same calendar day during GMT', () => {
11
10
  afterEach(() => MockDate.reset());
12
- it('Within the first minute of update - Breaking', () => {
13
- MockDate.set('2021-12-31T06:30:00Z');
14
- const { baseElement, getByText, queryByTestId } = render(
15
- <ArticleHeader
16
- updated={updated}
17
- breaking="true"
18
- headline="This%20is%20the%20headline"
19
- />
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} />
20
19
  );
21
- expect(baseElement).toMatchSnapshot();
22
- expect(getByText('BREAKING')).toBeVisible();
23
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
20
+
24
21
  expect(getByText('6.30am')).toBeVisible();
25
22
  expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
26
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
27
- expect(getByText('This is the headline')).toBeVisible();
28
23
  });
29
- it('Within the first minute of update - Not Breaking', () => {
30
- MockDate.set('2021-12-31T06:30:00Z');
31
- const { baseElement, getByText, queryByTestId, queryByText } = render(
32
- <ArticleHeader
33
- updated={updated}
34
- breaking="false"
35
- headline="This%20is%20the%20headline"
36
- />
37
- );
38
- expect(baseElement).toMatchSnapshot();
39
- expect(queryByText('BREAKING')).toBeFalsy();
40
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
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
+
41
30
  expect(getByText('6.30am')).toBeVisible();
42
- expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
43
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
44
- expect(getByText('This is the headline')).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();
45
41
  });
46
- it('Within the first minute of update - No headline not breaking', () => {
47
- MockDate.set('2021-12-31T06:30:00Z');
48
- const { baseElement, getByText, queryByTestId, queryByText } = render(
42
+
43
+ it('After 12 hours but same calendar day', () => {
44
+ MockDate.set('2021-12-20T20:30:00Z');
45
+
46
+ const { getByText, queryByTestId } = render(
49
47
  <ArticleHeader updated={updated} />
50
48
  );
51
- expect(baseElement).toMatchSnapshot();
52
- expect(queryByText('This is the headline')).toBeFalsy();
53
- expect(queryByText('BREAKING')).toBeFalsy();
54
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
49
+
55
50
  expect(getByText('6.30am')).toBeVisible();
56
51
  expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
57
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
58
52
  });
59
- it('within an hour of updating', () => {
53
+
54
+ it('With breaking flag and headline', () => {
60
55
  MockDate.set('2021-12-31T07:00:00Z');
61
- const { getByText, queryByTestId } = render(
56
+
57
+ const { baseElement, getByText } = render(
62
58
  <ArticleHeader
63
59
  updated={updated}
64
60
  breaking="true"
65
61
  headline="This%20is%20the%20headline"
66
62
  />
67
63
  );
68
- expect(getByText('BREAKING')).toBeVisible();
69
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
64
+
70
65
  expect(getByText('6.30am')).toBeVisible();
71
- expect(queryByTestId('TimeSincePublishing')).toBeTruthy();
72
66
  expect(getByText('30 minutes ago')).toBeVisible();
73
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
67
+ expect(getByText('BREAKING')).toBeVisible();
74
68
  expect(getByText('This is the headline')).toBeVisible();
69
+
70
+ expect(baseElement).toMatchSnapshot();
75
71
  });
76
- it('between 1 and 12 hours after update time', () => {
72
+
73
+ it('With breaking flag expired', () => {
77
74
  MockDate.set('2021-12-31T08:30:00Z');
78
- const { getByText, queryByTestId, queryByText } = render(
79
- <ArticleHeader
80
- updated={updated}
81
- breaking="true"
82
- headline="This%20is%20the%20headline"
83
- />
75
+
76
+ const { getByText, queryByText } = render(
77
+ <ArticleHeader updated={updated} breaking="true" />
84
78
  );
79
+
80
+ expect(getByText('6.30am')).toBeVisible();
81
+ expect(getByText('2 hours ago')).toBeVisible();
85
82
  expect(queryByText('BREAKING')).toBeFalsy();
86
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
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
+
87
116
  expect(getByText('6.30am')).toBeVisible();
88
- expect(queryByTestId('TimeSincePublishing')).toBeTruthy();
89
117
  expect(getByText('2 hours ago')).toBeVisible();
90
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
91
- expect(getByText('This is the headline')).toBeVisible();
92
118
  });
93
- it('after 12 hours but on the same calendar day', () => {
94
- MockDate.set('2021-12-31T19:30:00Z');
95
- const { getByText, queryByTestId, queryByText } = render(
96
- <ArticleHeader
97
- updated={updated}
98
- breaking="true"
99
- headline="This%20is%20the%20headline"
100
- />
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} />
101
125
  );
102
- expect(queryByText('BREAKING')).toBeFalsy();
103
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
126
+
104
127
  expect(getByText('6.30am')).toBeVisible();
105
128
  expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
106
- expect(queryByTestId('UpdatedDate')).toBeFalsy();
107
- expect(getByText('This is the headline')).toBeVisible();
108
129
  });
109
130
  });
110
- describe('Across calendar days', () => {
111
- const updated = '2021-12-31T23:30:00Z';
131
+
132
+ describe('Different calendar days', () => {
112
133
  afterEach(() => MockDate.reset());
113
- it('within an hour of updating but on a different calendar day', () => {
114
- MockDate.set('2022-01-01T00:29:00Z');
115
- const { getByTestId, queryByTestId, getByText } = render(
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
+ /*
150
+ describe('ArticleHeader', () => {
151
+ describe('Same calendar day during GMT', () => {
152
+ afterEach(() => MockDate.reset());
153
+
154
+ const date = '31/12/2021';
155
+ const time = '06:30';
156
+
157
+ it('Within a minute of updating', () => {
158
+ MockDate.set('2021-12-31T06:30:10Z');
159
+
160
+ const { getByText, queryByTestId } = render(
161
+ <ArticleHeader date={date} time={time} />
162
+ );
163
+
164
+ expect(getByText('6.30am')).toBeVisible();
165
+ expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
166
+ });
167
+
168
+ it('Within an hour of updating', () => {
169
+ MockDate.set('2021-12-31T07:00:00Z');
170
+
171
+ const { getByText } = render(<ArticleHeader date={date} time={time} />);
172
+
173
+ expect(getByText('6.30am')).toBeVisible();
174
+ expect(getByText('30 minutes ago')).toBeVisible();
175
+ });
176
+
177
+ it('Between 1 and 12 hours after updating', () => {
178
+ MockDate.set('2021-12-31T08:30:00Z');
179
+
180
+ const { getByText } = render(<ArticleHeader date={date} time={time} />);
181
+
182
+ expect(getByText('6.30am')).toBeVisible();
183
+ expect(getByText('2 hours ago')).toBeVisible();
184
+ });
185
+
186
+ it('After 12 hours but same calendar day', () => {
187
+ MockDate.set('2021-12-20T20:30:00Z');
188
+
189
+ const { getByText, queryByTestId } = render(
190
+ <ArticleHeader date={date} time={time} />
191
+ );
192
+
193
+ expect(getByText('6.30am')).toBeVisible();
194
+ expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
195
+ });
196
+
197
+ it('With breaking flag and headline', () => {
198
+ MockDate.set('2021-12-31T07:00:00Z');
199
+
200
+ const { baseElement, getByText } = render(
116
201
  <ArticleHeader
117
- updated={updated}
202
+ date={date}
203
+ time={time}
118
204
  breaking="true"
119
205
  headline="This%20is%20the%20headline"
120
206
  />
121
207
  );
208
+
209
+ expect(getByText('6.30am')).toBeVisible();
210
+ expect(getByText('30 minutes ago')).toBeVisible();
122
211
  expect(getByText('BREAKING')).toBeVisible();
123
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
124
- expect(getByText('11.30pm')).toBeVisible();
125
- expect(getByTestId('TimeSincePublishing')).toBeTruthy();
126
- expect(getByTestId('UpdatedDate')).toBeVisible();
127
- expect(getByText('December 31 2021')).toBeVisible();
128
212
  expect(getByText('This is the headline')).toBeVisible();
213
+
214
+ expect(baseElement).toMatchSnapshot();
129
215
  });
130
- it('between 1-12 hours of updating but on a different calendar day', () => {
131
- MockDate.set('2022-01-01T02:00:00Z');
132
- const { getByTestId, queryByText, queryByTestId, getByText } = render(
133
- <ArticleHeader
134
- updated={updated}
135
- breaking="true"
136
- headline="This%20is%20the%20headline"
137
- />
216
+
217
+ it('With breaking flag expired', () => {
218
+ MockDate.set('2021-12-31T08:30:00Z');
219
+
220
+ const { getByText, queryByText } = render(
221
+ <ArticleHeader date={date} time={time} breaking="true" />
138
222
  );
139
- expect(queryByText('BREAKING')).toBeFalsy();
140
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
141
- expect(getByText('11.30pm')).toBeVisible();
142
- expect(getByTestId('TimeSincePublishing')).toBeTruthy();
223
+
224
+ expect(getByText('6.30am')).toBeVisible();
143
225
  expect(getByText('2 hours ago')).toBeVisible();
144
- expect(getByTestId('UpdatedDate')).toBeVisible();
145
- expect(getByText('December 31 2021')).toBeVisible();
146
- expect(getByText('This is the headline')).toBeVisible();
226
+ expect(queryByText('BREAKING')).toBeFalsy();
147
227
  });
148
- it('after 12 hours but on a different calendar day', () => {
149
- MockDate.set('2022-01-01T14:30:00Z');
150
- const { getByTestId, queryByText, queryByTestId, getByText } = render(
151
- <ArticleHeader
152
- updated={updated}
153
- breaking="true"
154
- headline="This%20is%20the%20headline"
155
- />
228
+ });
229
+
230
+ describe('Same calendar day during BST', () => {
231
+ afterEach(() => MockDate.reset());
232
+
233
+ const date = '20/04/2022';
234
+ const time = '06:30';
235
+
236
+ it('Within a minute of updating', () => {
237
+ MockDate.set('2022-04-20T06:30:10+01:00');
238
+
239
+ const { getByText, queryByTestId } = render(
240
+ <ArticleHeader date={date} time={time} />
156
241
  );
157
- expect(queryByText('BREAKING')).toBeFalsy();
158
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
159
- expect(getByText('11.30pm')).toBeVisible();
242
+
243
+ expect(getByText('6.30am')).toBeVisible();
160
244
  expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
161
- expect(getByTestId('UpdatedDate')).toBeVisible();
162
- expect(getByText('December 31 2021')).toBeVisible();
163
- expect(getByText('This is the headline')).toBeVisible();
164
245
  });
165
- it('after multiple calendar days', () => {
166
- MockDate.set('2022-01-03T14:30:00Z');
167
- const { getByTestId, queryByText, queryByTestId, getByText } = render(
168
- <ArticleHeader
169
- updated={updated}
170
- breaking="true"
171
- headline="This%20is%20the%20headline"
172
- />
246
+
247
+ it('Within an hour of updating', () => {
248
+ MockDate.set('2022-04-20T07:00:00+01:00');
249
+
250
+ const { getByText } = render(<ArticleHeader date={date} time={time} />);
251
+
252
+ expect(getByText('6.30am')).toBeVisible();
253
+ expect(getByText('30 minutes ago')).toBeVisible();
254
+ });
255
+
256
+ it('Between 1 and 12 hours after updating', () => {
257
+ MockDate.set('2022-04-20T08:30:00+01:00');
258
+
259
+ const { getByText } = render(<ArticleHeader date={date} time={time} />);
260
+
261
+ expect(getByText('6.30am')).toBeVisible();
262
+ expect(getByText('2 hours ago')).toBeVisible();
263
+ });
264
+
265
+ it('After 12 hours but same calendar day', () => {
266
+ MockDate.set('2022-04-20T20:30:00+01:00');
267
+
268
+ const { getByText, queryByTestId } = render(
269
+ <ArticleHeader date={date} time={time} />
173
270
  );
174
- expect(queryByText('BREAKING')).toBeFalsy();
175
- expect(queryByTestId('UpdatedTime')).toBeTruthy();
176
- expect(getByText('11.30pm')).toBeVisible();
271
+
272
+ expect(getByText('6.30am')).toBeVisible();
177
273
  expect(queryByTestId('TimeSincePublishing')).toBeFalsy();
178
- expect(getByTestId('UpdatedDate')).toBeVisible();
274
+ });
275
+ });
276
+
277
+ describe('Different calendar days', () => {
278
+ afterEach(() => MockDate.reset());
279
+
280
+ const date = '31/12/2021';
281
+ const time = '22:30';
282
+
283
+ it('Between 1 and 12 hours after updating', () => {
284
+ MockDate.set('2022-01-01T02:30:00Z');
285
+
286
+ const { getByText } = render(<ArticleHeader date={date} time={time} />);
287
+
288
+ expect(getByText('10.30pm')).toBeVisible();
289
+ expect(getByText('4 hours ago')).toBeVisible();
179
290
  expect(getByText('December 31 2021')).toBeVisible();
180
- expect(getByText('This is the headline')).toBeVisible();
181
291
  });
182
292
  });
183
293
  });
294
+ */