-
Notifications
You must be signed in to change notification settings - Fork 166
Better types and tests for useKeyProps #2468
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
637f1f8
Better types + tests for useKeyProps
Saadnajmi da7f383
Change files
Saadnajmi aed8f18
Update base type
Saadnajmi a51c309
type KeyboardEvent
Saadnajmi bf0b9c1
KeyboardEvent -> KeyPressEvent
Saadnajmi 240113d
More tests + type fix
Saadnajmi b4975cb
More tests
Saadnajmi 0544ba1
Combine useKeyProps to one file
Saadnajmi fadfed7
more
Saadnajmi d26a452
PR comments
Saadnajmi 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-native-interactive-hooks-856e3a2e-9eda-44e0-a5c4-f3a83ad215f8.json
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,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Better types + tests for useKeyProps", | ||
"packageName": "@fluentui-react-native/interactive-hooks", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
const { configureJest } = require('@fluentui-react-native/scripts'); | ||
module.exports = configureJest(); | ||
const { configureReactNativeJest } = require('@fluentui-react-native/scripts'); | ||
module.exports = configureReactNativeJest('win32'); |
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
31 changes: 31 additions & 0 deletions
31
packages/utils/interactive-hooks/src/__tests__/__snapshots__/useKeyProps.test.tsx.snap
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,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Pressable with useKeyProps 1`] = ` | ||
<View | ||
accessible={true} | ||
focusable={true} | ||
keyUpEvents={ | ||
Array [ | ||
Object { | ||
"key": " ", | ||
}, | ||
Object { | ||
"key": "Enter", | ||
}, | ||
] | ||
} | ||
onBlur={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
onKeyDown={[Function]} | ||
onKeyUp={[Function]} | ||
onMouseEnter={[Function]} | ||
onMouseLeave={[Function]} | ||
onResponderGrant={[Function]} | ||
onResponderMove={[Function]} | ||
onResponderRelease={[Function]} | ||
onResponderTerminate={[Function]} | ||
onResponderTerminationRequest={[Function]} | ||
onStartShouldSetResponder={[Function]} | ||
/> | ||
`; |
4 changes: 2 additions & 2 deletions
4
...nteractive-hooks/src/events.types.test.ts → ...-hooks/src/__tests__/events.types.test.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
31 changes: 31 additions & 0 deletions
31
packages/utils/interactive-hooks/src/__tests__/useKeyProps.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,31 @@ | ||
import * as React from 'react'; | ||
import * as renderer from 'react-test-renderer'; | ||
import { Pressable } from 'react-native'; | ||
import { useKeyProps } from '../useKeyProps'; | ||
import { checkRenderConsistency, checkReRender } from '@fluentui-react-native/test-tools'; | ||
import { PressablePropsExtended } from '../usePressableState.types'; | ||
|
||
const dummyFunction = () => { | ||
console.log('dummy'); | ||
}; | ||
|
||
// Simple wrapper function to let us use `PressablePropsExtended` to fix type errors | ||
const PressableWithDesktopProps = (props: PressablePropsExtended) => { | ||
return <Pressable {...props} />; | ||
}; | ||
|
||
it('Pressable with useKeyProps', () => { | ||
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter'); | ||
const tree = renderer.create(<PressableWithDesktopProps {...keyboardProps} />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('Simple Pressable with useKeyProps rendering does not invalidate styling', () => { | ||
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter'); | ||
checkRenderConsistency(() => <PressableWithDesktopProps {...keyboardProps} />, 2); | ||
}); | ||
|
||
it('Pressable with useKeyProps re-renders correctly', () => { | ||
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter'); | ||
checkReRender(() => <PressableWithDesktopProps {...keyboardProps} />, 2); | ||
}); | ||
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.