@@ -16,7 +16,7 @@ let ReactNative;
16
16
let UIManager ;
17
17
let createReactNativeComponentClass ;
18
18
19
- describe ( 'ReactFabric' , ( ) => {
19
+ describe ( 'created with ReactFabric called with ReactNative ' , ( ) => {
20
20
beforeEach ( ( ) => {
21
21
jest . resetModules ( ) ;
22
22
require ( 'react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager' ) ;
@@ -55,7 +55,7 @@ describe('ReactFabric', () => {
55
55
} ) ;
56
56
57
57
it ( 'dispatches commands on Fabric nodes with the RN renderer' , ( ) => {
58
- UIManager . dispatchViewManagerCommand . mockReset ( ) ;
58
+ nativeFabricUIManager . dispatchCommand . mockClear ( ) ;
59
59
const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
60
60
validAttributes : { title : true } ,
61
61
uiViewClassName : 'RCTView' ,
@@ -64,13 +64,75 @@ describe('ReactFabric', () => {
64
64
let ref = React . createRef ( ) ;
65
65
66
66
ReactFabric . render ( < View title = "bar" ref = { ref } /> , 11 ) ;
67
- expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
67
+ expect ( nativeFabricUIManager . dispatchCommand ) . not . toBeCalled ( ) ;
68
68
ReactNative . dispatchCommand ( ref . current , 'myCommand' , [ 10 , 20 ] ) ;
69
+ expect ( nativeFabricUIManager . dispatchCommand ) . toHaveBeenCalledTimes ( 1 ) ;
70
+ expect ( nativeFabricUIManager . dispatchCommand ) . toHaveBeenCalledWith (
71
+ expect . any ( Object ) ,
72
+ 'myCommand' ,
73
+ [ 10 , 20 ] ,
74
+ ) ;
75
+ expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
76
+ } ) ;
77
+ } ) ;
78
+
79
+ describe ( 'created with ReactNative called with ReactFabric' , ( ) => {
80
+ beforeEach ( ( ) => {
81
+ jest . resetModules ( ) ;
82
+ require ( 'react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager' ) ;
83
+ ReactFabric = require ( 'react-native-renderer/fabric' ) ;
84
+ jest . resetModules ( ) ;
85
+ UIManager = require ( 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' )
86
+ . UIManager ;
87
+ jest . mock ( 'shared/ReactFeatureFlags' , ( ) =>
88
+ require ( 'shared/forks/ReactFeatureFlags.native-oss' ) ,
89
+ ) ;
90
+ ReactNative = require ( 'react-native-renderer' ) ;
91
+
92
+ React = require ( 'react' ) ;
93
+ createReactNativeComponentClass = require ( 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' )
94
+ . ReactNativeViewConfigRegistry . register ;
95
+ } ) ;
96
+
97
+ it ( 'find Paper nodes with the Fabric renderer' , ( ) => {
98
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
99
+ validAttributes : { title : true } ,
100
+ uiViewClassName : 'RCTView' ,
101
+ } ) ) ;
102
+
103
+ let ref = React . createRef ( ) ;
104
+
105
+ class Component extends React . Component {
106
+ render ( ) {
107
+ return < View title = "foo" /> ;
108
+ }
109
+ }
110
+
111
+ ReactNative . render ( < Component ref = { ref } /> , 11 ) ;
112
+
113
+ let handle = ReactFabric . findNodeHandle ( ref . current ) ;
114
+ expect ( handle ) . toBe ( 3 ) ;
115
+ } ) ;
116
+
117
+ it ( 'dispatches commands on Paper nodes with the Fabric renderer' , ( ) => {
118
+ UIManager . dispatchViewManagerCommand . mockReset ( ) ;
119
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
120
+ validAttributes : { title : true } ,
121
+ uiViewClassName : 'RCTView' ,
122
+ } ) ) ;
123
+
124
+ let ref = React . createRef ( ) ;
125
+
126
+ ReactNative . render ( < View title = "bar" ref = { ref } /> , 11 ) ;
127
+ expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
128
+ ReactFabric . dispatchCommand ( ref . current , 'myCommand' , [ 10 , 20 ] ) ;
69
129
expect ( UIManager . dispatchViewManagerCommand ) . toHaveBeenCalledTimes ( 1 ) ;
70
130
expect ( UIManager . dispatchViewManagerCommand ) . toHaveBeenCalledWith (
71
131
expect . any ( Number ) ,
72
132
'myCommand' ,
73
133
[ 10 , 20 ] ,
74
134
) ;
135
+
136
+ expect ( nativeFabricUIManager . dispatchCommand ) . not . toBeCalled ( ) ;
75
137
} ) ;
76
138
} ) ;
0 commit comments