-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
80 lines (67 loc) · 2.65 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import SharedTimer from './index'
import renderer from 'react-test-renderer'
const getTime = () => new Date('1983-04-26T00:00:00')
const targetTime = new Date('1983-04-26T01:02:03')
test('SharedTimer without Wrapper renders bare text', () => {
const component = renderer.create(<SharedTimer getTime={getTime} targetTime={targetTime} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer with past targetTime renders time since', () => {
const component = renderer.create(<SharedTimer getTime={getTime} targetTime={new Date('1983-04-25T00:00:00')} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer with past targetTime renders time since 5 min ago', () => {
const component = renderer.create(<SharedTimer getTime={getTime} targetTime={new Date('1983-04-25T23:55:00')} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer renders m:ss', () => {
const component = renderer.create(<SharedTimer getTime={getTime} targetTime={new Date('1983-04-26T00:03:45')} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer renders 0:ss', () => {
const component = renderer.create(<SharedTimer getTime={getTime} targetTime={new Date('1983-04-26T00:00:12')} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer defaults getTime to () => new Date()', () => {
const component = renderer.create(<SharedTimer targetTime={new Date()} />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
test('SharedTimer defaults targetTime to new Date()', () => {
const component = renderer.create(<SharedTimer />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const Timer = props => (
<SharedTimer
{...props}
Wrapper="span"
wrapperProps={{className: props.className}}
/>
)
test('Timer with span Wrapper renders text in span', () => {
const component = renderer.create(<Timer getTime={getTime} targetTime={targetTime} className="my-class" />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})
const TestComponent = ({children, className}) => (
<div className={className}>T minus {children}</div>
)
const ComponentWrappedTimer = props => (
<SharedTimer
{...props}
Wrapper={TestComponent}
wrapperProps={{className: props.className}}
/>
)
test('Timer with component Wrapper renders text in component', () => {
const component = renderer.create(<ComponentWrappedTimer getTime={getTime} targetTime={targetTime} className="my-class" />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot()
})