You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { render, screen } from '@testing-library/react'
  2. import { ActionButton, ActionButtonState } from './index'
  3. describe('ActionButton', () => {
  4. test('renders button with default props', () => {
  5. render(<ActionButton>Click me</ActionButton>)
  6. const button = screen.getByRole('button', { name: 'Click me' })
  7. expect(button).toBeInTheDocument()
  8. expect(button.classList.contains('action-btn')).toBe(true)
  9. expect(button.classList.contains('action-btn-m')).toBe(true)
  10. })
  11. test('renders button with xs size', () => {
  12. render(<ActionButton size='xs'>Small Button</ActionButton>)
  13. const button = screen.getByRole('button', { name: 'Small Button' })
  14. expect(button.classList.contains('action-btn-xs')).toBe(true)
  15. })
  16. test('renders button with l size', () => {
  17. render(<ActionButton size='l'>Large Button</ActionButton>)
  18. const button = screen.getByRole('button', { name: 'Large Button' })
  19. expect(button.classList.contains('action-btn-l')).toBe(true)
  20. })
  21. test('renders button with xl size', () => {
  22. render(<ActionButton size='xl'>Extra Large Button</ActionButton>)
  23. const button = screen.getByRole('button', { name: 'Extra Large Button' })
  24. expect(button.classList.contains('action-btn-xl')).toBe(true)
  25. })
  26. test('applies correct state classes', () => {
  27. const { rerender } = render(
  28. <ActionButton state={ActionButtonState.Destructive}>Destructive</ActionButton>,
  29. )
  30. let button = screen.getByRole('button', { name: 'Destructive' })
  31. expect(button.classList.contains('action-btn-destructive')).toBe(true)
  32. rerender(<ActionButton state={ActionButtonState.Active}>Active</ActionButton>)
  33. button = screen.getByRole('button', { name: 'Active' })
  34. expect(button.classList.contains('action-btn-active')).toBe(true)
  35. rerender(<ActionButton state={ActionButtonState.Disabled}>Disabled</ActionButton>)
  36. button = screen.getByRole('button', { name: 'Disabled' })
  37. expect(button.classList.contains('action-btn-disabled')).toBe(true)
  38. rerender(<ActionButton state={ActionButtonState.Hover}>Hover</ActionButton>)
  39. button = screen.getByRole('button', { name: 'Hover' })
  40. expect(button.classList.contains('action-btn-hover')).toBe(true)
  41. })
  42. test('applies custom className', () => {
  43. render(<ActionButton className='custom-class'>Custom Class</ActionButton>)
  44. const button = screen.getByRole('button', { name: 'Custom Class' })
  45. expect(button.classList.contains('custom-class')).toBe(true)
  46. })
  47. test('applies custom style', () => {
  48. render(
  49. <ActionButton styleCss={{ color: 'red', backgroundColor: 'blue' }}>
  50. Custom Style
  51. </ActionButton>,
  52. )
  53. const button = screen.getByRole('button', { name: 'Custom Style' })
  54. expect(button).toHaveStyle({
  55. color: 'red',
  56. backgroundColor: 'blue',
  57. })
  58. })
  59. test('forwards additional button props', () => {
  60. render(<ActionButton disabled data-testid='test-button'>Disabled Button</ActionButton>)
  61. const button = screen.getByRole('button', { name: 'Disabled Button' })
  62. expect(button).toBeDisabled()
  63. expect(button).toHaveAttribute('data-testid', 'test-button')
  64. })
  65. })