Skip to content

Commit

Permalink
Show success alert message
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Dec 11, 2024
1 parent 6717a84 commit 39a67bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor

closeScreen();
captureFeedback(userFeedback);
Alert.alert(text.successMessageText);
};

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/js/feedback/FeedbackForm.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export interface FeedbackTextConfiguration {
*/
nameLabel?: string;

/**
* Message after feedback was sent successfully
*/
successMessageText?: string;

/**
* Placeholder text for Feedback name input
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/js/feedback/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CANCEL_BUTTON_LABEL = 'Cancel';
const ERROR_TITLE = 'Error';
const FORM_ERROR = 'Please fill out all required fields.';
const EMAIL_ERROR = 'Please enter a valid email address.';
const SUCCESS_MESSAGE_TEXT = 'Thank you for your report!';

export const defaultConfiguration: Partial<FeedbackFormProps> = {
// FeedbackGeneralConfiguration
Expand All @@ -41,4 +42,5 @@ export const defaultConfiguration: Partial<FeedbackFormProps> = {
errorTitle: ERROR_TITLE,
formError: FORM_ERROR,
emailError: EMAIL_ERROR,
successMessageText: SUCCESS_MESSAGE_TEXT,
};
15 changes: 15 additions & 0 deletions packages/core/test/feedback/FeedbackForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const defaultProps: FeedbackFormProps = {
errorTitle: 'Error',
formError: 'Please fill out all required fields.',
emailError: 'The email address is not valid.',
successMessageText: 'Feedback success',
};

describe('FeedbackForm', () => {
Expand Down Expand Up @@ -109,6 +110,20 @@ describe('FeedbackForm', () => {
});
});

it('shows success message when the form is submitted successfully', async () => {
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />);

fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe');
fireEvent.changeText(getByPlaceholderText(defaultProps.emailPlaceholder), '[email protected]');
fireEvent.changeText(getByPlaceholderText(defaultProps.messagePlaceholder), 'This is a feedback message.');

fireEvent.press(getByText(defaultProps.submitButtonLabel));

await waitFor(() => {
expect(Alert.alert).toHaveBeenCalledWith(defaultProps.successMessageText);
});
});

it('calls closeScreen when the form is submitted successfully', async () => {
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />);

Expand Down

0 comments on commit 39a67bd

Please sign in to comment.