Skip to content
Merged
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: import { isModalSupported } from ''../../src/js/feedback/utils''; and then (isModalSupported as jest.MockedFunction<typeof isModalSupported>) should also work and it will be typesafe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea Krystof 👍
Updated with d8ab914

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