-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/labsAndTests
- Loading branch information
Showing
16 changed files
with
337 additions
and
65 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
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
120 changes: 120 additions & 0 deletions
120
.../HomeScreen/ProfileScreen/SettingsScreen/InAppFeedbackScreen/InAppFeedbackscreen.test.tsx
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React from 'react' | ||
import { Alert } from 'react-native' | ||
|
||
import { StackScreenProps } from '@react-navigation/stack' | ||
|
||
import { waitFor } from '@testing-library/react-native' | ||
import { RootNavStackParamList } from 'App' | ||
import { t } from 'i18next' | ||
|
||
import { context, fireEvent, render, screen } from 'testUtils' | ||
|
||
import InAppFeedbackScreen from './InAppFeedbackScreen' | ||
|
||
const mockNavigationSpy = jest.fn() | ||
jest.mock('utils/hooks', () => { | ||
const original = jest.requireActual('utils/hooks') | ||
return { | ||
...original, | ||
useRouteNavigation: () => mockNavigationSpy, | ||
} | ||
}) | ||
|
||
context('InAppFeedbackScreen', () => { | ||
const initializeTestInstance = () => { | ||
const props = { | ||
navigation: { | ||
goBack: jest.fn(), | ||
addListener: jest.fn().mockReturnValue(() => {}), | ||
}, | ||
route: { | ||
params: { | ||
screen: 'InAppFeedback', | ||
}, | ||
}, | ||
} as unknown as StackScreenProps<RootNavStackParamList, 'InAppFeedback'> | ||
|
||
render(<InAppFeedbackScreen {...props} />) | ||
return props | ||
} | ||
|
||
beforeEach(() => { | ||
jest.spyOn(Alert, 'alert').mockClear() | ||
}) | ||
|
||
describe('onSubmit behavior with various inputs', () => { | ||
const submitFeedback = (text: string) => { | ||
fireEvent.changeText(screen.getByTestId('AppFeedbackTaskID'), text) | ||
fireEvent.press(screen.getByRole('button', { name: t('inAppFeedback.submitFeedback') })) | ||
} | ||
|
||
it('does NOT alert for normal text', async () => { | ||
initializeTestInstance() | ||
submitFeedback('Hello, I want to submit some feedback.') | ||
await waitFor(() => { | ||
// No alert means no PII found | ||
expect(Alert.alert).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
// ------------------ | ||
// SSN TEST CASES | ||
// ------------------ | ||
it('alerts for an SSN with leading punctuation', async () => { | ||
initializeTestInstance() | ||
submitFeedback('My SSN:123-45-6789') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
// ------------------ | ||
// PHONE NUMBER TEST CASES | ||
// ------------------ | ||
it('alerts for a phone number with leading text', async () => { | ||
initializeTestInstance() | ||
submitFeedback('Call me123-456-7890') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
it('alerts for a phone number with trailing punctuation', async () => { | ||
initializeTestInstance() | ||
submitFeedback('Call me at 123-456-7890.') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
// ------------------ | ||
// EMAIL TEST CASES | ||
// ------------------ | ||
it('alerts for a valid email address', async () => { | ||
initializeTestInstance() | ||
submitFeedback('Please email me at [email protected]') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
it('alerts for an email address with leading punctuation', async () => { | ||
initializeTestInstance() | ||
submitFeedback('My email is,[email protected], thanks!') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
// ------------------ | ||
// MAILTO TEST CASES | ||
// ------------------ | ||
it('alerts for a mailto link with leading punctuation', async () => { | ||
initializeTestInstance() | ||
submitFeedback('(mailto:[email protected])') | ||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.