ant-design/components/collapse/__tests__/index.test.js
偏右 83ddfb807e
test: Enable transition and animation in jest (#26571)
* test:  add test cases to increase coverage

* test: fix snapshot

* fix: test node envioronment

* fix: test node envioronment

* fix test case

* test: refactor menu test cases

* test: update test code style

* test: add more menu test cases

* add comment

* test: update snapshot

* fix: alert test case

* fix: form onLeaveEnd test cov

* test: fix button click wave test cases

* chore: clean up snapshots
2020-09-18 16:53:18 +08:00

72 lines
2.1 KiB
JavaScript

import React from 'react';
import { mount } from 'enzyme';
import { sleep } from '../../../tests/utils';
describe('Collapse', () => {
// eslint-disable-next-line global-require
const Collapse = require('..').default;
it('should support remove expandIcon', () => {
const wrapper = mount(
<Collapse expandIcon={() => null}>
<Collapse.Panel header="header" />
</Collapse>,
);
expect(wrapper.render()).toMatchSnapshot();
});
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);
});
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>} />
</Collapse>,
);
expect(wrapper.render()).toMatchSnapshot();
});
it('could be expand and collapse', async () => {
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);
wrapper.find('.ant-collapse-header').at(0).simulate('click');
wrapper.update();
await sleep(400);
wrapper.update();
expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true);
});
it('could override default openAnimation', () => {
const wrapper = mount(
<Collapse openAnimation={{}}>
<Collapse.Panel header="This is panel header 1" key="1">
content
</Collapse.Panel>
</Collapse>,
);
wrapper.find('.ant-collapse-header').at(0).simulate('click');
expect(wrapper.render()).toMatchSnapshot();
});
});