-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert WelcomeScreen to hooks and Typescript #943
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
jest.mock('react-native-firebase', () => ({ | ||
links: jest.fn(), | ||
onLink: jest.fn(), | ||
getInitialLink: jest.fn(() => Promise.resolve('firebaseDeepLinkUri')), | ||
})); |
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 was deleted.
Oops, something went wrong.
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,91 @@ | ||
import 'react-native'; | ||
import React from 'react'; | ||
import { fireEvent } from 'react-native-testing-library'; | ||
|
||
import WelcomeScreen from '..'; | ||
|
||
import { renderWithContext, snapshotWithContext } from '../../../../testUtils'; | ||
import * as common from '../../../utils/common'; | ||
import { trackActionWithoutData } from '../../../actions/analytics'; | ||
import { ACTIONS } from '../../../constants'; | ||
|
||
const next = jest.fn(() => () => {}); | ||
|
||
jest.mock('react-native-device-info'); | ||
jest.mock('../../../actions/analytics'); | ||
jest.mock('../../../components/BottomButton', () => 'BottomButton'); | ||
jest.mock('../../../components/common', () => ({ | ||
Flex: 'Flex', | ||
Text: 'Text', | ||
Button: 'Button', | ||
})); | ||
|
||
// @ts-ignore | ||
common.disableBack = { add: jest.fn(), remove: jest.fn() }; | ||
|
||
(trackActionWithoutData as jest.Mock).mockReturnValue({ | ||
type: 'tracked action without data', | ||
}); | ||
|
||
describe('WelcomeScreen', () => { | ||
const allowSignInVariantConfig = { | ||
navParams: { allowSignIn: true }, | ||
}; | ||
|
||
it('should render correctly', () => { | ||
snapshotWithContext(<WelcomeScreen next={next} />); | ||
}); | ||
|
||
it('should render correctly with sign in button', () => { | ||
snapshotWithContext( | ||
<WelcomeScreen next={next} />, | ||
allowSignInVariantConfig, | ||
); | ||
}); | ||
|
||
it('getStarted btn should call next', () => { | ||
const { getByTestId } = renderWithContext(<WelcomeScreen next={next} />); | ||
fireEvent(getByTestId('get-started'), 'onPress'); | ||
|
||
expect(common.disableBack.remove).toHaveBeenCalledTimes(1); | ||
expect(next).toHaveBeenCalledTimes(1); | ||
expect(next).toHaveBeenCalledWith({ signin: false }); | ||
}); | ||
|
||
it('tryItNow btn should call next', () => { | ||
const { getByTestId } = renderWithContext( | ||
<WelcomeScreen next={next} />, | ||
allowSignInVariantConfig, | ||
); | ||
fireEvent(getByTestId('get-started-sign-in-variant'), 'onPress'); | ||
|
||
expect(common.disableBack.remove).toHaveBeenCalledTimes(1); | ||
expect(next).toHaveBeenCalledTimes(1); | ||
expect(next).toHaveBeenCalledWith({ signin: false }); | ||
}); | ||
|
||
it('signIn btn should call next with signIn = true', () => { | ||
const { getByTestId } = renderWithContext( | ||
<WelcomeScreen next={next} />, | ||
allowSignInVariantConfig, | ||
); | ||
fireEvent(getByTestId('sign-in'), 'onPress'); | ||
|
||
expect(next).toHaveBeenCalledTimes(1); | ||
expect(next).toHaveBeenCalledWith({ signin: true }); | ||
}); | ||
|
||
it('should fire analytics event on mount', () => { | ||
renderWithContext(<WelcomeScreen next={next} />); | ||
|
||
expect(trackActionWithoutData).toHaveBeenCalledWith( | ||
ACTIONS.ONBOARDING_STARTED, | ||
); | ||
}); | ||
|
||
it('should clean up back handler on unmount', () => { | ||
renderWithContext(<WelcomeScreen next={next} />).unmount(); | ||
|
||
expect(common.disableBack.remove).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. This might simplify a lot of the testing set-up. I gotta get familiar with
react-native-testing-library
as well!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya let's have a conversation about testing sometime :) I like the new helper function and expanded upon it and fixed a few things in my graphql branch. I think
react-native-testing-library
is a good compromise of old and new. We can mock stuff to approximate shallow rendering and shallow snapshots. But it tries to keep you from calling implementation details directly.I've also looked at
native-testing-library
but it's a lot more opinionated. It pushes you towards integration testing and doesn't support events on mocked components. testing-library/native-testing-library#17Enzyme just still doesn't support the new React Context APIs used by a lot of the newer libraries or Hooks...