2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2022-04-20 12:13:11 +08:00
|
|
|
// eslint-disable-next-line import/no-named-as-default
|
|
|
|
import { render } from '@testing-library/react';
|
2017-01-27 14:27:18 +08:00
|
|
|
import Spin 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>', () => {
|
2022-07-01 11:53:49 +08:00
|
|
|
const { container } = render(
|
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
|
|
|
);
|
2022-07-01 11:53:49 +08:00
|
|
|
expect((container.querySelector('.ant-spin-nested-loading')! as HTMLElement).style.length).toBe(
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
expect((container.querySelector('.ant-spin')! as HTMLElement).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" />;
|
2022-07-01 11:53:49 +08:00
|
|
|
const { asFragment } = render(<Spin indicator={customIndicator} />);
|
|
|
|
expect(asFragment().firstChild).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', () => {
|
2022-04-18 21:02:11 +08:00
|
|
|
const { container, rerender } = render(<Spin spinning={false} />);
|
2022-04-20 12:13:11 +08:00
|
|
|
expect(container.querySelector('.ant-spin-spinning')).toBeFalsy();
|
2022-04-18 21:02:11 +08:00
|
|
|
rerender(<Spin spinning />);
|
2022-04-20 12:13:11 +08:00
|
|
|
expect(container.querySelector('.ant-spin-spinning')).toBeTruthy();
|
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', () => {
|
2022-07-01 11:53:49 +08:00
|
|
|
const { asFragment } = render(<Spin indicator={null as any} />);
|
|
|
|
expect(asFragment().firstChild).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" />);
|
2022-07-01 11:53:49 +08:00
|
|
|
const { asFragment } = render(<Spin />);
|
|
|
|
expect(asFragment().firstChild).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', () => {
|
2022-07-01 11:53:49 +08:00
|
|
|
const { container } = render(<Spin>{0}</Spin>);
|
|
|
|
expect(container.querySelector('.ant-spin-container')?.textContent).toBe('0');
|
2020-11-18 11:59:29 +08:00
|
|
|
});
|
2017-01-27 14:27:18 +08:00
|
|
|
});
|