- Added error state with retry functionality to equipment.tsx - Display error message when sensor loading fails - Provide "Try Again" button to retry loading - Clear error on successful retry - Added error state with retry functionality to subscription.tsx - Display error message when beneficiary loading fails - Provide "Try Again" button with icon to retry loading - Show offline icon and proper error layout - Added comprehensive tests for error handling - ErrorMessage component tests for inline errors - FullScreenError component tests - Equipment screen error state tests - Subscription screen error state tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
import { ErrorMessage, FullScreenError } from '@/components/ui/ErrorMessage';
|
|
|
|
describe('ErrorMessage', () => {
|
|
it('renders error message with retry button', () => {
|
|
const onRetry = jest.fn();
|
|
const { getByText } = render(
|
|
<ErrorMessage message="Test error" onRetry={onRetry} />
|
|
);
|
|
|
|
expect(getByText('Test error')).toBeTruthy();
|
|
expect(getByText('Retry')).toBeTruthy();
|
|
});
|
|
|
|
it('calls onRetry when retry button is pressed', () => {
|
|
const onRetry = jest.fn();
|
|
const { getByText } = render(
|
|
<ErrorMessage message="Test error" onRetry={onRetry} />
|
|
);
|
|
|
|
fireEvent.press(getByText('Retry'));
|
|
expect(onRetry).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('renders without retry button when onRetry is not provided', () => {
|
|
const { queryByText } = render(<ErrorMessage message="Test error" />);
|
|
|
|
expect(queryByText('Retry')).toBeNull();
|
|
});
|
|
|
|
it('renders with skip button when onSkip is provided', () => {
|
|
const onSkip = jest.fn();
|
|
const { getByText } = render(
|
|
<ErrorMessage message="Test error" onSkip={onSkip} />
|
|
);
|
|
|
|
expect(getByText('Skip')).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe('FullScreenError', () => {
|
|
it('renders full screen error with retry button', () => {
|
|
const onRetry = jest.fn();
|
|
const { getByText } = render(
|
|
<FullScreenError message="Connection failed" onRetry={onRetry} />
|
|
);
|
|
|
|
expect(getByText('Something went wrong')).toBeTruthy();
|
|
expect(getByText('Connection failed')).toBeTruthy();
|
|
expect(getByText('Try Again')).toBeTruthy();
|
|
});
|
|
|
|
it('calls onRetry when Try Again button is pressed', () => {
|
|
const onRetry = jest.fn();
|
|
const { getByText } = render(
|
|
<FullScreenError message="Connection failed" onRetry={onRetry} />
|
|
);
|
|
|
|
fireEvent.press(getByText('Try Again'));
|
|
expect(onRetry).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('renders custom title', () => {
|
|
const { getByText } = render(
|
|
<FullScreenError title="Custom Error" message="Test message" />
|
|
);
|
|
|
|
expect(getByText('Custom Error')).toBeTruthy();
|
|
});
|
|
|
|
it('renders without retry button when onRetry is not provided', () => {
|
|
const { queryByText } = render(
|
|
<FullScreenError message="Connection failed" />
|
|
);
|
|
|
|
expect(queryByText('Try Again')).toBeNull();
|
|
});
|
|
});
|