2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import Card from '../index';
|
|
|
|
import Button from '../../button/index';
|
2018-05-19 09:46:03 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const testMethod = typeof window !== 'undefined' ? it : xit;
|
2018-05-19 09:46:03 +00:00
|
|
|
|
|
|
|
describe('Card', () => {
|
|
|
|
beforeAll(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
jest.useFakeTimers();
|
|
|
|
});
|
2018-05-19 09:46:03 +00:00
|
|
|
|
|
|
|
afterAll(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
jest.useRealTimers();
|
|
|
|
});
|
2018-05-19 09:46:03 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function fakeResizeWindowTo(wrapper, width) {
|
2018-05-19 09:46:03 +00:00
|
|
|
Object.defineProperties(wrapper.vm.$refs.cardContainerRef, {
|
|
|
|
offsetWidth: {
|
2019-01-12 03:33:27 +00:00
|
|
|
get() {
|
|
|
|
return width;
|
|
|
|
},
|
2018-05-19 09:46:03 +00:00
|
|
|
configurable: true,
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
window.resizeTo(width);
|
2018-05-19 09:46:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testMethod('resize card will trigger different padding', () => {
|
|
|
|
const wrapper = mount(Card, {
|
|
|
|
propsData: 'xxx',
|
|
|
|
slots: {
|
|
|
|
default: 'xxx',
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
fakeResizeWindowTo(wrapper, 1000);
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.vm.$forceUpdate();
|
|
|
|
expect(wrapper.findAll('.ant-card-wider-padding').length).toBe(1);
|
|
|
|
fakeResizeWindowTo(wrapper, 800);
|
|
|
|
jest.runAllTimers();
|
|
|
|
wrapper.vm.$forceUpdate();
|
|
|
|
expect(wrapper.findAll('.ant-card-wider-padding').length).toBe(0);
|
|
|
|
});
|
2018-09-05 13:28:54 +00:00
|
|
|
it('should still have padding when card which set padding to 0 is loading', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card loading bodyStyle={{ padding: 0 }}>
|
|
|
|
xxx
|
|
|
|
</Card>
|
|
|
|
);
|
2018-09-05 13:28:54 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-11-28 13:58:42 +00:00
|
|
|
|
|
|
|
it('title should be vertically aligned', () => {
|
|
|
|
const wrapper = mount({
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Card title="Card title" extra={<Button>Button</Button>} style={{ width: '300px' }}>
|
|
|
|
<p>Card content</p>
|
|
|
|
</Card>
|
|
|
|
);
|
2018-11-28 13:58:42 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|