|
1 | 1 | /* eslint-disable react/no-render-return-value, max-classes-per-file, func-names, no-console */
|
2 |
| -import { fireEvent, render, act } from '@testing-library/react'; |
| 2 | +import { fireEvent, render, act, screen } from '@testing-library/react'; |
3 | 3 | import { Provider } from '@rc-component/motion';
|
4 | 4 | import KeyCode from '@rc-component/util/lib/KeyCode';
|
5 | 5 | import React, { cloneElement, useEffect } from 'react';
|
@@ -733,4 +733,40 @@ describe('dialog', () => {
|
733 | 733 | expect(document.querySelector('.rc-dialog')).toBeTruthy();
|
734 | 734 | expect(document.querySelector('.rc-dialog-close')).toBeFalsy();
|
735 | 735 | });
|
| 736 | + |
| 737 | + it('should render extra when extra is a React node', () => { |
| 738 | + render(<Dialog visible extra={<span data-testid="extra-node">Node</span>} />); |
| 739 | + |
| 740 | + expect(screen.getByTestId('extra-node')).toBeInTheDocument(); |
| 741 | + }); |
| 742 | + |
| 743 | + it('does not render extra when extra is empty string', () => { |
| 744 | + render(<Dialog visible extra="" />); |
| 745 | + expect(screen.queryByTestId('.rc-dialog-extra')).toBeNull(); |
| 746 | + }); |
| 747 | + |
| 748 | + it('does not render extra when extra is string with only spaces', () => { |
| 749 | + render(<Dialog visible extra=" " />); |
| 750 | + expect(screen.queryByText(' ')).toBeNull(); |
| 751 | + }); |
| 752 | + |
| 753 | + it('renders extra when extra is non-empty string', () => { |
| 754 | + render(<Dialog visible extra="hello" />); |
| 755 | + expect(screen.getByText('hello')).toBeInTheDocument(); |
| 756 | + const extraDiv = document.querySelector('.rc-dialog-extra'); |
| 757 | + expect(extraDiv).toHaveTextContent('hello'); |
| 758 | + }); |
| 759 | + |
| 760 | + it('does not render extra when extra is null or undefined', () => { |
| 761 | + const { container } = render(<Dialog visible extra={null} />); |
| 762 | + expect(container.querySelector('.rc-dialog-extra')).toBeNull(); |
| 763 | + |
| 764 | + const { container: container2 } = render(<Dialog visible />); |
| 765 | + expect(container2.querySelector('.rc-dialog-extra')).toBeNull(); |
| 766 | + }); |
| 767 | + |
| 768 | + it('renders extra when extra is a non-empty string', () => { |
| 769 | + render(<Dialog visible extra="Extra Text" />); |
| 770 | + expect(screen.getByText('Extra Text')).toBeInTheDocument(); |
| 771 | + }); |
736 | 772 | });
|
0 commit comments