Skip to content

Commit 4a747e6

Browse files
committed
Add tests for DateTimePickerHours
1 parent 261b1e2 commit 4a747e6

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React from "react/addons";
2+
import Constants from "../Constants.js";
3+
jest.dontMock("../DateTimePickerHours.js");
4+
const { TestUtils } = React.addons;
5+
6+
describe("DateTimePickerHours", function() {
7+
const DateTimePickerHours = require("../DateTimePickerHours.js");
8+
let hours, onSwitchMock, setSelectedHourMock;
9+
10+
11+
describe("Controls", function() {
12+
13+
beforeEach(() => {
14+
setSelectedHourMock = jest.genMockFunction();
15+
onSwitchMock = jest.genMockFunction();
16+
hours = TestUtils.renderIntoDocument(
17+
<DateTimePickerHours
18+
mode={Constants.MODE_TIME}
19+
onSwitch={onSwitchMock}
20+
setSelectedHour={setSelectedHourMock}
21+
/>
22+
);
23+
});
24+
25+
it("calls setSelectedHour when clicking a hour", function() {
26+
const hour = TestUtils.scryRenderedDOMComponentsWithClass(hours, "hour")[0];
27+
TestUtils.Simulate.click(hour);
28+
expect(setSelectedHourMock.mock.calls.length).toBe(1);
29+
});
30+
31+
it("calls onSwitch when clicking the switch", function() {
32+
const switchIcon = TestUtils.findRenderedDOMComponentWithClass(hours, "picker-switch");
33+
TestUtils.Simulate.click(switchIcon);
34+
expect(onSwitchMock.mock.calls.length).toBe(1);
35+
});
36+
});
37+
38+
describe("UI", function() {
39+
beforeEach(() => {
40+
setSelectedHourMock = jest.genMockFunction();
41+
onSwitchMock = jest.genMockFunction();
42+
});
43+
44+
it("renders the switch if mode is time", function() {
45+
hours = TestUtils.renderIntoDocument(
46+
<DateTimePickerHours
47+
mode={Constants.MODE_TIME}
48+
onSwitch={onSwitchMock}
49+
setSelectedHour={setSelectedHourMock}
50+
/>
51+
);
52+
const switchList = TestUtils.scryRenderedDOMComponentsWithClass(hours, "list-unstyled");
53+
expect(switchList.length).toBe(1);
54+
});
55+
56+
it("does not render the switch if mode is date", function() {
57+
hours = TestUtils.renderIntoDocument(
58+
<DateTimePickerHours
59+
mode={Constants.MODE_DATE}
60+
onSwitch={onSwitchMock}
61+
setSelectedHour={setSelectedHourMock}
62+
/>
63+
);
64+
const switchList = TestUtils.scryRenderedDOMComponentsWithClass(hours, "list-unstyled");
65+
expect(switchList.length).toBe(0);
66+
});
67+
68+
it("renders 24 Hours", function() {
69+
hours = TestUtils.renderIntoDocument(
70+
<DateTimePickerHours
71+
mode={Constants.MODE_DATE}
72+
onSwitch={onSwitchMock}
73+
setSelectedHour={setSelectedHourMock}
74+
/>
75+
);
76+
const hourList = TestUtils.scryRenderedDOMComponentsWithClass(hours, "hour");
77+
expect(hourList.length).toBe(24);
78+
});
79+
80+
it("renders 01 to 24", function() {
81+
hours = TestUtils.renderIntoDocument(
82+
<DateTimePickerHours
83+
mode={Constants.MODE_DATE}
84+
onSwitch={onSwitchMock}
85+
setSelectedHour={setSelectedHourMock}
86+
/>
87+
);
88+
const hourList = TestUtils.scryRenderedDOMComponentsWithClass(hours, "hour");
89+
expect(hourList.map((x) => x.props.children)).toEqual(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"]);
90+
});
91+
92+
});
93+
94+
});

0 commit comments

Comments
 (0)