Skip to content

Commit 7dcd83a

Browse files
committed
adding tests
1 parent e4d25b2 commit 7dcd83a

File tree

7 files changed

+212
-5
lines changed

7 files changed

+212
-5
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
"path-exists": "2.1.0",
3939
"postcss-loader": "1.0.0",
4040
"promise": "7.1.1",
41+
"react-addons-test-utils": "^15.4.2",
4142
"react-dev-utils": "^0.4.2",
43+
"react-test-renderer": "^15.4.2",
4244
"recursive-readdir": "2.1.0",
4345
"strip-ansi": "3.0.1",
4446
"style-loader": "0.13.1",

scripts/start.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ function addMiddleware(devServer) {
204204
proxyReq.setHeader('authorization', token);
205205
console.log(`requested: [${req.method}] ${req.url}`);
206206
console.log('query:', req.query);
207-
console.log('-\n');
207+
console.log('-');
208208
},
209209
onProxyRes: (proxyRes, req, res) => {
210210
proxyRes.on('data', (chunk) => {
211211
console.log(`response for: [${req.method}] ${req.url}`);
212212
console.log((new StringDecoder('utf8')).write(chunk));
213-
console.log('-\n');
213+
console.log('-');
214214
});
215215
},
216216
// pathRewrite: {

src/__tests__sample/Bookie.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
jest.dontMock('../Bookie.jsx');
2+
3+
describe('Bookie', function () {
4+
var React = require('react');
5+
var ReactDOM = require('react-dom');
6+
var TestUtils = require('react-addons-test-utils');
7+
8+
var Bookie;
9+
10+
beforeEach(function () {
11+
Bookie = require('../Bookie').default;
12+
});
13+
14+
it('should exists', function () {
15+
// Render into document
16+
var bookie = TestUtils.renderIntoDocument(<Bookie />);
17+
expect(TestUtils.isCompositeComponent(bookie)).toBeTruthy();
18+
});
19+
});

src/components/Bookie.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Bookie extends Component {
7575
pickerUpdater.adjust();
7676
if (setLoading)
7777
this.setParentLoading(pickerUpdater.state().loading);
78-
console.log('applying diff', diff, pickerUpdater.diff());
78+
// console.log('applying diff', diff, pickerUpdater.diff());
7979
this.setState(pickerUpdater.diff(), () => { this.pullMissingData(); });
8080
}
8181
}

src/components/Bookie.test.jsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const React = require('react');
2+
const TestUtils = require('react-addons-test-utils');
3+
const Bookie = require('./Bookie').default;
4+
const renderer = require('react-test-renderer');
5+
6+
const Scheduler = require('../lib/Scheduler').default;
7+
const moment = require('moment');
8+
9+
Scheduler.getCurrentMoment = (() => moment('2017-01-01 22:00'));
10+
11+
12+
// setState is async, so you probably need
13+
14+
// showsHeader.setState({
15+
// showVideo: true
16+
// });
17+
// jest.runAllTicks();
18+
// find ...
19+
// expect ...
20+
21+
it('should exists', function () {
22+
const bookie = TestUtils.renderIntoDocument(<Bookie />);
23+
expect(TestUtils.isCompositeComponent(bookie)).toBeTruthy();
24+
});
25+
26+
it('compare DOM snapshot', () => {
27+
const tree = renderer.create(<Bookie />).toJSON();
28+
expect(tree).toMatchSnapshot();
29+
});
30+
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
exports[`test compare DOM snapshot 1`] = `
2+
<div
3+
className="bookie-container">
4+
<ul
5+
className="pick-day">
6+
<li
7+
className="disabled"
8+
onClick={undefined}>
9+
<a>
10+
<<
11+
</a>
12+
</li>
13+
<li
14+
className="current"
15+
onClick={[Function]}>
16+
<a>
17+
01/01/2017
18+
</a>
19+
</li>
20+
<li
21+
className=""
22+
onClick={[Function]}>
23+
<a>
24+
01/02/2017
25+
</a>
26+
</li>
27+
<li
28+
className=""
29+
onClick={[Function]}>
30+
<a>
31+
01/03/2017
32+
</a>
33+
</li>
34+
<li
35+
className=""
36+
onClick={[Function]}>
37+
<a>
38+
01/04/2017
39+
</a>
40+
</li>
41+
<li
42+
className=""
43+
onClick={[Function]}>
44+
<a>
45+
>>
46+
</a>
47+
</li>
48+
</ul>
49+
<ul
50+
className="pick-minutes">
51+
<li
52+
className="disabled"
53+
onClick={undefined}>
54+
<a>
55+
00
56+
</a>
57+
</li>
58+
<li
59+
className="disabled"
60+
onClick={undefined}>
61+
<a>
62+
15
63+
</a>
64+
</li>
65+
<li
66+
className="disabled"
67+
onClick={undefined}>
68+
<a>
69+
30
70+
</a>
71+
</li>
72+
<li
73+
className="disabled"
74+
onClick={undefined}>
75+
<a>
76+
45
77+
</a>
78+
</li>
79+
</ul>
80+
<ul
81+
className="pick-hour">
82+
<li
83+
className="disabled"
84+
onClick={undefined}>
85+
<a>
86+
<<
87+
</a>
88+
</li>
89+
<li
90+
className="disabled"
91+
onClick={undefined}>
92+
<a>
93+
10pm
94+
</a>
95+
</li>
96+
<li
97+
className="disabled"
98+
onClick={undefined}>
99+
<a>
100+
11pm
101+
</a>
102+
</li>
103+
<li
104+
className="disabled"
105+
onClick={undefined}>
106+
<a>
107+
12am
108+
</a>
109+
</li>
110+
<li
111+
className="disabled"
112+
onClick={undefined}>
113+
<a>
114+
1am
115+
</a>
116+
</li>
117+
<li
118+
className=""
119+
onClick={[Function]}>
120+
<a>
121+
>>
122+
</a>
123+
</li>
124+
</ul>
125+
<div
126+
className="range">
127+
<span
128+
className="pick start picking"
129+
onClick={[Function]}>
130+
choose start
131+
</span>
132+
<span>
133+
 — 
134+
</span>
135+
<span
136+
className="pick end"
137+
onClick={[Function]}>
138+
choose end
139+
</span>
140+
</div>
141+
<div
142+
className="text-center">
143+
<button
144+
className="btn btn-default"
145+
disabled={true}
146+
onClick={[Function]}
147+
type="button">
148+
Book
149+
</button>
150+
</div>
151+
</div>
152+
`;

src/lib/Scheduler.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ moment.updateLocale(moment.locale(), {
2121
});
2222

2323
class Scheduler {
24+
static getCurrentMoment() {
25+
return moment();
26+
}
27+
2428
static getDaysFrame(frameStartDate) {
2529
const mbase = moment.utc(frameStartDate);
2630
const result = [];
@@ -80,7 +84,7 @@ class Scheduler {
8084
}
8185

8286
static getNowStr() {
83-
return moment().startOf('minute').format();
87+
return Scheduler.getCurrentMoment().startOf('minute').format();
8488
}
8589

8690
static getNextDayString(date) {
@@ -102,7 +106,7 @@ class Scheduler {
102106
let result = '';
103107
if (dateStr) {
104108
const mVal = moment(dateStr);
105-
const mToday = moment();
109+
const mToday = Scheduler.getCurrentMoment();
106110
if (formatDayToString(mToday) === formatDayToString(mVal))
107111
result = mVal.format('ha:mm');
108112
else if (mToday.year() === mVal.year())

0 commit comments

Comments
 (0)