-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Update mocks #3854
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
Open
akwasniewski
wants to merge
10
commits into
next
Choose a base branch
from
@akwasniewski/update-mocks
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−14
Open
Update mocks #3854
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8f13c5e
update mocks
akwasniewski 694761e
update hook
akwasniewski 87eea00
virtual detector
akwasniewski 4b2fa18
rest
akwasniewski 08abfcc
rename to errors
akwasniewski bc8a4bc
capitalise test suite name
akwasniewski 2b5ac66
mocking HostGestureDetector directly
akwasniewski 40eed71
restores relation traversal
akwasniewski 390de3f
styling
akwasniewski bb4b556
Merge branch 'next' into @akwasniewski/update-mocks
akwasniewski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
125 changes: 125 additions & 0 deletions
125
packages/react-native-gesture-handler/src/__tests__/Errors.test.tsx
This file contains hidden or 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,125 @@ | ||
| import React from 'react'; | ||
| import { render, cleanup } from '@testing-library/react-native'; | ||
| import { | ||
| Gesture, | ||
| GestureDetector, | ||
| GestureHandlerRootView, | ||
| InterceptingGestureDetector, | ||
| useTapGesture, | ||
| } from '../index'; | ||
| import { findNodeHandle, View } from 'react-native'; | ||
| import { VirtualDetector } from '../v3/detectors/VirtualDetector/VirtualDetector'; | ||
|
|
||
| beforeEach(() => cleanup()); | ||
| jest.mock('react-native/Libraries/ReactNative/RendererProxy', () => ({ | ||
| findNodeHandle: jest.fn(), | ||
| })); | ||
|
|
||
| describe('VirtualDetector', () => { | ||
| test('virtual detector must be under InterceptingGestureDetector', () => { | ||
| function VirtualDetectorWithNoBoundary() { | ||
| const tap = useTapGesture({}); | ||
| return ( | ||
| <GestureHandlerRootView> | ||
| <VirtualDetector gesture={tap}> | ||
| <View /> | ||
| </VirtualDetector> | ||
| </GestureHandlerRootView> | ||
| ); | ||
| } | ||
|
|
||
| expect(() => render(<VirtualDetectorWithNoBoundary />)).toThrow( | ||
| 'VirtualGestureDetector must be a descendant of an InterceptingGestureDetector' | ||
| ); | ||
| }); | ||
| test('virtual detector does not handle animated events', () => { | ||
| (findNodeHandle as jest.Mock).mockReturnValue(123); | ||
|
|
||
| function VirtualDetectorAnimated() { | ||
| const tap = useTapGesture({ useAnimated: true }); | ||
| return ( | ||
| <GestureHandlerRootView> | ||
| <InterceptingGestureDetector> | ||
| <VirtualDetector gesture={tap}> | ||
| <View /> | ||
| </VirtualDetector> | ||
| </InterceptingGestureDetector> | ||
| </GestureHandlerRootView> | ||
| ); | ||
| } | ||
|
|
||
| expect(() => render(<VirtualDetectorAnimated />)).toThrow( | ||
| 'VirtualGestureDetector cannot handle Animated events with native driver when used inside InterceptingGestureDetector. Use Reanimated or Animated events without native driver instead.' | ||
| ); | ||
| }); | ||
|
|
||
| test('intercepting detector cant handle multiple types of events', () => { | ||
| (findNodeHandle as jest.Mock).mockReturnValue(123); | ||
| const mockWorklet = () => undefined; | ||
| mockWorklet.__workletHash = 123; | ||
|
|
||
| function InterceptingDetectorMultipleTypes() { | ||
| const tap = useTapGesture({ useAnimated: true }); | ||
| const tap2 = useTapGesture({ onActivate: mockWorklet }); | ||
| return ( | ||
| <GestureHandlerRootView> | ||
| <InterceptingGestureDetector gesture={tap}> | ||
| <VirtualDetector gesture={tap2}> | ||
| <View /> | ||
| </VirtualDetector> | ||
| </InterceptingGestureDetector> | ||
| </GestureHandlerRootView> | ||
| ); | ||
| } | ||
|
|
||
| expect(() => render(<InterceptingDetectorMultipleTypes />)).toThrow( | ||
| 'InterceptingGestureDetector can only handle either Reanimated or Animated events.' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Check if descendant of root view', () => { | ||
| test('gesture detector', () => { | ||
| function GestureDetectorNoRootView() { | ||
| const tap = useTapGesture({}); | ||
| return ( | ||
| <GestureDetector gesture={tap}> | ||
| <View /> | ||
| </GestureDetector> | ||
| ); | ||
| } | ||
| expect(() => render(<GestureDetectorNoRootView />)).toThrow( | ||
| 'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation for more details.' | ||
| ); | ||
| }); | ||
|
|
||
| test('intercepting detector', () => { | ||
| function GestureDetectorNoRootView() { | ||
| const tap = useTapGesture({}); | ||
| return ( | ||
| <InterceptingGestureDetector gesture={tap}> | ||
| <View /> | ||
| </InterceptingGestureDetector> | ||
| ); | ||
| } | ||
|
|
||
| expect(() => render(<GestureDetectorNoRootView />)).toThrow( | ||
| 'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation for more details.' | ||
| ); | ||
| }); | ||
|
|
||
| test('legacy detector', () => { | ||
| function GestureDetectorNoRootView() { | ||
| const tap = Gesture.Tap(); | ||
| return ( | ||
| <GestureDetector gesture={tap}> | ||
| <View /> | ||
| </GestureDetector> | ||
| ); | ||
| } | ||
|
|
||
| expect(() => render(<GestureDetectorNoRootView />)).toThrow( | ||
| 'GestureDetector must be used as a descendant of GestureHandlerRootView. Otherwise the gestures will not be recognized. See https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/installation for more details.' | ||
| ); | ||
| }); | ||
| }); |
10 changes: 10 additions & 0 deletions
10
packages/react-native-gesture-handler/src/mocks/GestureButtons.tsx
This file contains hidden or 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,10 @@ | ||
| import React from 'react'; | ||
| import { TouchableNativeFeedback, View } from 'react-native'; | ||
| export const RawButton = ({ enabled, ...rest }: any) => ( | ||
| <TouchableNativeFeedback disabled={enabled === false} {...rest}> | ||
| <View /> | ||
| </TouchableNativeFeedback> | ||
| ); | ||
| export const BaseButton = RawButton; | ||
| export const RectButton = RawButton; | ||
| export const BorderlessButton = TouchableNativeFeedback; |
This file contains hidden or 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
3 changes: 1 addition & 2 deletions
3
packages/react-native-gesture-handler/src/v3/detectors/useEnsureGestureHandlerRootView.ts
This file contains hidden or 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
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.
mocks?I think the current setup dates back to the time when all of Gesture Handler was a single file, so it was correct to mock everything to a single file.