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
Simplify the integration by directly saving the passed options
  • Loading branch information
antonis committed Jan 29, 2025
commit cbb1fd198864d777027efca9d8c9d87e4163dacc
11 changes: 1 addition & 10 deletions packages/core/src/js/feedback/integration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { Integration } from '@sentry/core';

import { defaultConfiguration } from './defaults';
import defaultStyles from './FeedbackForm.styles';
import type { FeedbackFormProps } from './FeedbackForm.types';

export const FEEDBACK_FORM_INTEGRATION_NAME = 'MobileFeedback';
Expand All @@ -13,14 +11,7 @@ type FeedbackIntegration = Integration & {
let savedOptions: Partial<FeedbackFormProps> = {};

export const feedbackIntegration = (initOptions: FeedbackFormProps = {}): FeedbackIntegration => {
savedOptions = {
...defaultConfiguration,
...initOptions,
styles: {
...defaultStyles,
...initOptions.styles,
},
};
savedOptions = initOptions;

return {
name: FEEDBACK_FORM_INTEGRATION_NAME,
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/feedback/FeedbackFormManager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from '@testing-library/react-native';
import * as React from 'react';
import { Text } from 'react-native';

import { defaultConfiguration } from '../../src/js/feedback/defaults';
import { FeedbackFormProvider, showFeedbackForm } from '../../src/js/feedback/FeedbackFormManager';
import { feedbackIntegration } from '../../src/js/feedback/integration';
import { isModalSupported } from '../../src/js/feedback/utils';
Expand Down Expand Up @@ -73,4 +74,23 @@ describe('FeedbackFormManager', () => {
expect(getByPlaceholderText('Custom Message Placeholder')).toBeTruthy();
expect(getByText('Custom Submit Button')).toBeTruthy();
});

it('showFeedbackForm displays the form with the feedbackIntegration options merged with the defaults', () => {
mockedIsModalSupported.mockReturnValue(true);
const { getByPlaceholderText, getByText } = render(
<FeedbackFormProvider>
<Text>App Components</Text>
</FeedbackFormProvider>
);

feedbackIntegration({
submitButtonLabel: 'Custom Submit Button',
}),

showFeedbackForm();

expect(getByText(defaultConfiguration.submitButtonLabel)).toBeFalsy(); // overridden value
expect(getByText('Custom Submit Button')).toBeTruthy(); // overridden value
expect(getByPlaceholderText(defaultConfiguration.messagePlaceholder)).toBeTruthy(); // default configuration value
});
});
Loading