2017-01-27 14:27:18 +08:00
|
|
|
import React from 'react';
|
2018-12-05 19:12:18 +08:00
|
|
|
import { render, mount } from 'enzyme';
|
2022-03-25 14:26:09 +08:00
|
|
|
// eslint-disable-next-line import/no-named-as-default
|
|
|
|
import Spin, { Spin as SpinClass } from '..';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2017-01-27 14:27:18 +08:00
|
|
|
|
|
|
|
describe('Spin', () => {
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Spin);
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Spin);
|
2019-08-26 22:53:20 +08:00
|
|
|
|
2017-01-27 14:27:18 +08:00
|
|
|
it('should only affect the spin element when set style to a nested <Spin>xx</Spin>', () => {
|
2018-12-05 19:12:18 +08:00
|
|
|
const wrapper = mount(
|
2017-01-27 14:27:18 +08:00
|
|
|
<Spin style={{ background: 'red' }}>
|
|
|
|
<div>content</div>
|
2018-12-07 20:02:01 +08:00
|
|
|
</Spin>,
|
2017-01-27 14:27:18 +08:00
|
|
|
);
|
2020-10-21 10:35:06 +08:00
|
|
|
expect(wrapper.find('.ant-spin-nested-loading').at(0).prop('style')).toBeFalsy();
|
|
|
|
expect(wrapper.find('.ant-spin').at(0).prop('style').background).toBe('red');
|
2017-01-27 14:27:18 +08:00
|
|
|
});
|
2017-11-04 12:05:25 +08:00
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
it("should render custom indicator when it's set", () => {
|
2017-11-04 12:05:25 +08:00
|
|
|
const customIndicator = <div className="custom-indicator" />;
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = render(<Spin indicator={customIndicator} />);
|
2018-02-14 12:30:31 +08:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2017-11-04 12:05:25 +08:00
|
|
|
});
|
2018-06-08 23:13:47 +08:00
|
|
|
|
2018-08-10 17:04:40 +08:00
|
|
|
it('should be controlled by spinning', () => {
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<Spin spinning={false} />);
|
2022-03-25 14:26:09 +08:00
|
|
|
expect(wrapper.find(SpinClass).instance().state.spinning).toBe(false);
|
2018-08-10 17:04:40 +08:00
|
|
|
wrapper.setProps({ spinning: true });
|
2022-03-25 14:26:09 +08:00
|
|
|
expect(wrapper.find(SpinClass).instance().state.spinning).toBe(true);
|
2018-08-10 17:04:40 +08:00
|
|
|
});
|
2019-11-27 09:40:47 +08:00
|
|
|
|
|
|
|
it('if indicator set null should not be render default indicator', () => {
|
|
|
|
const wrapper = mount(<Spin indicator={null} />);
|
2022-03-24 22:12:41 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2019-11-27 09:40:47 +08:00
|
|
|
});
|
2020-02-14 19:02:53 +08:00
|
|
|
|
|
|
|
it('should support static method Spin.setDefaultIndicator', () => {
|
|
|
|
Spin.setDefaultIndicator(<em className="custom-spinner" />);
|
|
|
|
const wrapper = mount(<Spin />);
|
2022-03-24 22:12:41 +08:00
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
2020-02-14 19:02:53 +08:00
|
|
|
Spin.setDefaultIndicator(null);
|
2020-02-19 13:20:43 +08:00
|
|
|
});
|
2020-11-18 11:59:29 +08:00
|
|
|
|
|
|
|
it('should render 0', () => {
|
2020-12-09 17:12:32 +08:00
|
|
|
const wrapper = mount(<Spin>{0}</Spin>);
|
2020-11-18 11:59:29 +08:00
|
|
|
expect(wrapper.find('.ant-spin-container').at(0).text()).toBe('0');
|
|
|
|
});
|
2017-01-27 14:27:18 +08:00
|
|
|
});
|