ant-design/components/date-picker/__tests__/WeekPicker.test.js

75 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-03-29 18:03:14 +08:00
import React from 'react';
import { mount, render } from 'enzyme';
2018-12-28 10:50:17 +08:00
import { setMockDate, resetMockDate } from '../../../tests/utils';
import DatePicker from '..';
import focusTest from '../../../tests/shared/focusTest';
import { openPanel } from './utils';
const { WeekPicker } = DatePicker;
describe('WeekPicker', () => {
2018-12-28 10:50:17 +08:00
beforeEach(() => {
setMockDate();
});
afterEach(() => {
resetMockDate();
});
focusTest(WeekPicker);
2018-03-29 18:03:14 +08:00
it('should support style prop', () => {
2018-12-07 20:02:01 +08:00
const wrapper = mount(<WeekPicker style={{ width: 400 }} />);
2018-03-29 18:03:14 +08:00
expect(wrapper.render()).toMatchSnapshot();
});
it('extra footer works', () => {
const wrapper = mount(
<WeekPicker renderExtraFooter={mode => <span className="extra-node">{mode}</span>} />,
);
openPanel(wrapper);
let extraNode = wrapper.find('.extra-node');
expect(extraNode.length).toBe(1);
expect(extraNode.text()).toBe('date');
wrapper
.find('.ant-calendar-month-select')
.hostNodes()
.simulate('click');
extraNode = wrapper.find('.ant-calendar-month-panel .extra-node');
expect(extraNode.length).toBe(1);
expect(extraNode.text()).toBe('month');
wrapper
.find('.ant-calendar-year-select')
.hostNodes()
.simulate('click');
extraNode = wrapper.find('.ant-calendar-year-panel .extra-node');
expect(extraNode.length).toBe(1);
expect(extraNode.text()).toBe('year');
wrapper
.find('.ant-calendar-year-panel-decade-select')
.hostNodes()
.simulate('click');
extraNode = wrapper.find('.ant-calendar-decade-panel .extra-node');
expect(extraNode.length).toBe(1);
expect(extraNode.text()).toBe('decade');
});
it('should support dateRender', () => {
const wrapper = mount(
<WeekPicker open dateRender={current => <span>{current.format('YYYY-MM-DD')}</span>} />,
);
expect(
render(
wrapper
.find('Trigger')
.instance()
.getComponent(),
),
).toMatchSnapshot();
});
});