|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { render } from '@testing-library/react'; |
| 3 | +import { Backdrop } from './Backdrop'; |
| 4 | + |
| 5 | +describe('Backdrop', () => { |
| 6 | + it('renders as a <div> element', () => { |
| 7 | + const { container } = render(<Backdrop />); |
| 8 | + expect(container.firstChild?.nodeName).toBe('DIV'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('always has base dsn-backdrop class', () => { |
| 12 | + const { container } = render(<Backdrop />); |
| 13 | + expect(container.firstChild).toHaveClass('dsn-backdrop'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('always has aria-hidden="true"', () => { |
| 17 | + const { container } = render(<Backdrop />); |
| 18 | + expect(container.firstChild).toHaveAttribute('aria-hidden', 'true'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('does not apply no-blur class when blur is true (default)', () => { |
| 22 | + const { container } = render(<Backdrop />); |
| 23 | + expect(container.firstChild).not.toHaveClass('dsn-backdrop--no-blur'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('applies no-blur class when blur is false', () => { |
| 27 | + const { container } = render(<Backdrop blur={false} />); |
| 28 | + expect(container.firstChild).toHaveClass('dsn-backdrop--no-blur'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('applies custom className', () => { |
| 32 | + const { container } = render(<Backdrop className="custom" />); |
| 33 | + expect(container.firstChild).toHaveClass('dsn-backdrop'); |
| 34 | + expect(container.firstChild).toHaveClass('custom'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('forwards ref', () => { |
| 38 | + const ref = { current: null as HTMLDivElement | null }; |
| 39 | + render(<Backdrop ref={ref} />); |
| 40 | + expect(ref.current).toBeInstanceOf(HTMLDivElement); |
| 41 | + }); |
| 42 | + |
| 43 | + it('spreads additional HTML attributes', () => { |
| 44 | + const { container } = render(<Backdrop data-testid="backdrop" />); |
| 45 | + expect(container.firstChild).toHaveAttribute('data-testid', 'backdrop'); |
| 46 | + }); |
| 47 | +}); |
0 commit comments