From 3daeba874c6d5661de2e87f5edea3b9322534a72 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 04:24:13 -0700 Subject: [PATCH 1/5] Create e2e test for Text.ellipsizeMode prop Differential Revision: D79882336 --- .../Libraries/Text/__tests__/Text-itest.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index c16ff81ade1a..e5d46240c74f 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -21,8 +21,75 @@ import {Text} from 'react-native'; import ReactNativeElement from 'react-native/src/private/webapis/dom/nodes/ReactNativeElement'; import ReadOnlyText from 'react-native/src/private/webapis/dom/nodes/ReadOnlyText'; +const TEST_TEXT = 'the text'; + describe('', () => { describe('props', () => { + describe('empty props', () => { + it('renders an empty element when there are no props', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput().toJSX()).toEqual( + + {TEST_TEXT} + , + ); + }); + }); + + describe('ellipsizeMode', () => { + it(`has 'tail' as default on JS side`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['ellipsizeMode']}).toJSX(), + ).toEqual( + {TEST_TEXT}, + ); + }); + + it(`has 'clip' as default on C++ side`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['ellipsizeMode']}).toJSX(), + ).toEqual({TEST_TEXT}); + }); + + (['head', 'middle', 'tail'] as const).forEach(propVal => { + it(`can be set to "${propVal}"`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['ellipsizeMode']}).toJSX(), + ).toEqual( + {TEST_TEXT}, + ); + }); + }); + }); + describe('style', () => { describe('writingDirection', () => { it('propagates to mounting layer', () => { From 1b69ecdeb28a74321be0814017084e6a1c8719e2 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 04:24:13 -0700 Subject: [PATCH 2/5] Prop test for Text.allowFontScaling Differential Revision: D79882955 --- .../Libraries/Text/__tests__/Text-itest.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index e5d46240c74f..f614c2340ece 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -46,6 +46,40 @@ describe('', () => { }); }); + describe('allowFontScaling', () => { + ([true, false] as const).forEach(propVal => { + it(`can be set to "${propVal.toString()}"`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['allowFontScaling']}).toJSX(), + ).toEqual( + + {TEST_TEXT} + , + ); + }); + }); + + it(`has 'true' as default`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['allowFontScaling']}).toJSX(), + ).toEqual( + {TEST_TEXT}, + ); + }); + }); + describe('ellipsizeMode', () => { it(`has 'tail' as default on JS side`, () => { const root = Fantom.createRoot(); From 2c9e1de2bcd69a7b5b5d6d4e1c2c5250cf702d02 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 05:53:33 -0700 Subject: [PATCH 3/5] E2E test for numberOfLines prop in Text Differential Revision: D79884649 --- .../Libraries/Text/__tests__/Text-itest.js | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index f614c2340ece..548146be4365 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -124,6 +124,65 @@ describe('', () => { }); }); + describe('numberOfLines', () => { + let originalConsoleError = null; + + afterEach(() => { + if (originalConsoleError != null) { + // $FlowExpectedError[cannot-write] + console.error = originalConsoleError; + originalConsoleError = null; + } + }); + + it(`doesn't allow negative numbers`, () => { + originalConsoleError = console.error; + // $FlowExpectedError[cannot-write] + console.error = jest.fn(); + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + // NB. "numberOfLines" is mapped to "maximumNumberOfLines" in C++ + root.getRenderedOutput({props: ['maximumNumberOfLines']}).toJSX(), + ).toEqual({TEST_TEXT}); + }); + + it(`has 0 as defult`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['maximumNumberOfLines']}).toJSX(), + ).toEqual({TEST_TEXT}); + }); + + it(`propagates valid numbers correctly`, () => { + const root = Fantom.createRoot(); + + [3, 1000].forEach(val => { + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['maximumNumberOfLines']}).toJSX(), + ).toEqual( + + {TEST_TEXT} + , + ); + }); + }); + }); + describe('style', () => { describe('writingDirection', () => { it('propagates to mounting layer', () => { From b5718a61e3d7aca137ab60a35e8d6a5904fd273e Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 05:53:33 -0700 Subject: [PATCH 4/5] Add Fantom test for Text.selectable Differential Revision: D79885301 --- .../Libraries/Text/__tests__/Text-itest.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index 548146be4365..924a86eb2505 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -183,6 +183,40 @@ describe('', () => { }); }); + describe('selectable', () => { + it(`can be set to "true"`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput({props: ['selectable']}).toJSX()).toEqual( + {TEST_TEXT}, + ); + }); + + it(`has 'false' as default`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput({props: ['selectable']}).toJSX()).toEqual( + {TEST_TEXT}, + ); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput({props: ['selectable']}).toJSX()).toEqual( + {TEST_TEXT}, + ); + }); + }); + describe('style', () => { describe('writingDirection', () => { it('propagates to mounting layer', () => { From 25c74f94eb9f91af627a9aecefc60d869244de14 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 05:59:18 -0700 Subject: [PATCH 5/5] e2e test for Text.id/nativeID (#53170) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53170 # Changelog: [Internal] - As in the title. Differential Revision: D79887689 --- .../Libraries/Text/__tests__/Text-itest.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index 924a86eb2505..e5c96606216f 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -124,6 +124,47 @@ describe('', () => { }); }); + describe('id and nativeID', () => { + it(`has 'id' propagated correctly`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual( + {TEST_TEXT}, + ); + }); + + it(`has 'nativeID' propagated correctly`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect(root.getRenderedOutput({props: ['nativeID']}).toJSX()).toEqual( + {TEST_TEXT}, + ); + }); + it(`has a precedence of 'id' over 'nativeID'`, () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + {TEST_TEXT} + , + ); + }); + + expect( + root.getRenderedOutput({props: ['id', 'nativeID']}).toJSX(), + ).toEqual({TEST_TEXT}); + }); + }); + describe('numberOfLines', () => { let originalConsoleError = null;