@financial-times/x-teaser 18.2.0 → 18.2.1

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.
@@ -17,9 +17,8 @@ const ScoopLabelSpy = jest
17
17
  const PremiumLabelSpy = jest
18
18
  .spyOn(PremiumLabel, 'default')
19
19
  .mockReturnValue(<div className="premium-label">PremiumLabel</div>)
20
- const AlwaysShowTimestampSpy = jest
21
- .spyOn(AlwaysShowTimestamp, 'default')
22
- .mockReturnValue(<div className="always-show-timestamp">AlwaysShowTimestamp</div>)
20
+ // don't mock this component as we want to test its logic
21
+ const AlwaysShowTimestampSpy = jest.spyOn(AlwaysShowTimestamp, 'default')
23
22
  const RelativeTimeSpy = jest
24
23
  .spyOn(RelativeTime, 'default')
25
24
  .mockReturnValue(<div className="relative-time">RelativeTimeSpy</div>)
@@ -128,8 +127,6 @@ describe('Status - Display Logic', () => {
128
127
  expect(LiveBlogStatusSpy).not.toHaveBeenCalled()
129
128
  expect(ScoopLabelSpy).not.toHaveBeenCalled()
130
129
  expect(AlwaysShowTimestampSpy).not.toHaveBeenCalled()
131
- expect(RelativeTimeSpy).not.toHaveBeenCalled()
132
- expect(TimeStampSpy).not.toHaveBeenCalled()
133
130
  })
134
131
 
