@@ -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' ) ;
@@ -75,7 +75,7 @@ describe('ReactFabric', () => {
75
75
} ) ;
76
76
77
77
it ( 'dispatches commands on Fabric nodes with the RN renderer' , ( ) => {
78
- UIManager . dispatchViewManagerCommand . mockReset ( ) ;
78
+ nativeFabricUIManager . dispatchCommand . mockClear ( ) ;
79
79
const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
80
80
validAttributes : { title : true } ,
81
81
uiViewClassName : 'RCTView' ,
@@ -84,13 +84,95 @@ describe('ReactFabric', () => {
84
84
let ref = React . createRef ( ) ;
85
85
86
86
ReactFabric . render ( < View title = "bar" ref = { ref } /> , 11 ) ;
87
- expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
87
+ expect ( nativeFabricUIManager . dispatchCommand ) . not . toBeCalled ( ) ;
88
88
ReactNative . dispatchCommand ( ref . current , 'myCommand' , [ 10 , 20 ] ) ;
89
+ expect ( nativeFabricUIManager . dispatchCommand ) . toHaveBeenCalledTimes ( 1 ) ;
90
+ expect ( nativeFabricUIManager . dispatchCommand ) . toHaveBeenCalledWith (
91
+ expect . any ( Object ) ,
92
+ 'myCommand' ,
93
+ [ 10 , 20 ] ,
94
+ ) ;
95
+ expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( 'created with ReactNative called with ReactFabric' , ( ) => {
100
+ beforeEach ( ( ) => {
101
+ jest . resetModules ( ) ;
102
+ require ( 'react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager' ) ;
103
+ ReactFabric = require ( 'react-native-renderer/fabric' ) ;
104
+ jest . resetModules ( ) ;
105
+ UIManager = require ( 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' )
106
+ . UIManager ;
107
+ jest . mock ( 'shared/ReactFeatureFlags' , ( ) =>
108
+ require ( 'shared/forks/ReactFeatureFlags.native-oss' ) ,
109
+ ) ;
110
+ ReactNative = require ( 'react-native-renderer' ) ;
111
+
112
+ React = require ( 'react' ) ;
113
+ createReactNativeComponentClass = require ( 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface' )
114
+ . ReactNativeViewConfigRegistry . register ;
115
+ } ) ;
116
+
117
+ it ( 'find Paper instances with the Fabric renderer' , ( ) => {
118
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
119
+ validAttributes : { title : true } ,
120
+ uiViewClassName : 'RCTView' ,
121
+ } ) ) ;
122
+
123
+ let ref = React . createRef ( ) ;
124
+
125
+ class Component extends React . Component {
126
+ render ( ) {
127
+ return < View title = "foo" /> ;
128
+ }
129
+ }
130
+
131
+ ReactNative . render ( < Component ref = { ref } /> , 11 ) ;
132
+
133
+ let instance = ReactFabric . findHostInstance_DEPRECATED ( ref . current ) ;
134
+ expect ( instance . _nativeTag ) . toBe ( 3 ) ;
135
+ } ) ;
136
+
137
+ it ( 'find Paper nodes with the Fabric renderer' , ( ) => {
138
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
139
+ validAttributes : { title : true } ,
140
+ uiViewClassName : 'RCTView' ,
141
+ } ) ) ;
142
+
143
+ let ref = React . createRef ( ) ;
144
+
145
+ class Component extends React . Component {
146
+ render ( ) {
147
+ return < View title = "foo" /> ;
148
+ }
149
+ }
150
+
151
+ ReactNative . render ( < Component ref = { ref } /> , 11 ) ;
152
+
153
+ let handle = ReactFabric . findNodeHandle ( ref . current ) ;
154
+ expect ( handle ) . toBe ( 3 ) ;
155
+ } ) ;
156
+
157
+ it ( 'dispatches commands on Paper nodes with the Fabric renderer' , ( ) => {
158
+ UIManager . dispatchViewManagerCommand . mockReset ( ) ;
159
+ const View = createReactNativeComponentClass ( 'RCTView' , ( ) => ( {
160
+ validAttributes : { title : true } ,
161
+ uiViewClassName : 'RCTView' ,
162
+ } ) ) ;
163
+
164
+ let ref = React . createRef ( ) ;
165
+
166
+ ReactNative . render ( < View title = "bar" ref = { ref } /> , 11 ) ;
167
+ expect ( UIManager . dispatchViewManagerCommand ) . not . toBeCalled ( ) ;
168
+ ReactFabric . dispatchCommand ( ref . current , 'myCommand' , [ 10 , 20 ] ) ;
89
169
expect ( UIManager . dispatchViewManagerCommand ) . toHaveBeenCalledTimes ( 1 ) ;
90
170
expect ( UIManager . dispatchViewManagerCommand ) . toHaveBeenCalledWith (
91
171
expect . any ( Number ) ,
92
172
'myCommand' ,
93
173
[ 10 , 20 ] ,
94
174
) ;
175
+
176
+ expect ( nativeFabricUIManager . dispatchCommand ) . not . toBeCalled ( ) ;
95
177
} ) ;
96
178
} ) ;
0 commit comments