2019-01-23 10:41:07 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2020-03-20 15:07:47 +08:00
|
|
|
import { sleep } from '../../../tests/utils';
|
2019-01-23 10:41:07 +08:00
|
|
|
|
|
|
|
describe('Collapse', () => {
|
2019-09-27 23:24:02 +08:00
|
|
|
// Fix css-animation deps on these
|
|
|
|
// https://github.com/yiminghe/css-animation/blob/a5986d73fd7dfce75665337f39b91483d63a4c8c/src/Event.js#L44
|
|
|
|
window.AnimationEvent = window.AnimationEvent || (() => {});
|
|
|
|
window.TransitionEvent = window.TransitionEvent || (() => {});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
// restore it
|
|
|
|
delete window.AnimationEvent;
|
|
|
|
delete window.TransitionEvent;
|
|
|
|
});
|
|
|
|
|
|
|
|
// eslint-disable-next-line global-require
|
|
|
|
const Collapse = require('..').default;
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2019-01-23 10:41:07 +08:00
|
|
|
it('should support remove expandIcon', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Collapse expandIcon={() => null}>
|
|
|
|
<Collapse.Panel header="header" />
|
2019-03-06 13:45:40 +08:00
|
|
|
</Collapse>,
|
2019-01-23 10:41:07 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-02-13 19:32:49 +08:00
|
|
|
|
2019-10-11 10:23:41 +08:00
|
|
|
it('should keep the className of the expandIcon', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Collapse
|
|
|
|
expandIcon={() => (
|
|
|
|
<button type="button" className="custom-expandicon-classname">
|
|
|
|
action
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Collapse.Panel header="header" />
|
|
|
|
</Collapse>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.find('.custom-expandicon-classname').exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-02-13 19:32:49 +08:00
|
|
|
it('should render extra node of panel', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Collapse>
|
|
|
|
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
|
|
|
|
<Collapse.Panel header="header" extra={<button type="button">action</button>} />
|
2019-03-06 13:45:40 +08:00
|
|
|
</Collapse>,
|
2019-02-13 19:32:49 +08:00
|
|
|
);
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-09-27 23:24:02 +08:00
|
|
|
|
2020-03-20 15:07:47 +08:00
|
|
|
it('could be expand and collapse', async () => {
|
2019-09-27 23:24:02 +08:00
|
|
|
const wrapper = mount(
|
|
|
|
<Collapse>
|
|
|
|
<Collapse.Panel header="This is panel header 1" key="1">
|
|
|
|
content
|
|
|
|
</Collapse.Panel>
|
|
|
|
</Collapse>,
|
|
|
|
);
|
|
|
|
expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(false);
|
2020-05-24 00:12:29 +08:00
|
|
|
wrapper.find('.ant-collapse-header').at(0).simulate('click');
|
|
|
|
wrapper.update();
|
2020-03-20 15:07:47 +08:00
|
|
|
await sleep(400);
|
2020-05-24 00:12:29 +08:00
|
|
|
wrapper.update();
|
2019-09-27 23:24:02 +08:00
|
|
|
expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true);
|
|
|
|
});
|
2020-03-18 20:44:18 +08:00
|
|
|
|
|
|
|
it('could override default openAnimation', () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<Collapse openAnimation={{}}>
|
|
|
|
<Collapse.Panel header="This is panel header 1" key="1">
|
|
|
|
content
|
|
|
|
</Collapse.Panel>
|
|
|
|
</Collapse>,
|
|
|
|
);
|
2020-05-24 00:12:29 +08:00
|
|
|
wrapper.find('.ant-collapse-header').at(0).simulate('click');
|
2020-03-18 20:44:18 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
2019-01-23 10:41:07 +08:00
|
|
|
});
|