Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds tests
  • Loading branch information
antonis committed Jan 27, 2025
commit f4df57c2c52ac2c6709863ad4fab39e0fecaec44
2 changes: 1 addition & 1 deletion packages/core/src/js/feedback/FeedbackFormManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FeedbackFormProvider extends React.Component<FeedbackFormProviderProps> {
{this.props.children}
{isVisible && (
<View>
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose}>
<Modal visible={isVisible} transparent animationType="slide" onRequestClose={this._handleClose} testID="feedback-form-modal">
<View style={styles.modalBackground}>
<FeedbackForm
onFormClose={this._handleClose}
Expand Down
53 changes: 53 additions & 0 deletions packages/core/test/feedback/FeedbackFormManager.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { logger } from '@sentry/core';
import { render } from '@testing-library/react-native';
import * as React from 'react';
import { Text } from 'react-native';

import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager';

jest.mock('../../src/js/feedback/utils', () => ({
isModalSupported: jest.fn(),
}));

beforeEach(() => {
logger.error = jest.fn();
});

describe('FeedbackFormManager', () => {
it('showFeedbackForm displays the form when FeedbackFormProvider is used', () => {
require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(true);
const { getByText, getByTestId } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

showFeedbackForm();

expect(getByTestId('feedback-form-modal')).toBeTruthy();
expect(getByText('App Components')).toBeTruthy();
});

it('showFeedbackForm does not display the form when Modal is not available', () => {
require('../../src/js/feedback/utils').isModalSupported.mockReturnValue(false);
const { getByText, queryByTestId } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

showFeedbackForm();

expect(queryByTestId('feedback-form-modal')).toBeNull();
expect(getByText('App Components')).toBeTruthy();
expect(logger.error).toHaveBeenLastCalledWith(
'FeedbackForm Modal is not supported in React Native < 0.71 with Fabric renderer.',
);
});

it('showFeedbackForm does not throw an error when FeedbackFormProvider is not used', () => {
expect(() => {
showFeedbackForm();
}).not.toThrow();
});
});
Loading