From 39a67bd9ee34ef95abcb247021e32526e01821ff Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 11 Dec 2024 11:34:21 +0200 Subject: [PATCH] Show success alert message --- packages/core/src/js/feedback/FeedbackForm.tsx | 1 + .../core/src/js/feedback/FeedbackForm.types.ts | 5 +++++ packages/core/src/js/feedback/defaults.ts | 2 ++ packages/core/test/feedback/FeedbackForm.test.tsx | 15 +++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/packages/core/src/js/feedback/FeedbackForm.tsx b/packages/core/src/js/feedback/FeedbackForm.tsx index 84b9f3c9c..d99d1da13 100644 --- a/packages/core/src/js/feedback/FeedbackForm.tsx +++ b/packages/core/src/js/feedback/FeedbackForm.tsx @@ -52,6 +52,7 @@ export class FeedbackForm extends React.Component = { // FeedbackGeneralConfiguration @@ -41,4 +42,5 @@ export const defaultConfiguration: Partial = { errorTitle: ERROR_TITLE, formError: FORM_ERROR, emailError: EMAIL_ERROR, + successMessageText: SUCCESS_MESSAGE_TEXT, }; diff --git a/packages/core/test/feedback/FeedbackForm.test.tsx b/packages/core/test/feedback/FeedbackForm.test.tsx index 10b1f41c3..780995900 100644 --- a/packages/core/test/feedback/FeedbackForm.test.tsx +++ b/packages/core/test/feedback/FeedbackForm.test.tsx @@ -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', () => { @@ -109,6 +110,20 @@ describe('FeedbackForm', () => { }); }); + it('shows success message when the form is submitted successfully', async () => { + const { getByPlaceholderText, getByText } = render(); + + fireEvent.changeText(getByPlaceholderText(defaultProps.namePlaceholder), 'John Doe'); + fireEvent.changeText(getByPlaceholderText(defaultProps.emailPlaceholder), 'john.doe@example.com'); + 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();