mirror of
https://github.com/langgenius/dify.git
synced 2025-11-14 02:12:34 +00:00
Signed-off-by: -LAN- <laipz8200@outlook.com> Co-authored-by: twwu <twwu@dify.ai> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: jyong <718720800@qq.com> Co-authored-by: Wu Tianwei <30284043+WTW0313@users.noreply.github.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: lyzno1 <yuanyouhuilyz@gmail.com> Co-authored-by: quicksand <quicksandzn@gmail.com> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: lyzno1 <92089059+lyzno1@users.noreply.github.com> Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: nite-knite <nkCoding@gmail.com> Co-authored-by: Hanqing Zhao <sherry9277@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Harry <xh001x@hotmail.com>
77 lines
3.1 KiB
TypeScript
77 lines
3.1 KiB
TypeScript
import { render, screen } from '@testing-library/react'
|
|
import { ActionButton, ActionButtonState } from './index'
|
|
|
|
describe('ActionButton', () => {
|
|
test('renders button with default props', () => {
|
|
render(<ActionButton>Click me</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Click me' })
|
|
expect(button).toBeInTheDocument()
|
|
expect(button.classList.contains('action-btn')).toBe(true)
|
|
expect(button.classList.contains('action-btn-m')).toBe(true)
|
|
})
|
|
|
|
test('renders button with xs size', () => {
|
|
render(<ActionButton size='xs'>Small Button</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Small Button' })
|
|
expect(button.classList.contains('action-btn-xs')).toBe(true)
|
|
})
|
|
|
|
test('renders button with l size', () => {
|
|
render(<ActionButton size='l'>Large Button</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Large Button' })
|
|
expect(button.classList.contains('action-btn-l')).toBe(true)
|
|
})
|
|
|
|
test('renders button with xl size', () => {
|
|
render(<ActionButton size='xl'>Extra Large Button</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Extra Large Button' })
|
|
expect(button.classList.contains('action-btn-xl')).toBe(true)
|
|
})
|
|
|
|
test('applies correct state classes', () => {
|
|
const { rerender } = render(
|
|
<ActionButton state={ActionButtonState.Destructive}>Destructive</ActionButton>,
|
|
)
|
|
let button = screen.getByRole('button', { name: 'Destructive' })
|
|
expect(button.classList.contains('action-btn-destructive')).toBe(true)
|
|
|
|
rerender(<ActionButton state={ActionButtonState.Active}>Active</ActionButton>)
|
|
button = screen.getByRole('button', { name: 'Active' })
|
|
expect(button.classList.contains('action-btn-active')).toBe(true)
|
|
|
|
rerender(<ActionButton state={ActionButtonState.Disabled}>Disabled</ActionButton>)
|
|
button = screen.getByRole('button', { name: 'Disabled' })
|
|
expect(button.classList.contains('action-btn-disabled')).toBe(true)
|
|
|
|
rerender(<ActionButton state={ActionButtonState.Hover}>Hover</ActionButton>)
|
|
button = screen.getByRole('button', { name: 'Hover' })
|
|
expect(button.classList.contains('action-btn-hover')).toBe(true)
|
|
})
|
|
|
|
test('applies custom className', () => {
|
|
render(<ActionButton className='custom-class'>Custom Class</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Custom Class' })
|
|
expect(button.classList.contains('custom-class')).toBe(true)
|
|
})
|
|
|
|
test('applies custom style', () => {
|
|
render(
|
|
<ActionButton styleCss={{ color: 'red', backgroundColor: 'blue' }}>
|
|
Custom Style
|
|
</ActionButton>,
|
|
)
|
|
const button = screen.getByRole('button', { name: 'Custom Style' })
|
|
expect(button).toHaveStyle({
|
|
color: 'red',
|
|
backgroundColor: 'blue',
|
|
})
|
|
})
|
|
|
|
test('forwards additional button props', () => {
|
|
render(<ActionButton disabled data-testid='test-button'>Disabled Button</ActionButton>)
|
|
const button = screen.getByRole('button', { name: 'Disabled Button' })
|
|
expect(button).toBeDisabled()
|
|
expect(button).toHaveAttribute('data-testid', 'test-button')
|
|
})
|
|
})
|