From 6d4fcbf5d4a28a156ce5ef01cf65d6efdd86b3b9 Mon Sep 17 00:00:00 2001 From: Laura Macaluso Date: Thu, 5 Mar 2026 07:02:49 -0800 Subject: [PATCH] Add missing Fantom integration test coverage for TouchableHighlight (#55928) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55928 Changelog: [Internal] Add tests for previously untested TouchableHighlight-specific features in the Fantom integration test suite: - **underlayColor**: Verify default underlay color ('black') and custom underlay color ('red') render correctly when pressed, using `testOnly_pressed={true}` to force the pressed visual state. - **activeOpacity (pressed state)**: Verify default activeOpacity (0.85) and custom activeOpacity (0.5) are applied to the child element's opacity when pressed. - **onShowUnderlay**: Verify the callback fires when the element is clicked, via `Fantom.dispatchNativeEvent`. - **displayName**: Verify `TouchableHighlight.displayName` is `'TouchableHighlight'`. These tests cover the underlay mechanism, which is the defining feature of TouchableHighlight that distinguishes it from TouchableOpacity. Reviewed By: NickGerleman Differential Revision: D95225416 fbshipit-source-id: d1923c27d1ec9536d6b1e4ae41ba750212f27bc6 --- .../__tests__/TouchableHighlight-itest.js | 195 ++++++++++++++++++ 1 file changed, 195 insertions(+) diff --git a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableHighlight-itest.js b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableHighlight-itest.js index 5073c21afe5..776ec964a4e 100644 --- a/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableHighlight-itest.js +++ b/packages/react-native/Libraries/Components/Touchable/__tests__/TouchableHighlight-itest.js @@ -116,6 +116,84 @@ describe('', () => { , ); }); + + it('applies default activeOpacity (0.85) to child when pressed', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + + + , + ); + }); + + it('applies custom activeOpacity to child when pressed', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect(root.getRenderedOutput({props: ['opacity']}).toJSX()).toEqual( + + + , + ); + }); + }); + + describe('underlayColor', () => { + it('renders default underlay color (black) when pressed', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['backgroundColor']}).toJSX(), + ).toEqual( + + + , + ); + }); + + it('renders custom underlay color when pressed', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['backgroundColor']}).toJSX(), + ).toEqual( + + + , + ); + }); }); describe('onPress', () => { @@ -143,6 +221,32 @@ describe('', () => { }); }); + describe('onShowUnderlay', () => { + it('triggers onShowUnderlay callback when pressed', () => { + const elementRef = createRef(); + const onShowUnderlayCallback = jest.fn(); + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + {}} + onShowUnderlay={onShowUnderlayCallback} + style={{height: 100}}> + + , + ); + }); + + const element = ensureInstance(elementRef.current, ReactNativeElement); + Fantom.dispatchNativeEvent(element, 'click'); + + expect(onShowUnderlayCallback).toHaveBeenCalledTimes(1); + }); + }); + describe('disabled', () => { it('cannot be pressed when disabled', () => { const elementRef = createRef(); @@ -184,6 +288,93 @@ describe('', () => { , ); }); + + it('sets accessibilityState disabled when accessibilityState is empty', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), + ).toEqual( + , + ); + }); + + it('preserves accessibilityState values when disabled is true', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), + ).toEqual( + , + ); + }); + + it('overwrites accessibilityState disabled with disabled prop', () => { + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), + ).toEqual( + , + ); + }); + + it('disables when only accessibilityState disabled is set', () => { + const elementRef = createRef(); + const onPressCallback = jest.fn(); + + const root = Fantom.createRoot(); + + Fantom.runTask(() => { + root.render( + + + , + ); + }); + + expect( + root.getRenderedOutput({props: ['accessibilityState']}).toJSX(), + ).toEqual( + , + ); + + const element = ensureInstance(elementRef.current, ReactNativeElement); + Fantom.dispatchNativeEvent(element, 'click'); + + expect(onPressCallback).toHaveBeenCalledTimes(0); + }); }); describe('children', () => { @@ -243,4 +434,8 @@ describe('', () => { }); }); }); + + it('has the correct displayName', () => { + expect(TouchableHighlight.displayName).toBe('TouchableHighlight'); + }); });