mirror of
https://github.com/langgenius/dify.git
synced 2026-02-24 18:05:11 +00:00
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { fireEvent, render } from '@testing-library/react'
|
|
import AddButton from './add-button'
|
|
|
|
describe('AddButton', () => {
|
|
describe('Rendering', () => {
|
|
it('should render without crashing', () => {
|
|
const { container } = render(<AddButton onClick={vi.fn()} />)
|
|
expect(container.firstChild).toBeInTheDocument()
|
|
})
|
|
|
|
it('should render an add icon', () => {
|
|
const { container } = render(<AddButton onClick={vi.fn()} />)
|
|
const svg = container.querySelector('span')
|
|
expect(svg).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
describe('Props', () => {
|
|
it('should apply custom className', () => {
|
|
const { container } = render(<AddButton onClick={vi.fn()} className="my-custom" />)
|
|
expect(container.firstChild).toHaveClass('my-custom')
|
|
})
|
|
|
|
it('should retain base classes when custom className is applied', () => {
|
|
const { container } = render(<AddButton onClick={vi.fn()} className="my-custom" />)
|
|
expect(container.firstChild).toHaveClass('cursor-pointer')
|
|
expect(container.firstChild).toHaveClass('rounded-md')
|
|
expect(container.firstChild).toHaveClass('select-none')
|
|
})
|
|
})
|
|
|
|
describe('User Interactions', () => {
|
|
it('should call onClick when clicked', () => {
|
|
const onClick = vi.fn()
|
|
const { container } = render(<AddButton onClick={onClick} />)
|
|
fireEvent.click(container.firstChild!)
|
|
expect(onClick).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('should call onClick multiple times on repeated clicks', () => {
|
|
const onClick = vi.fn()
|
|
const { container } = render(<AddButton onClick={onClick} />)
|
|
fireEvent.click(container.firstChild!)
|
|
fireEvent.click(container.firstChild!)
|
|
fireEvent.click(container.firstChild!)
|
|
expect(onClick).toHaveBeenCalledTimes(3)
|
|
})
|
|
})
|
|
})
|