From 81abd306bbcde3bea255c835271b4f0675f67d4c Mon Sep 17 00:00:00 2001 From: Zeya Peng Date: Wed, 13 Aug 2025 17:36:06 -0700 Subject: [PATCH] test FlatList props: data, renderItem, horizontal, inverted, scrollEnabled (#53186) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53186 ## Changelog: [Internal] [Changed] - test FlatList props: data, renderItem, horizontal, inverted, scrollEnabled uncovered one bug in `getDebugProps()` Reviewed By: rshest Differential Revision: D79895309 fbshipit-source-id: 0644cf9877620a7787ee085a8e934f462e5de3ef --- .../Lists/__tests__/FlatList-itest.js | 148 ++++++++++++++++++ .../scrollview/BaseScrollViewProps.cpp | 2 +- 2 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 packages/react-native/Libraries/Lists/__tests__/FlatList-itest.js diff --git a/packages/react-native/Libraries/Lists/__tests__/FlatList-itest.js b/packages/react-native/Libraries/Lists/__tests__/FlatList-itest.js new file mode 100644 index 00000000000..e24f8011639 --- /dev/null +++ b/packages/react-native/Libraries/Lists/__tests__/FlatList-itest.js @@ -0,0 +1,148 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; + +import * as Fantom from '@react-native/fantom'; +import * as React from 'react'; +import {FlatList, Text} from 'react-native'; + +describe('', () => { + describe('props', () => { + describe('data & renderItem', () => { + const root = Fantom.createRoot(); + it('List is rendered as expected', () => { + Fantom.runTask(() => { + root.render( + {item.title}} + />, + ); + }); + + expect( + JSON.stringify(root.getRenderedOutput({props: []}).toJSX()), + ).toEqual( + JSON.stringify( + + + Title Text + Title Text 2 + + , + ), + ); + }); + }); + + describe('inverted', () => { + it('changes prop isInvertedVirtualizedList which gets propagated to mounting layer', () => { + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render(); + }); + + expect( + root + .getRenderedOutput({ + props: ['inverted', 'isInvertedVirtualizedList'], + }) + .toJSX(), + ).toEqual( + + + , + ); + }); + + it('default value is false', () => { + const root = Fantom.createRoot(); + Fantom.runTask(() => { + root.render(); + }); + + expect( + root + .getRenderedOutput({ + props: ['inverted', 'isInvertedVirtualizedList'], + }) + .toJSX(), + ).toEqual( + + + , + ); + }); + }); + }); + + describe('props inherited from ScrollView', () => { + describe('horizontal', () => { + const root = Fantom.createRoot(); + it('is propagated to the mounting layer', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['horizontal']}).toJSX()).toEqual( + + + , + ); + }); + + it('default value is false', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect(root.getRenderedOutput({props: ['horizontal']}).toJSX()).toEqual( + + + , + ); + }); + }); + + describe('scrollEnabled', () => { + const root = Fantom.createRoot(); + it('default value is true', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['scrollEnabled']}).toJSX(), + ).toEqual( + + + , + ); + }); + it('is propagated to the mounting layer', () => { + Fantom.runTask(() => { + root.render(); + }); + + expect( + root.getRenderedOutput({props: ['scrollEnabled']}).toJSX(), + ).toEqual( + + + , + ); + }); + }); + }); +}); diff --git a/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp index a62c9f1bc99..a683cb87f82 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/scrollview/BaseScrollViewProps.cpp @@ -558,7 +558,7 @@ SharedDebugStringConvertibleList BaseScrollViewProps::getDebugProps() const { "snapToEnd", snapToEnd, defaultScrollViewProps.snapToEnd), debugStringConvertibleItem( "isInvertedVirtualizedList", - snapToEnd, + isInvertedVirtualizedList, defaultScrollViewProps.isInvertedVirtualizedList)}; } #endif