ant-design/components/result/__tests__/index.test.js
二货机器人 a67c0d28d3
fix: react 18 test fixing (#34787)
* fix: try fix

* chore: ci

* test: recover

* test: more test case

* test: more and mote

* test: btn test

* fix: react 18 compitable

* chore: more test

* test: all confirm test

* chore: tmp

* chore: test lib

* chore: tmp

* chore: tmp

* test: back of part

* test: back of menu index test

* test: more test

* test: form test

* test: rm IE11 test case

* chore: fix compatible

* chore: clean up

* chore: back of all test case

* test: ignore 18 lines

* chore: remove render test of enzyme in upload

* test: back of IE11 test case to fit 100% coverage

* chore: fix pkg deps
2022-04-06 11:07:15 +08:00

77 lines
2.5 KiB
JavaScript

import React from 'react';
import { mount } from 'enzyme';
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
import Result from '..';
import Button from '../../button';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
describe('Result', () => {
mountTest(Result);
rtlTest(Result);
it('🙂 successPercent should decide the progress status when it exists', () => {
const wrapper = mount(
<Result
status="success"
title="Successfully Purchased Cloud Server ECS!"
subTitle="Order number: 2017182818828182881 Cloud server configuration takes 1-5 minutes, please wait."
extra={[
<Button type="primary" key="console">
Go Console
</Button>,
<Button key="buy">Buy Again</Button>,
]}
/>,
);
expect(wrapper.find('.anticon-check-circle')).toHaveLength(1);
});
it('🙂 different status, different class', () => {
const wrapper = mount(<Result status="warning" />);
expect(wrapper.find('.ant-result-warning')).toHaveLength(1);
wrapper.setProps({
status: 'error',
});
expect(wrapper.find('.ant-result-error')).toHaveLength(1);
wrapper.setProps({
status: '500',
});
expect(wrapper.find('.ant-result-500')).toHaveLength(1);
});
it('🙂 When status = 404, the icon is an image', () => {
const wrapper = mount(<Result status="404" />);
expect(wrapper.find('.ant-result-404 .ant-result-image')).toHaveLength(1);
});
it('🙂 When extra is undefined, the extra dom is undefined', () => {
const wrapper = mount(<Result status="404" />);
expect(wrapper.find('.ant-result-extra')).toHaveLength(0);
});
it('🙂 result should support className', () => {
const wrapper = mount(<Result status="404" title="404" className="my-result" />);
expect(wrapper.find('.ant-result.my-result')).toHaveLength(1);
});
it('should warning when pass a string as icon props', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<Result title="404" icon="ab" />);
expect(warnSpy).not.toHaveBeenCalled();
render(<Result title="404" icon="smile" />);
expect(warnSpy).toHaveBeenCalledWith(
`Warning: [antd: Result] \`icon\` is using ReactNode instead of string naming in v4. Please check \`smile\` at https://ant.design/components/icon`,
);
warnSpy.mockRestore();
});
});