/
CalendarMonth_spec.jsx
50 lines (43 loc) · 1.83 KB
/
CalendarMonth_spec.jsx
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
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon-sandbox';
import moment from 'moment';
import CalendarMonth from '../../src/components/CalendarMonth';
describe('CalendarMonth', () => {
describe('#render', () => {
describe('data-visible attribute', () => {
it('data-visible attribute is truthy if props.isVisible', () => {
const wrapper = shallow(<CalendarMonth isVisible />).dive();
expect(wrapper.prop('data-visible')).to.equal(true);
});
it('data-visible attribute is falsy if !props.isVisible', () => {
const wrapper = shallow(<CalendarMonth isVisible={false} />).dive();
expect(wrapper.prop('data-visible')).to.equal(false);
});
});
describe('caption', () => {
it('text is the correctly formatted month title', () => {
const MONTH = moment();
const captionWrapper = shallow(<CalendarMonth month={MONTH} />).dive().find('strong');
expect(captionWrapper.text()).to.equal(MONTH.format('MMMM YYYY'));
});
});
it('renderMonthElement renders month element when month changes', () => {
const renderMonthElementStub = sinon.stub().returns(<div id="month-element" />);
const wrapper = shallow(<CalendarMonth renderMonthElement={renderMonthElementStub} />).dive();
wrapper.setProps({ month: moment().subtract(1, 'months') });
const [{
month,
onMonthSelect,
onYearSelect,
isVisible,
}] = renderMonthElementStub.getCall(0).args;
expect(moment.isMoment(month)).to.equal(true);
expect(typeof onMonthSelect).to.equal('function');
expect(typeof onYearSelect).to.equal('function');
expect(typeof isVisible).to.equal('boolean');
expect(wrapper.find('#month-element').exists()).to.equal(true);
});
});
});