forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorState.test.tsx
More file actions
56 lines (48 loc) · 1.47 KB
/
Copy pathErrorState.test.tsx
File metadata and controls
56 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { render, screen, fireEvent } from '@testing-library/react';
import { ErrorState } from '../ErrorState';
describe('ErrorState', () => {
it('renders network error correctly', () => {
const onRetry = jest.fn();
render(
<ErrorState
type="network"
onRetry={onRetry}
/>
);
expect(screen.getByText('Connection Error')).toBeInTheDocument();
expect(screen.getByText(/Unable to connect to the server/i)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /Try Again/i })).toBeInTheDocument();
});
it('renders server error with status code', () => {
render(
<ErrorState
type="server"
statusCode={500}
onRetry={() => {}}
/>
);
expect(screen.getByText('Server Error')).toBeInTheDocument();
expect(screen.getByText(/Server error 500/i)).toBeInTheDocument();
});
it('calls onRetry when retry button is clicked', () => {
const onRetry = jest.fn();
render(
<ErrorState
type="network"
onRetry={onRetry}
/>
);
fireEvent.click(screen.getByRole('button', { name: /Try Again/i }));
expect(onRetry).toHaveBeenCalledTimes(1);
});
it('does not show retry button when showRetry is false', () => {
render(
<ErrorState
type="network"
onRetry={() => {}}
showRetry={false}
/>
);
expect(screen.queryByRole('button', { name: /Try Again/i })).not.toBeInTheDocument();
});
});