2019-01-12 11:33:27 +08:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Card from '../index';
|
|
|
|
import Button from '../../button/index';
|
2020-03-07 19:45:13 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2018-05-19 17:46:03 +08:00
|
|
|
|
|
|
|
describe('Card', () => {
|
2020-03-07 19:45:13 +08:00
|
|
|
mountTest(Card);
|
2018-05-19 17:46:03 +08:00
|
|
|
beforeAll(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
2018-05-19 17:46:03 +08:00
|
|
|
|
|
|
|
afterAll(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2018-09-05 21:28:54 +08:00
|
|
|
it('should still have padding when card which set padding to 0 is loading', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card loading bodyStyle={{ padding: 0 }}>
|
|
|
|
xxx
|
|
|
|
</Card>
|
|
|
|
);
|
2018-09-05 21:28:54 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-11-28 21:58:42 +08:00
|
|
|
|
|
|
|
it('title should be vertically aligned', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card title="Card title" extra={<Button>Button</Button>} style={{ width: '300px' }}>
|
|
|
|
<p>Card content</p>
|
|
|
|
</Card>
|
|
|
|
);
|
2018-11-28 21:58:42 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2020-03-07 19:45:13 +08:00
|
|
|
|
|
|
|
it('onTabChange should work', () => {
|
|
|
|
const tabList = [
|
|
|
|
{
|
|
|
|
key: 'tab1',
|
|
|
|
tab: 'tab1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'tab2',
|
|
|
|
tab: 'tab2',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
const onTabChange = jest.fn();
|
|
|
|
const wrapper = mount(
|
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card onTabChange={onTabChange} tabList={tabList}>
|
|
|
|
xxx
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sync: false,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
wrapper
|
|
|
|
.findAll('.ant-tabs-tab')
|
|
|
|
.at(1)
|
|
|
|
.trigger('click');
|
|
|
|
expect(onTabChange).toHaveBeenCalledWith('tab2');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not render when actions is number', () => {
|
|
|
|
const wrapper = mount({
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card title="Card title" actions={11}>
|
|
|
|
<p>Card content</p>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-card-actions').length).toBe(0);
|
|
|
|
});
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|