Skip to content

Commit bbc676f

Browse files
committed
chore: unit test card people component
1 parent 7986265 commit bbc676f

File tree

4 files changed

+38
-111
lines changed

4 files changed

+38
-111
lines changed

template/__tests__/App.test.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

template/__tests__/__snapshots__/App.test.tsx.snap

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { fireEvent, render, waitFor } from '@testing-library/react-native';
3+
import CardPeoples from 'components/organisms/CardPeoples';
4+
5+
describe('Card People Component', () => {
6+
const onPress = jest.fn();
7+
it('should render correctly', () => {
8+
render(<CardPeoples onPress={onPress} name="React" homeworld="Earth" />);
9+
});
10+
it('should has the people name', () => {
11+
const { getByText } = render(
12+
<CardPeoples onPress={onPress} name="React" homeworld="Earth" />,
13+
);
14+
15+
expect(getByText('React')).toBeDefined();
16+
});
17+
it('should has the people homeworld', () => {
18+
const { getByText } = render(
19+
<CardPeoples onPress={onPress} name="React" homeworld="Earth" />,
20+
);
21+
22+
expect(getByText('Earth')).toBeDefined();
23+
});
24+
it('should onPress to be called', () => {
25+
const { getByTestId } = render(
26+
<CardPeoples onPress={onPress} name="React" homeworld="Earth" />,
27+
);
28+
const button = getByTestId('Button');
29+
fireEvent.press(button);
30+
expect(onPress).toBeCalled();
31+
});
32+
});

template/src/components/organisms/CardPeoples.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
import { log } from '@utils/console';
1+
import React from 'react';
22
import { WINDOW_DEVICE_WIDTH } from '@utils/constants';
33
import { Box } from 'components/molecules/Box';
44
import { Button } from 'components/molecules/Button';
55
import { Typography } from 'components/molecules/Typography';
6-
import React, { useEffect } from 'react';
76
import { IPeople } from 'src/interfaces/IPeople';
8-
import { theme } from 'theme';
9-
interface CardPeopleProps extends IPeople {
7+
interface CardPeopleProps extends Pick<IPeople, 'name' | 'homeworld'> {
108
onPress: () => void;
119
}
1210
const CardPeoples = ({ name, homeworld, onPress }: CardPeopleProps) => {
1311
return (
1412
<Box width="100%">
1513
<Button
1614
width={WINDOW_DEVICE_WIDTH * 0.8}
17-
px={'16px'}
18-
m={2}
15+
px={'ls'}
16+
m={'xs'}
1917
key={name}
2018
variant="rounded"
2119
height={80}
2220
onPress={onPress}
23-
bg={'primary'}>
21+
bg={'primary'}
22+
testID="Button">
2423
<Typography color={'secondary'}>{name}</Typography>
2524
<Typography color={'secondary'}>{homeworld}</Typography>
2625
</Button>

0 commit comments

Comments
 (0)