-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,11 +44,12 @@ const defaultProps: FeedbackFormProps = { | |
emailError: 'The email address is not valid.', | ||
successMessageText: 'Feedback success', | ||
networkError: 'Network error', | ||
genericError: 'Generic error', | ||
}; | ||
|
||
describe('FeedbackForm', () => { | ||
beforeEach(() => { | ||
(checkInternetConnection as jest.Mock).mockImplementation((onConnected, _) => { | ||
(checkInternetConnection as jest.Mock).mockImplementation((onConnected, _onDisconnected, _onError) => { | ||
onConnected(); | ||
}); | ||
}); | ||
|
@@ -138,7 +139,7 @@ describe('FeedbackForm', () => { | |
}); | ||
|
||
it('shows an error message when there is no network connection', async () => { | ||
(checkInternetConnection as jest.Mock).mockImplementationOnce((_, onDisconnected) => { | ||
(checkInternetConnection as jest.Mock).mockImplementationOnce((_onConnected, onDisconnected, _onError) => { | ||
onDisconnected(); | ||
}); | ||
|
||
|
@@ -155,6 +156,24 @@ describe('FeedbackForm', () => { | |
}); | ||
}); | ||
|
||
it('shows an error message when there is a generic connection', async () => { | ||
(checkInternetConnection as jest.Mock).mockImplementationOnce((_onConnected, _onDisconnected, onError) => { | ||
onError(); | ||
}); | ||
|
||
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.errorTitle, defaultProps.networkError); | ||
}); | ||
}); | ||
|
||
it('calls onFormClose when the form is submitted successfully', async () => { | ||
const { getByPlaceholderText, getByText } = render(<FeedbackForm {...defaultProps} />); | ||
|
||
|