|
| 1 | +import React from 'react'; |
| 2 | +import { UploadOutlined } from '@dtinsight/react-icons'; |
| 3 | +import { render, screen } from '@testing-library/react'; |
| 4 | + |
| 5 | +import Button from '../index'; |
| 6 | + |
| 7 | +describe('Button', () => { |
| 8 | + it('renders button with text correctly', () => { |
| 9 | + render(<Button>Test Button</Button>); |
| 10 | + expect(screen.getByText('Test Button')).toBeInTheDocument(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('renders button with icon correctly', () => { |
| 14 | + const { container } = render(<Button icon={<UploadOutlined />}>With Icon</Button>); |
| 15 | + expect(container.querySelector('.dtc-button__icon')).toBeInTheDocument(); |
| 16 | + expect(screen.getByText('With Icon')).toBeInTheDocument(); |
| 17 | + }); |
| 18 | + |
| 19 | + it('renders icon-only button correctly', () => { |
| 20 | + const { container } = render(<Button icon={<UploadOutlined />} />); |
| 21 | + expect(container.querySelector('.dtc-button__icon')).toBeInTheDocument(); |
| 22 | + expect(container.querySelector('.dtc-button__text')).toBeNull(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('applies custom className correctly', () => { |
| 26 | + const { container } = render(<Button className="custom-class">Custom Class</Button>); |
| 27 | + expect(container.querySelector('.dtc-button.custom-class')).toBeInTheDocument(); |
| 28 | + }); |
| 29 | + |
| 30 | + it('passes other props to antd Button', () => { |
| 31 | + render( |
| 32 | + <Button type="primary" data-testid="primary-button"> |
| 33 | + Primary |
| 34 | + </Button> |
| 35 | + ); |
| 36 | + const button = screen.getByTestId('primary-button'); |
| 37 | + expect(button).toHaveClass('ant-btn-primary'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('applies correct size to icon and text', () => { |
| 41 | + const { container } = render( |
| 42 | + <Button size="small" icon={<UploadOutlined />}> |
| 43 | + Small Button |
| 44 | + </Button> |
| 45 | + ); |
| 46 | + expect(container.querySelector('.dtc-button__icon--small')).toBeInTheDocument(); |
| 47 | + expect(container.querySelector('.dtc-button__text--small')).toBeInTheDocument(); |
| 48 | + }); |
| 49 | +}); |
0 commit comments