@samitouri / QOS-React / commits / 8416ebee38

Update ReactFabric-test.internal to concurrent root (#30103)

Jan Kassens committed Jun 26, 2024 at 16:04 UTC 8416ebee38b1712611d8987ba64ce8fd87c3a540
1 file changed +103 -27
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
+103 -27
@@ -29,9 +29,6 @@ describe('ReactFabric', () => {
29 beforeEach(() => {
30 jest.resetModules();
31
32 - // TODO: migrate these tests off of the legacy API
33 - require('shared/ReactFeatureFlags').disableLegacyMode = false;
34 -
32 require('react-native/Libraries/ReactPrivate/InitializeNativeFabricUIManager');
33
34 React = require('react');
@@ -51,7 +48,7 @@ describe('ReactFabric', () => {
48 }));
49
50 await act(() => {
54 - ReactFabric.render(<View foo="test" />, 1);
51 + ReactFabric.render(<View foo="test" />, 1, null, true);
52 });
53 expect(nativeFabricUIManager.createNode).toBeCalled();
54 expect(nativeFabricUIManager.appendChild).not.toBeCalled();
@@ -69,13 +66,13 @@ describe('ReactFabric', () => {
66 nativeFabricUIManager.createNode.mockReturnValue(firstNode);
67
68 await act(() => {
72 - ReactFabric.render(<View foo="foo" />, 11);
69 + ReactFabric.render(<View foo="foo" />, 11, null, true);
70 });
71
72 expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
73
74 await act(() => {
78 - ReactFabric.render(<View foo="bar" />, 11);
75 + ReactFabric.render(<View foo="bar" />, 11, null, true);
76 });
77
78 expect(nativeFabricUIManager.createNode).toHaveBeenCalledTimes(1);
@@ -99,7 +96,7 @@ describe('ReactFabric', () => {
96 }));
97
98 await act(() => {
102 - ReactFabric.render(<Text foo="a">1</Text>, 11);
99 + ReactFabric.render(<Text foo="a">1</Text>, 11, null, true);
100 });
101 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
102 expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
@@ -110,7 +107,7 @@ describe('ReactFabric', () => {
107
108 // If no properties have changed, we shouldn't call cloneNode.
109 await act(() => {
113 - ReactFabric.render(<Text foo="a">1</Text>, 11);
110 + ReactFabric.render(<Text foo="a">1</Text>, 11, null, true);
111 });
112 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
113 expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
@@ -121,7 +118,7 @@ describe('ReactFabric', () => {
118
119 // Only call cloneNode for the changed property (and not for text).
120 await act(() => {
124 - ReactFabric.render(<Text foo="b">1</Text>, 11);
121 + ReactFabric.render(<Text foo="b">1</Text>, 11, null, true);
122 });
123 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
124 expect(nativeFabricUIManager.cloneNodeWithNewChildren).not.toBeCalled();
@@ -134,7 +131,7 @@ describe('ReactFabric', () => {
131
132 // Only call cloneNode for the changed text (and no other properties).
133 await act(() => {
137 - ReactFabric.render(<Text foo="b">2</Text>, 11);
134 + ReactFabric.render(<Text foo="b">2</Text>, 11, null, true);
135 });
136 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
137 expect(
@@ -149,7 +146,7 @@ describe('ReactFabric', () => {
146
147 // Call cloneNode for both changed text and properties.
148 await act(() => {
152 - ReactFabric.render(<Text foo="c">3</Text>, 11);
149 + ReactFabric.render(<Text foo="c">3</Text>, 11, null, true);
150 });
151 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
152 expect(
@@ -175,6 +172,8 @@ describe('ReactFabric', () => {
172 1
173 </Text>,
174 11,
175 + null,
176 + true,
177 );
178 });
179 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
@@ -190,6 +189,8 @@ describe('ReactFabric', () => {
189 1
190 </Text>,
191 11,
192 + null,
193 + true,
194 );
195 });
196 expect(
@@ -207,6 +208,8 @@ describe('ReactFabric', () => {
208 2
209 </Text>,
210 11,
211 + null,
212 + true,
213 );
214 });
215 const argIndex = gate(flags => flags.passChildrenWhenCloningPersistedNodes)
@@ -236,11 +239,15 @@ describe('ReactFabric', () => {
239 </View>
240 );
241
239 - await act(() => ReactFabric.render(<Component foo={true} />, 11));
242 + await act(() =>
243 + ReactFabric.render(<Component foo={true} />, 11, null, true),
244 + );
245 expect(nativeFabricUIManager.completeRoot).toBeCalled();
246 jest.clearAllMocks();
247
243 - await act(() => ReactFabric.render(<Component foo={false} />, 11));
248 + await act(() =>
249 + ReactFabric.render(<Component foo={false} />, 11, null, true),
250 + );
251 expect(nativeFabricUIManager.cloneNode).not.toBeCalled();
252 expect(nativeFabricUIManager.cloneNodeWithNewProps).toHaveBeenCalledTimes(
253 1,
@@ -289,6 +296,8 @@ describe('ReactFabric', () => {
296 }}
297 />,
298 11,
299 + null,
300 + true,
301 );
302 });
303
@@ -320,6 +329,8 @@ describe('ReactFabric', () => {
329 }}
330 />,
331 11,
332 + null,
333 + true,
334 );
335 });
336
@@ -350,6 +361,8 @@ describe('ReactFabric', () => {
361 }}
362 />,
363 11,
364 + null,
365 + true,
366 );
367 });
368
@@ -382,6 +395,8 @@ describe('ReactFabric', () => {
395 }}
396 />,
397 11,
398 + null,
399 + true,
400 );
401 });
402
@@ -395,7 +410,33 @@ describe('ReactFabric', () => {
410 expect(nativeFabricUIManager.sendAccessibilityEvent).not.toBeCalled();
411 });
412
398 - it('returns the correct instance and calls it in the callback', () => {
413 + it('calls the callback with the correct instance and returns null', async () => {
414 + const View = createReactNativeComponentClass('RCTView', () => ({
415 + validAttributes: {foo: true},
416 + uiViewClassName: 'RCTView',
417 + }));
418 +
419 + let a;
420 + let b;
421 + let c;
422 + await act(() => {
423 + c = ReactFabric.render(
424 + <View foo="foo" ref={v => (a = v)} />,
425 + 11,
426 + function () {
427 + b = this;
428 + },
429 + true,
430 + );
431 + });
432 +
433 + expect(a).toBeTruthy();
434 + expect(a).toBe(b);
435 + expect(c).toBe(null);
436 + });
437 +
438 + // @gate !disableLegacyMode
439 + it('returns the instance in legacy mode and calls the callback with it', () => {
440 const View = createReactNativeComponentClass('RCTView', () => ({
441 validAttributes: {foo: true},
442 uiViewClassName: 'RCTView',
@@ -404,7 +445,12 @@ describe('ReactFabric', () => {
445 let a;
446 let b;
447 const c = ReactFabric.render(
407 - <View foo="foo" ref={v => (a = v)} />,
448 + <View
449 + foo="foo"
450 + ref={v => {
451 + a = v;
452 + }}
453 + />,
454 11,
455 function () {
456 b = this;
@@ -440,7 +486,7 @@ describe('ReactFabric', () => {
486 const after = 'mxhpgwfralkeoivcstzy';
487
488 await act(() => {
443 - ReactFabric.render(<Component chars={before} />, 11);
489 + ReactFabric.render(<Component chars={before} />, 11, null, true);
490 });
491 expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
492 RCTView null
@@ -466,7 +512,7 @@ describe('ReactFabric', () => {
512 RCTView {"title":"t"}`);
513
514 await act(() => {
469 - ReactFabric.render(<Component chars={after} />, 11);
515 + ReactFabric.render(<Component chars={after} />, 11, null, true);
516 });
517 expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
518 RCTView null
@@ -525,6 +571,8 @@ describe('ReactFabric', () => {
571 <Component ref={ref} />
572 </View>,
573 11,
574 + null,
575 + true,
576 );
577 });
578 expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(
@@ -555,8 +603,10 @@ describe('ReactFabric', () => {
603
604 // Call setState() so that we skip over the top-level host node.
605 // It should still get recreated despite a bailout.
558 - ref.current.setState({
559 - chars: after,
606 + await act(() => {
607 + ref.current.setState({
608 + chars: after,
609 + });
610 });
611 expect(nativeFabricUIManager.__dumpHierarchyForJestTestsOnly()).toBe(`11
612 RCTView null
@@ -595,7 +645,7 @@ describe('ReactFabric', () => {
645 }
646
647 await act(() => {
598 - ReactFabric.render(<Component />, 11);
648 + ReactFabric.render(<Component />, 11, null, true);
649 });
650 expect(mockArgs.length).toEqual(0);
651 });
@@ -621,6 +671,8 @@ describe('ReactFabric', () => {
671 <View foo="b" />
672 </View>,
673 22,
674 + null,
675 + true,
676 );
677 });
678 expect(snapshots).toEqual([
@@ -649,6 +701,8 @@ describe('ReactFabric', () => {
701 <View />
702 </Text>,
703 11,
704 + null,
705 + true,
706 );
707 });
708
@@ -658,6 +712,8 @@ describe('ReactFabric', () => {
712 <Image />
713 </Text>,
714 11,
715 + null,
716 + true,
717 );
718 });
719 });
@@ -678,7 +734,7 @@ describe('ReactFabric', () => {
734
735 await expect(async () => {
736 await act(() => {
681 - ReactFabric.render(<View>this should warn</View>, 11);
737 + ReactFabric.render(<View>this should warn</View>, 11, null, true);
738 });
739 }).toErrorDev(['Text strings must be rendered within a <Text> component.']);
740
@@ -689,6 +745,8 @@ describe('ReactFabric', () => {
745 <ScrollView>hi hello hi</ScrollView>
746 </Text>,
747 11,
748 + null,
749 + true,
750 );
751 });
752 }).toErrorDev(['Text strings must be rendered within a <Text> component.']);
@@ -708,6 +766,8 @@ describe('ReactFabric', () => {
766 <Indirection />
767 </Text>,
768 11,
769 + null,
770 + true,
771 );
772 });
773 });
@@ -727,7 +787,7 @@ describe('ReactFabric', () => {
787 const touchStart2 = jest.fn();
788
789 await act(() => {
730 - ReactFabric.render(<View onTouchStart={touchStart} />, 11);
790 + ReactFabric.render(<View onTouchStart={touchStart} />, 11, null, true);
791 });
792
793 expect(nativeFabricUIManager.createNode.mock.calls.length).toBe(1);
@@ -753,7 +813,7 @@ describe('ReactFabric', () => {
813 expect(touchStart2).not.toBeCalled();
814
815 await act(() => {
756 - ReactFabric.render(<View onTouchStart={touchStart2} />, 11);
816 + ReactFabric.render(<View onTouchStart={touchStart2} />, 11, null, true);
817 });
818
819 // Intentionally dispatch to the same instanceHandle again.
@@ -819,6 +879,8 @@ describe('ReactFabric', () => {
879 />
880 </View>,
881 11,
882 + null,
883 + true,
884 );
885 });
886
@@ -914,6 +976,8 @@ describe('ReactFabric', () => {
976 />
977 </View>,
978 1,
979 + null,
980 + true,
981 );
982 });
983
@@ -973,6 +1037,8 @@ describe('ReactFabric', () => {
1037 ReactFabric.render(
1038 <ContainsStrictModeChild ref={n => (parent = n)} />,
1039 11,
1040 + null,
1041 + true,
1042 );
1043 });
1044
@@ -1012,6 +1078,8 @@ describe('ReactFabric', () => {
1078 <IsInStrictMode ref={n => (parent = n)} />
1079 </StrictMode>,
1080 11,
1081 + null,
1082 + true,
1083 );
1084 });
1085
@@ -1053,6 +1121,8 @@ describe('ReactFabric', () => {
1121 ReactFabric.render(
1122 <ContainsStrictModeChild ref={n => (parent = n)} />,
1123 11,
1124 + null,
1125 + true,
1126 );
1127 });
1128
@@ -1092,6 +1162,8 @@ describe('ReactFabric', () => {
1162 <IsInStrictMode ref={n => (parent = n)} />
1163 </StrictMode>,
1164 11,
1165 + null,
1166 + true,
1167 );
1168 });
1169
@@ -1127,6 +1199,8 @@ describe('ReactFabric', () => {
1199 }}
1200 />,
1201 11,
1202 + null,
1203 + true,
1204 );
1205 });
1206 const dangerouslyRetainedViewRef = viewRef;
@@ -1149,7 +1223,7 @@ describe('ReactFabric', () => {
1223 }));
1224
1225 await act(() => {
1152 - ReactFabric.render(<View foo="test" />, 1);
1226 + ReactFabric.render(<View foo="test" />, 1, null, true);
1227 });
1228
1229 const internalInstanceHandle =
@@ -1182,6 +1256,8 @@ describe('ReactFabric', () => {
1256 }}
1257 />,
1258 1,
1259 + null,
1260 + true,
1261 );
1262 });
1263
@@ -1196,7 +1272,7 @@ describe('ReactFabric', () => {
1272 expect(publicInstance).toBe(viewRef);
1273
1274 await act(() => {
1199 - ReactFabric.render(null, 1);
1275 + ReactFabric.render(null, 1, null, true);
1276 });
1277
1278 const publicInstanceAfterUnmount =
@@ -1215,7 +1291,7 @@ describe('ReactFabric', () => {
1291 }));
1292
1293 await act(() => {
1218 - ReactFabric.render(<RCTText>Text content</RCTText>, 1);
1294 + ReactFabric.render(<RCTText>Text content</RCTText>, 1, null, true);
1295 });
1296
1297 // Access the internal instance handle used to create the text node.
@@ -1247,7 +1323,7 @@ describe('ReactFabric', () => {
1323 expect(publicInstance).toBe(expectedPublicInstance);
1324
1325 await act(() => {
1250 - ReactFabric.render(null, 1);
1326 + ReactFabric.render(null, 1, null, true);
1327 });
1328
1329 const publicInstanceAfterUnmount =