From 173bc6848694a017ae6e041079d3681c3d891de2 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 1/6] Create e2e test for Text.ellipsizeMode prop (#53163) Summary: # Changelog: [Internal] - Adds a Fantom test that tests the `Text.ellipsizeMode` prop. It also adds a test for the `` component without any props Reviewed By: andrewdacenko 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 e01037518c6916079a143904b312ec61d98a9dc8 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 2/6] Prop test for Text.allowFontScaling Summary: # Changelog: [Internal] - Adds Fantom test for `Text.allowFontScaling`. Reviewed By: andrewdacenko 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 83df1d4f987780543d9d0cb469f42c47245078ab Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 3/6] E2E test for numberOfLines prop in Text (#53167) Summary: # Changelog [Internal] - As in the title. Reviewed By: andrewdacenko 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 ce1755aad59d3b4eb232113ae78bdc8e658df1a6 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 4/6] Add Fantom test for Text.selectable (#53168) Summary: # Changelog: [Internal]- Adds Fantom test for `Text.selectable` prop. Reviewed By: andrewdacenko 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 2313de64ac4a040128a5a78ceffa1d27205258c9 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 5/6] e2e test for Text.id/nativeID (#53170) Summary: # 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; From e165d87d488d64977b1580a94e58abea6b637bd0 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 8 Aug 2025 06:31:02 -0700 Subject: [PATCH 6/6] Add test for Text.maxFontSizeMultiplier Summary: # Changelog: [Internal] - As in the title. Differential Revision: D79888839 --- .../Libraries/Text/__tests__/Text-itest.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/react-native/Libraries/Text/__tests__/Text-itest.js b/packages/react-native/Libraries/Text/__tests__/Text-itest.js index e5c96606216f..c640d35a7a2c 100644 --- a/packages/react-native/Libraries/Text/__tests__/Text-itest.js +++ b/packages/react-native/Libraries/Text/__tests__/Text-itest.js @@ -165,6 +165,26 @@ describe('', () => { }); }); + describe('maxFontSizeMultiplier', () => { + it(`propagates valid numbers correctly`, () => { + const root = Fantom.createRoot(); + + [-1, 0, 1, 3, 1000].forEach(val => { + Fantom.runTask(() => { + root.render({TEST_TEXT}); + }); + + expect( + root.getRenderedOutput({props: ['maxFontSizeMultiplier']}).toJSX(), + ).toEqual( + + {TEST_TEXT} + , + ); + }); + }); + }); + describe('numberOfLines', () => { let originalConsoleError = null;