@financial-times/x-teaser 17.0.2 → 17.0.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.
- package/__tests__/RelativeTime.test.jsx +67 -0
- package/dist/Teaser.cjs.js +2 -2
- package/dist/Teaser.es5.js +2 -2
- package/dist/Teaser.esm.js +2 -2
- package/package.json +2 -2
- package/src/RelativeTime.jsx +13 -9
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { h } = require('@financial-times/x-engine')
|
|
2
|
+
const { mount } = require('@financial-times/x-test-utils/enzyme')
|
|
3
|
+
|
|
4
|
+
import RelativeTime from '../src/RelativeTime'
|
|
5
|
+
|
|
6
|
+
jest.mock('../src/concerns/date-time', () => ({
|
|
7
|
+
isRecent: jest.fn(),
|
|
8
|
+
getRelativeDate: jest.fn(),
|
|
9
|
+
getStatus: jest.fn()
|
|
10
|
+
}))
|
|
11
|
+
|
|
12
|
+
import { isRecent, getRelativeDate, getStatus } from '../src/concerns/date-time'
|
|
13
|
+
|
|
14
|
+
describe('RelativeTime - Timestamp and Status Label Logic', () => {
|
|
15
|
+
const samplePublishedDate = '2021-10-15T12:00:00.000Z'
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks()
|
|
19
|
+
getRelativeDate.mockReturnValue('1 hour ago')
|
|
20
|
+
isRecent.mockReturnValue(true)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('NEW status', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
getStatus.mockReturnValue('new')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('displays only the NEW label without timestamp element', () => {
|
|
29
|
+
const subject = mount(
|
|
30
|
+
<RelativeTime publishedDate={samplePublishedDate} firstPublishedDate={samplePublishedDate} />
|
|
31
|
+
)
|
|
32
|
+
expect(subject.find('.o-teaser__timestamp-prefix')).toHaveLength(1)
|
|
33
|
+
expect(subject.find('.o-teaser__timestamp-prefix').text()).toContain('new')
|
|
34
|
+
expect(subject.find('time')).toHaveLength(0)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
describe('UPDATED status', () => {
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
getStatus.mockReturnValue('updated')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('displays only the UPDATED label without timestamp element', () => {
|
|
44
|
+
const subject = mount(
|
|
45
|
+
<RelativeTime publishedDate={samplePublishedDate} firstPublishedDate={samplePublishedDate} />
|
|
46
|
+
)
|
|
47
|
+
expect(subject.find('.o-teaser__timestamp-prefix')).toHaveLength(1)
|
|
48
|
+
expect(subject.find('.o-teaser__timestamp-prefix').text()).toContain('updated')
|
|
49
|
+
expect(subject.find('time')).toHaveLength(0)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('no status (older content)', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
getStatus.mockReturnValue('')
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('displays only the timestamp without status label', () => {
|
|
59
|
+
const subject = mount(
|
|
60
|
+
<RelativeTime publishedDate={samplePublishedDate} firstPublishedDate={samplePublishedDate} />
|
|
61
|
+
)
|
|
62
|
+
expect(subject.find('.o-teaser__timestamp-prefix')).toHaveLength(0)
|
|
63
|
+
expect(subject.find('time')).toHaveLength(1)
|
|
64
|
+
expect(subject.find('.o-teaser__timestamp-date')).toHaveLength(1)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
})
|
package/dist/Teaser.cjs.js
CHANGED
|
@@ -429,12 +429,12 @@ var RelativeTime = ({
|
|
|
429
429
|
className: `o-teaser__timestamp o-teaser__timestamp--${status}`
|
|
430
430
|
}, status ? xEngine.h("span", {
|
|
431
431
|
className: "o-teaser__timestamp-prefix"
|
|
432
|
-
}, ` ${status} `, " ") :
|
|
432
|
+
}, ` ${status} `, " ") : xEngine.h("time", {
|
|
433
433
|
className: "o-teaser__timestamp-date o-date",
|
|
434
434
|
"data-o-component": "o-date",
|
|
435
435
|
"data-o-date-format": showAlways ? 'time-ago-limit-24-hours' : 'time-ago-limit-4-hours',
|
|
436
436
|
dateTime: dateformat(publishedDate, dateformat.masks.isoDateTime, true)
|
|
437
|
-
},
|
|
437
|
+
}, displayTime(relativeDate))) : null;
|
|
438
438
|
};
|
|
439
439
|
|
|
440
440
|
const LiveBlogLabels = {
|
package/dist/Teaser.es5.js
CHANGED
|
@@ -516,12 +516,12 @@ var RelativeTime = (function (_ref) {
|
|
|
516
516
|
className: "o-teaser__timestamp o-teaser__timestamp--".concat(status)
|
|
517
517
|
}, status ? xEngine.h("span", {
|
|
518
518
|
className: "o-teaser__timestamp-prefix"
|
|
519
|
-
}, " ".concat(status, " "), " ") :
|
|
519
|
+
}, " ".concat(status, " "), " ") : xEngine.h("time", {
|
|
520
520
|
className: "o-teaser__timestamp-date o-date",
|
|
521
521
|
"data-o-component": "o-date",
|
|
522
522
|
"data-o-date-format": showAlways ? 'time-ago-limit-24-hours' : 'time-ago-limit-4-hours',
|
|
523
523
|
dateTime: dateformat(publishedDate, dateformat.masks.isoDateTime, true)
|
|
524
|
-
},
|
|
524
|
+
}, displayTime(relativeDate))) : null;
|
|
525
525
|
});
|
|
526
526
|
|
|
527
527
|
var LiveBlogLabels = {
|
package/dist/Teaser.esm.js
CHANGED
|
@@ -423,12 +423,12 @@ var RelativeTime = ({
|
|
|
423
423
|
className: `o-teaser__timestamp o-teaser__timestamp--${status}`
|
|
424
424
|
}, status ? h("span", {
|
|
425
425
|
className: "o-teaser__timestamp-prefix"
|
|
426
|
-
}, ` ${status} `, " ") :
|
|
426
|
+
}, ` ${status} `, " ") : h("time", {
|
|
427
427
|
className: "o-teaser__timestamp-date o-date",
|
|
428
428
|
"data-o-component": "o-date",
|
|
429
429
|
"data-o-date-format": showAlways ? 'time-ago-limit-24-hours' : 'time-ago-limit-4-hours',
|
|
430
430
|
dateTime: dateformat(publishedDate, dateformat.masks.isoDateTime, true)
|
|
431
|
-
},
|
|
431
|
+
}, displayTime(relativeDate))) : null;
|
|
432
432
|
};
|
|
433
433
|
|
|
434
434
|
const LiveBlogLabels = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/x-teaser",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.3",
|
|
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,7 +18,7 @@
|
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@financial-times/x-engine": "^17.0.
|
|
21
|
+
"@financial-times/x-engine": "^17.0.3",
|
|
22
22
|
"date-fns": "^2.30.0",
|
|
23
23
|
"dateformat": "^3.0.3"
|
|
24
24
|
},
|
package/src/RelativeTime.jsx
CHANGED
|
@@ -21,15 +21,19 @@ export default ({ publishedDate, firstPublishedDate, showAlways = false }) => {
|
|
|
21
21
|
|
|
22
22
|
return showAlways === true || isRecent(relativeDate) ? (
|
|
23
23
|
<div className={`o-teaser__timestamp o-teaser__timestamp--${status}`}>
|
|
24
|
-
{status ?
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
{status ? (
|
|
25
|
+
<span className="o-teaser__timestamp-prefix">{` ${status} `} </span>
|
|
26
|
+
) : (
|
|
27
|
+
<time
|
|
28
|
+
className="o-teaser__timestamp-date o-date"
|
|
29
|
+
data-o-component="o-date"
|
|
30
|
+
data-o-date-format={showAlways ? 'time-ago-limit-24-hours' : 'time-ago-limit-4-hours'}
|
|
31
|
+
dateTime={dateformat(publishedDate, dateformat.masks.isoDateTime, true)}
|
|
32
|
+
>
|
|
33
|
+
{/* Let o-date handle anything < 1 hour on the client */}
|
|
34
|
+
{displayTime(relativeDate)}
|
|
35
|
+
</time>
|
|
36
|
+
)}
|
|
33
37
|
</div>
|
|
34
38
|
) : null
|
|
35
39
|
}
|