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'); + }); });