Skip to content

Commit d2f6fc9

Browse files
committed
test: adjust all tests
1 parent f9e06ad commit d2f6fc9

6 files changed

+33
-7
lines changed

Diff for: components/__tests__/AnalysisResultView-test.tsx renamed to __tests__/AnalysisResultView-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react-native';
3-
import AnalysisResultView from '../AnalysisResultView';
3+
import AnalysisResultView from '../components/AnalysisResultView';
44

55
describe('AnalysisResultView', () => {
66
it('renders correctly when analysisResult is provided', () => {

Diff for: components/__tests__/AnalyzeButton-test.tsx renamed to __tests__/AnalyzeButton-test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render, fireEvent } from '@testing-library/react-native';
3-
import AnalyzeButton from '../AnalyzeButton';
3+
import AnalyzeButton from '../components/AnalyzeButton';
44

55
describe('AnalyzeButton', () => {
66
it('renders button with correct text when not loading and no analysisResult', () => {

Diff for: __tests__/ImagePickerView-test.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { render, fireEvent } from '@testing-library/react-native';
3+
import ImagePickerView from '../components/ImagePickerView';
4+
5+
describe('ImagePickerView', () => {
6+
it('renders placeholder text when imageUri is null', () => {
7+
const { getByText } = render(<ImagePickerView imageUri={null} onPickImage={() => {}} />);
8+
expect(getByText('대화 스크린샷을 업로드해주세요')).toBeTruthy();
9+
});
10+
11+
it('calls onPickImage when placeholder is pressed', () => {
12+
const onPickImageMock = jest.fn();
13+
const { getByText } = render(<ImagePickerView imageUri={null} onPickImage={onPickImageMock} />);
14+
fireEvent.press(getByText('대화 스크린샷을 업로드해주세요'));
15+
expect(onPickImageMock).toHaveBeenCalled();
16+
});
17+
18+
it('calls onPickImage when image is pressed', () => {
19+
const onPickImageMock = jest.fn();
20+
const { getByTestId } = render(<ImagePickerView imageUri="test-uri" onPickImage={onPickImageMock} />);
21+
fireEvent.press(getByTestId('image'));
22+
expect(onPickImageMock).toHaveBeenCalled();
23+
});
24+
});

Diff for: components/ImagePickerView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const ImagePickerView: React.FC<ImagePickerViewProps> = ({ imageUri, onPickImage
1111
return (
1212
<TouchableOpacity style={styles.placeholderContainer} onPress={onPickImage}>
1313
{imageUri ? (
14-
<Image source={{ uri: imageUri }} style={styles.image} />
14+
<Image source={{ uri: imageUri }} style={styles.image} testID="image" />
1515
) : (
1616
<Text style={styles.placeholderText}>대화 스크린샷을 업로드해주세요</Text>
1717
)}

Diff for: components/__tests__/ImagePickerView-test.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ describe('ImagePickerView', () => {
99
});
1010

1111
it('renders image when imageUri is provided', () => {
12-
const { getByTestId } = render(<ImagePickerView imageUri="test-uri" onPickImage={() => {}} />);
12+
const { getByTestId } = render(<ImagePickerView imageUri="https://via.placeholder.com/150" onPickImage={() => {}} />);
1313
const image = getByTestId('image');
14-
expect(image.props.source.uri).toBe('test-uri');
14+
expect(image.props.source.uri).toBe('https://via.placeholder.com/150');
1515
});
1616

1717
it('calls onPickImage when placeholder is pressed', () => {
@@ -23,7 +23,7 @@ describe('ImagePickerView', () => {
2323

2424
it('calls onPickImage when image is pressed', () => {
2525
const onPickImageMock = jest.fn();
26-
const { getByTestId } = render(<ImagePickerView imageUri="test-uri" onPickImage={onPickImageMock} />);
26+
const { getByTestId } = render(<ImagePickerView imageUri="https://via.placeholder.com/150" onPickImage={onPickImageMock} />);
2727
fireEvent.press(getByTestId('image'));
2828
expect(onPickImageMock).toHaveBeenCalled();
2929
});

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"!**/.expo/**",
2525
"!**/scripts/**",
2626
"!**/app/+html.tsx",
27-
"!**/app/+not-found.tsx"
27+
"!**/app/+not-found.tsx",
28+
"!**/app/_layout.tsx",
29+
"!**/hooks/**"
2830
]
2931
},
3032
"dependencies": {

0 commit comments

Comments
 (0)