Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit b20b154

Browse files
committed
add: create tests for FilterTabs, GiftCard, and RecipientCard components to verify rendering and interaction
1 parent c4488ad commit b20b154

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { fireEvent, render } from '@testing-library/react-native';
2+
3+
import FilterTabs from '@/components/utils/FilterTabs';
4+
5+
describe('FilterTabs Component', () => {
6+
it('should render all tabs', () => {
7+
const mockProps = {
8+
selectedTab: 'All',
9+
onSelectTab: jest.fn(),
10+
recipients: [
11+
{ id: '1', name: 'John Doe' },
12+
{ id: '2', name: 'Jane Smith' },
13+
],
14+
selectedRecipient: null,
15+
onSelectRecipient: jest.fn(),
16+
};
17+
18+
const { getByText } = render(<FilterTabs {...mockProps} />);
19+
expect(getByText('All')).toBeTruthy();
20+
expect(getByText('Recipients')).toBeTruthy();
21+
});
22+
23+
it('should call onSelectTab when a tab is pressed', () => {
24+
const mockOnSelectTab = jest.fn();
25+
const mockProps = {
26+
selectedTab: 'All',
27+
onSelectTab: mockOnSelectTab,
28+
recipients: [
29+
{ id: '1', name: 'John Doe' },
30+
{ id: '2', name: 'Jane Smith' },
31+
],
32+
selectedRecipient: null,
33+
onSelectRecipient: jest.fn(),
34+
};
35+
36+
const { getByText } = render(<FilterTabs {...mockProps} />);
37+
fireEvent.press(getByText('All'));
38+
expect(mockOnSelectTab).toHaveBeenCalledWith('All');
39+
});
40+
41+
it('should open the recipient modal when the Recipients tab is pressed', () => {
42+
const mockProps = {
43+
selectedTab: 'All',
44+
onSelectTab: jest.fn(),
45+
recipients: [
46+
{ id: '1', name: 'John Doe' },
47+
{ id: '2', name: 'Jane Smith' },
48+
],
49+
selectedRecipient: null,
50+
onSelectRecipient: jest.fn(),
51+
};
52+
53+
const { getByText } = render(<FilterTabs {...mockProps} />);
54+
fireEvent.press(getByText('Recipients'));
55+
expect(getByText('Select Recipient')).toBeTruthy();
56+
});
57+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { fireEvent, render } from '@testing-library/react-native';
2+
3+
import GiftCard from '@/components/utils/GiftCard';
4+
5+
describe('GiftCard Component', () => {
6+
it('should render gift details correctly', () => {
7+
const mockProps = {
8+
id: '1', // Updated to string
9+
image: 'https://example.com/image.jpg',
10+
title: 'Gift 1',
11+
description: 'A wonderful gift',
12+
price: 20,
13+
recipient: '1',
14+
selectedDate: '2025-05-01',
15+
};
16+
17+
const { getByText } = render(<GiftCard {...mockProps} />);
18+
expect(getByText('Gift 1')).toBeTruthy();
19+
expect(getByText('for Loading...')).toBeTruthy();
20+
expect(getByText('Happening on May 1, 2025')).toBeTruthy();
21+
});
22+
23+
it('should trigger onPress when the card is clicked', () => {
24+
const mockOnPress = jest.fn();
25+
const mockProps = {
26+
id: '1', // Updated to string
27+
image: 'https://example.com/image.jpg',
28+
title: 'Gift 1',
29+
description: 'A wonderful gift',
30+
price: 20,
31+
recipient: '1',
32+
selectedDate: '2025-05-01',
33+
onEdit: mockOnPress,
34+
};
35+
36+
const { getByText } = render(<GiftCard {...mockProps} />);
37+
fireEvent.press(getByText('Gift 1'));
38+
expect(mockOnPress).toHaveBeenCalled();
39+
});
40+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { fireEvent, render } from '@testing-library/react-native';
2+
3+
import RecipientCard from '@/components/utils/RecipientCard';
4+
5+
describe('RecipientCard Component', () => {
6+
it('should render recipient details correctly', () => {
7+
const recipient = { id: 1, name: 'John Doe', giftCount: 3 };
8+
const { getByText } = render(<RecipientCard recipient={recipient} />);
9+
expect(getByText('John Doe')).toBeTruthy();
10+
expect(getByText('3 Gifts')).toBeTruthy();
11+
});
12+
13+
it('should trigger onPress when the card is clicked', () => {
14+
const mockOnPress = jest.fn();
15+
const recipient = { id: 1, name: 'John Doe', giftCount: 3 };
16+
const { getByText } = render(
17+
<RecipientCard recipient={recipient} onPress={mockOnPress} />,
18+
);
19+
fireEvent.press(getByText('John Doe'));
20+
expect(mockOnPress).toHaveBeenCalledWith(recipient);
21+
});
22+
});

0 commit comments

Comments
 (0)