Skip to content

Commit

Permalink
add click to change header test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 27, 2019
1 parent 2112634 commit f2a0b6f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,32 @@ describe('Panel', () => {
jest.useRealTimers();
});
});

describe('click to switch', () => {
it('date', () => {
const wrapper = mount(
<MomentPickerPanel defaultValue={getMoment('1990-09-03')} />,
);

wrapper.clickButton('prev');
expect(wrapper.find('.rc-picker-date-panel-header-view').text()).toEqual(
'Aug1990',
);

wrapper.clickButton('next');
expect(wrapper.find('.rc-picker-date-panel-header-view').text()).toEqual(
'Sep1990',
);

wrapper.clickButton('super-prev');
expect(wrapper.find('.rc-picker-date-panel-header-view').text()).toEqual(
'Sep1989',
);

wrapper.clickButton('super-next');
expect(wrapper.find('.rc-picker-date-panel-header-view').text()).toEqual(
'Sep1990',
);
});
});
});
12 changes: 12 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ Object.assign(Enzyme.ReactWrapper.prototype, {

return matchCell;
},
clickButton(type) {
let matchBtn;
this.find('button').forEach(btn => {
if (btn.props().className.includes(`-header-${type}-btn`)) {
matchBtn = btn;
}
});

matchBtn.simulate('click');

return matchBtn;
},
clearValue(index = 0) {
this.find('Picker')
.at(index)
Expand Down
1 change: 1 addition & 0 deletions tests/util/commonUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type Wrapper = ReactWrapper & {
selectCell: (text: number | string, index?: number) => Wrapper;
clearValue: (index?: number) => void;
keyDown: (which: number, info?: object) => void;
clickButton: (type: 'prev' | 'next' | 'super-prev' | 'super-next') => Wrapper;
};

export const mount = originMount as (
Expand Down

1 comment on commit f2a0b6f

@vercel
Copy link

@vercel vercel bot commented on f2a0b6f Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.