-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better types and tests for useKeyProps (#2468)
* Better types + tests for useKeyProps * Change files * Update base type * type KeyboardEvent * KeyboardEvent -> KeyPressEvent * More tests + type fix * More tests * Combine useKeyProps to one file * more * PR comments
- Loading branch information
Showing
17 changed files
with
261 additions
and
296 deletions.
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 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 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 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 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 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
37 changes: 37 additions & 0 deletions
37
packages/utils/interactive-hooks/src/__tests__/useKeyProps.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,37 @@ | ||
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('useKeyProps called twice', () => { | ||
const keyboardProps1 = useKeyProps(dummyFunction, ' ', 'Enter'); | ||
const keyboardProps2 = useKeyProps(dummyFunction, ' ', 'Enter'); | ||
expect(keyboardProps1).toBe(keyboardProps2); | ||
}); | ||
|
||
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 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 was deleted.
Oops, something went wrong.
Oops, something went wrong.