135
132
  it('should not render PremiumLabel when showPremiumLabel = false', () => {
@@ -155,6 +152,9 @@ describe('Status - Display Logic', () => {
155
152
  })
156
153
 
157
154
  it('renders only AlwaysShowTimestamp when higher-level render props are absent and AlwaysShowTimestamp props are present', () => {
155
+ AlwaysShowTimestampSpy.mockReturnValueOnce(
156
+ <div className="always-show-timestamp">AlwaysShowTimestamp</div>
157
+ )
158
158
  mount(<Status {...props} />)
159
159
 
160
160
  expect(AlwaysShowTimestampSpy).toHaveBeenCalledTimes(1)
@@ -179,6 +179,27 @@ describe('Status - Display Logic', () => {
179
179
  expect(AlwaysShowTimestampSpy).not.toHaveBeenCalled()
180
180
  })
181
181
 
182
+ it('should select RelativeTime when publishedDate is same as today in AlwaysShowTimestamp', () => {
183
+ props.publishedDate = new Date().toISOString()
184
+ mount(<Status {...props} />)
185
+
186
+ expect(AlwaysShowTimestampSpy).toHaveBeenCalledTimes(1)
187
+ expect(RelativeTimeSpy).toHaveBeenCalledTimes(1)
188
+ expect(TimeStampSpy).not.toHaveBeenCalled()
189
+ })
190
+
191
+ it('should select TimeStamp when publishedDate is not the same as today in AlwaysShowTimestamp', () => {
192
+ const yesterday = new Date()
193
+ // yes this works on the first of the month too
194
+ yesterday.setDate(yesterday.getDate() - 1)
195
+ props.publishedDate = yesterday.toISOString()
196
+ mount(<Status {...props} />)
197
+
198
+ expect(AlwaysShowTimestampSpy).toHaveBeenCalledTimes(1)
199
+ expect(TimeStampSpy).toHaveBeenCalledTimes(1)
200
+ expect(RelativeTimeSpy).not.toHaveBeenCalled()
201
+ })
202
+
182
203
  it('should not render AlwaysShowTimestamp when useRelativeTimeIfToday = false', () => {
183
204
  props.useRelativeTimeIfToday = false
184
205
  mount(<Status {...props} />)
@@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var xEngine = require('@financial-times/x-engine');
8
8
  var dateformat = _interopDefault(require('dateformat'));
9
- var dateFns = require('date-fns');
10
9
 
11
10
  /**
12
11
  * Rules are sets of exclusive properties.
@@ -476,7 +475,7 @@ var LiveBlogStatus = ({
476
475
  var AlwaysShowTimestamp = props => {
477
476
  const localTodayDate = new Date().toISOString().substr(0, 10); // keep only the date bit
478
477
  const dateToCompare = new Date(props.publishedDate).toISOString().substr(0, 10);
479
- if (dateFns.differenceInCalendarDays(localTodayDate, dateToCompare) >= 1) {
478
+ if (localTodayDate !== dateToCompare) {
480
479
  return xEngine.h(TimeStamp, props);
481
480
  } else {
482
481
  return xEngine.h(RelativeTime, Object.assign({}, props, {
@@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var xEngine = require('@financial-times/x-engine');
8
8
  var dateformat = _interopDefault(require('dateformat'));
9
- var dateFns = require('date-fns');
10
9
 
11
10
  /**
12
11
  * Rules are sets of exclusive properties.
@@ -561,7 +560,7 @@ var LiveBlogStatus = (function (_ref) {
561
560
  var AlwaysShowTimestamp = (function (props) {
562
561
  var localTodayDate = new Date().toISOString().substr(0, 10); // keep only the date bit
563
562
  var dateToCompare = new Date(props.publishedDate).toISOString().substr(0, 10);
564
- if (dateFns.differenceInCalendarDays(localTodayDate, dateToCompare) >= 1) {
563
+ if (localTodayDate !== dateToCompare) {
565
564
  return xEngine.h(TimeStamp, props);
566
565
  } else {
567
566
  return xEngine.h(RelativeTime, Object.assign({}, props, {
@@ -1,6 +1,5 @@
1
1
  import { h } from '@financial-times/x-engine';
2
2
  import dateformat from 'dateformat';
3
- import { differenceInCalendarDays } from 'date-fns';
4
3
 
5
4
  /**
6
5
  * Rules are sets of exclusive properties.
@@ -470,7 +469,7 @@ var LiveBlogStatus = ({
470
469
  var AlwaysShowTimestamp = props => {
471
470
  const localTodayDate = new Date().toISOString().substr(0, 10); // keep only the date bit
472
471
  const dateToCompare = new Date(props.publishedDate).toISOString().substr(0, 10);
473
- if (differenceInCalendarDays(localTodayDate, dateToCompare) >= 1) {
472
+ if (localTodayDate !== dateToCompare) {
474
473
  return h(TimeStamp, props);
475
474
  } else {
476
475
  return h(RelativeTime, Object.assign({}, props, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@financial-times/x-teaser",
3
- "version": "18.2.0",
3
+ "version": "18.2.1",
4
4
  "description": "This module provides templates for use with o-teaser. Teasers are used to present content.",
5
5
  "source": "src/Teaser.jsx",
6
6
  "main": "dist/Teaser.cjs.js",
@@ -18,8 +18,7 @@
18
18
  "author": "",
19
19
  "license": "ISC",
20
20
  "dependencies": {
21
- "@financial-times/x-engine": "^18.2.0",
22
- "date-fns": "^2.30.0",
21
+ "@financial-times/x-engine": "^18.2.1",
23
22
  "dateformat": "^3.0.3"
24
23
  },
25
24
  "devDependencies": {
@@ -1,7 +1,6 @@
1
1
  import { h } from '@financial-times/x-engine'
2
2
  import TimeStamp from './TimeStamp'
3
3
  import RelativeTime from './RelativeTime'
4
- import { differenceInCalendarDays } from 'date-fns'
5
4
 
6
5
  /**
7
6
  * Timestamp shown always, the default 4h limit does not apply here
@@ -12,7 +11,7 @@ export default (props) => {
12
11
  const localTodayDate = new Date().toISOString().substr(0, 10) // keep only the date bit
13
12
  const dateToCompare = new Date(props.publishedDate).toISOString().substr(0, 10)
14
13
 
15
- if (differenceInCalendarDays(localTodayDate, dateToCompare) >= 1) {
14
+ if (localTodayDate !== dateToCompare) {
16
15
  return <TimeStamp {...props} />
17
16
  } else {
18
17
  return <RelativeTime {...props} showAlways={true} />