forked from microsoft/fluentui-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseKeyProps.test.tsx
More file actions
54 lines (45 loc) · 1.86 KB
/
useKeyProps.test.tsx
File metadata and controls
54 lines (45 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 TestComponent = () => {
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter');
return <PressableWithDesktopProps {...keyboardProps} />;
};
const tree = renderer.create(<TestComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
it('useKeyProps called twice', () => {
const TestComponent = () => {
const keyboardProps1 = useKeyProps(dummyFunction, ' ', 'Enter');
const keyboardProps2 = useKeyProps(dummyFunction, ' ', 'Enter');
expect(keyboardProps1).toBe(keyboardProps2);
return <PressableWithDesktopProps {...keyboardProps2} />;
};
const tree = renderer.create(<TestComponent />).toJSON();
expect(tree).toMatchSnapshot();
});
it('Pressable with useKeyProps simple rendering does not invalidate styling', () => {
const TestComponent = () => {
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter');
return <PressableWithDesktopProps {...keyboardProps} />;
};
checkRenderConsistency(() => <TestComponent />, 2);
});
it('Pressable with useKeyProps re-renders correctly', () => {
const TestComponent = () => {
const keyboardProps = useKeyProps(dummyFunction, ' ', 'Enter');
return <PressableWithDesktopProps {...keyboardProps} />;
};
checkReRender(() => <TestComponent />, 2);
});