Skip to content

Commit f4df57c

Browse files
committed
Adds tests
1 parent 587c3fc commit f4df57c

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

packages/core/src/js/feedback/FeedbackFormManager.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> {
6868
{this.props.children}
6969
{isVisible && (
7070
<View>
71-
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose}>
71+
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose} testID="feedback-form-modal">
7272
<View style={styles.modalBackground}>
7373
<FeedbackForm
7474
onFormClose={this._handleClose}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { logger } from '@sentry/core';
2+
import { render } from '@testing-library/react-native';
3+
import * as React from 'react';
4+
import { Text } from 'react-native';
5+
6+
import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager';
7+
8+
jest.mock('../../src/js/feedback/utils', () => ({
9+
isModalSupported: jest.fn(),
10+
}));
11+
12+
beforeEach(() => {
13+
logger.error = jest.fn();
14+
});
15+
16+
describe('FeedbackFormManager', () => {
17+
it('showFeedbackForm displays the form when FeedbackFormProvider is used', () => {
18+
require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(true);
19+
const { getByText, getByTestId } = render(
20+
<FeedbackFormProvider>
21+
<Text>App Components</Text>
22+
</FeedbackFormProvider>
23+
);
24+
25+
showFeedbackForm();
26+
27+
expect(getByTestId('feedback-form-modal')).toBeTruthy();
28+
expect(getByText('App Components')).toBeTruthy();
29+
});
30+
31+
it('showFeedbackForm does not display the form when Modal is not available', () => {
32+
require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(false);
33+
const { getByText, queryByTestId } = render(
34+
<FeedbackFormProvider>
35+
<Text>App Components</Text>
36+
</FeedbackFormProvider>
37+
);
38+
39+
showFeedbackForm();
40+
41+
expect(queryByTestId('feedback-form-modal')).toBeNull();
42+
expect(getByText('App Components')).toBeTruthy();
43+
expect(logger.error).toHaveBeenLastCalledWith(
44+
'FeedbackForm Modal is not supported in React Native < 0.71 with Fabric renderer.',
45+
);
46+
});
47+
48+
it('showFeedbackForm does not throw an error when FeedbackFormProvider is not used', () => {
49+
expect(() => {
50+
showFeedbackForm();
51+
}).not.toThrow();
52+
});
53+
});

0 commit comments

Comments
 (0)