Skip to content

Commit 0b11e70

Browse files
committed
add test coverage
1 parent e6801bc commit 0b11e70

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { render, screen, fireEvent } from '@testing-library/react';
2+
import { describe, it, expect, vi } from 'vitest';
3+
import { MobileTray } from './MobileTray';
4+
5+
describe('MobileTray', () => {
6+
const defaultProps = {
7+
isOpen: true,
8+
onOverlayClick: vi.fn(),
9+
onEscKeyPress: vi.fn(),
10+
onAnimationEnd: vi.fn(),
11+
children: <div>Test Content</div>,
12+
};
13+
14+
it('renders children when open', () => {
15+
render(<MobileTray {...defaultProps} />);
16+
expect(screen.getByText('Test Content')).toBeInTheDocument();
17+
});
18+
19+
it('renders overlay when open', () => {
20+
render(<MobileTray {...defaultProps} />);
21+
expect(screen.getByRole('presentation')).toHaveClass('bg-black bg-opacity-20');
22+
});
23+
24+
it('does not render overlay when closed', () => {
25+
render(<MobileTray {...defaultProps} isOpen={false} />);
26+
expect(screen.queryByRole('presentation')).not.toBeInTheDocument();
27+
});
28+
29+
it('calls onOverlayClick when overlay is clicked', () => {
30+
render(<MobileTray {...defaultProps} />);
31+
fireEvent.click(screen.getByRole('presentation'));
32+
expect(defaultProps.onOverlayClick).toHaveBeenCalled();
33+
});
34+
35+
it('calls onEscKeyPress when Escape key is pressed on overlay', () => {
36+
render(<MobileTray {...defaultProps} />);
37+
fireEvent.keyDown(screen.getByRole('presentation'), { key: 'Escape' });
38+
expect(defaultProps.onEscKeyPress).toHaveBeenCalled();
39+
});
40+
41+
it('calls onAnimationEnd when animation completes', () => {
42+
render(<MobileTray {...defaultProps} />);
43+
fireEvent.animationEnd(screen.getByTestId('ockMobileTray'));
44+
expect(defaultProps.onAnimationEnd).toHaveBeenCalled();
45+
});
46+
47+
it('applies custom animation class when provided', () => {
48+
render(<MobileTray {...defaultProps} animation="custom-animation" />);
49+
expect(screen.getByTestId('ockMobileTray')).toHaveClass('custom-animation');
50+
});
51+
52+
it('applies default translation classes when no animation prop is provided', () => {
53+
const { rerender } = render(<MobileTray {...defaultProps} />);
54+
expect(screen.getByTestId('ockMobileTray')).toHaveClass('translate-y-0');
55+
56+
rerender(<MobileTray {...defaultProps} isOpen={false} />);
57+
expect(screen.getByTestId('ockMobileTray')).toHaveClass('translate-y-full');
58+
});
59+
60+
it('applies custom className when provided', () => {
61+
render(<MobileTray {...defaultProps} className="custom-class" />);
62+
expect(screen.getByTestId('ockMobileTray')).toHaveClass('custom-class');
63+
});
64+
});

src/internal/components/MobileTray.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export function MobileTray({
3131
)}
3232
onClick={onOverlayClick}
3333
onKeyDown={onEscKeyPress}
34-
role="button"
35-
tabIndex={0}
34+
role="presentation"
3635
/>
3736
)}
3837
<div

0 commit comments

Comments
 (0)