From e018da5129d43ca9f581ce4fbe479d669d71536b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Parkitny?= Date: Thu, 21 Jan 2021 09:58:04 +0100 Subject: [PATCH 1/6] test: add pointerEvents test --- src/__tests__/fireEvent.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js index a8f1ac43d..aee2532b6 100644 --- a/src/__tests__/fireEvent.test.js +++ b/src/__tests__/fireEvent.test.js @@ -234,6 +234,21 @@ test('should not fire on non-editable TextInput with nested Text', () => { expect(onChangeTextMock).not.toHaveBeenCalled(); }); +test.only('should not fire on non-targetable View', () => { + const handlePress = jest.fn(); + + const screen = render( + + + Trigger + + + ); + + fireEvent.press(screen.getByText('Trigger')); + expect(handlePress).not.toHaveBeenCalled(); +}); + test('should pass event up on disabled TouchableOpacity', () => { const handleInnerPress = jest.fn(); const handleOuterPress = jest.fn(); From 04125cc761765863fc418a6e093dffe744447263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Parkitny?= Date: Thu, 21 Jan 2021 12:07:49 +0100 Subject: [PATCH 2/6] feat: add pointerEvents handling --- src/fireEvent.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fireEvent.js b/src/fireEvent.js index dcc49d81c..5c9d8d619 100644 --- a/src/fireEvent.js +++ b/src/fireEvent.js @@ -17,11 +17,25 @@ const isTouchResponder = (element?: ReactTestInstance) => { return !!element?.props.onStartShouldSetResponder || isTextInput(element); }; +const isPointerEventEnabled = (element?: ReactTestInstance) => { + if ( + element?.props.pointerEvents === 'none' || + element?.props.pointerEvents === 'box-only' + ) { + return false; + } + + if (!element?.parent) return true; + + return isPointerEventEnabled(element.parent); +}; + const isEventEnabled = ( element?: ReactTestInstance, touchResponder?: ReactTestInstance ) => { if (isTextInput(element)) return element?.props.editable !== false; + if (!isPointerEventEnabled(element)) return false; const touchStart = touchResponder?.props.onStartShouldSetResponder?.(); const touchMove = touchResponder?.props.onMoveShouldSetResponder?.(); From 076b8a5f3046bb28f55f91a66461cfec6e9ad1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Parkitny?= Date: Thu, 21 Jan 2021 12:08:08 +0100 Subject: [PATCH 3/6] test: add test for nested views --- src/__tests__/fireEvent.test.js | 34 ++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js index aee2532b6..19faa09a8 100644 --- a/src/__tests__/fireEvent.test.js +++ b/src/__tests__/fireEvent.test.js @@ -234,7 +234,7 @@ test('should not fire on non-editable TextInput with nested Text', () => { expect(onChangeTextMock).not.toHaveBeenCalled(); }); -test.only('should not fire on non-targetable View', () => { +test('should not fire on none pointerEvents View', () => { const handlePress = jest.fn(); const screen = render( @@ -249,6 +249,38 @@ test.only('should not fire on non-targetable View', () => { expect(handlePress).not.toHaveBeenCalled(); }); +test('should not fire on box-only pointerEvents View', () => { + const handlePress = jest.fn(); + + const screen = render( + + + Trigger + + + ); + + fireEvent.press(screen.getByText('Trigger')); + expect(handlePress).not.toHaveBeenCalled(); +}); + +test('should not fire on none pointerEvents View with nested elements', () => { + const handlePress = jest.fn(); + + const screen = render( + + + + Trigger + + + + ); + + fireEvent.press(screen.getByText('Trigger')); + expect(handlePress).not.toHaveBeenCalled(); +}); + test('should pass event up on disabled TouchableOpacity', () => { const handleInnerPress = jest.fn(); const handleOuterPress = jest.fn(); From 1181dc8b43c584cb626a09b7e32eb368dbcd9253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Parkitny?= Date: Thu, 21 Jan 2021 14:43:12 +0100 Subject: [PATCH 4/6] feat: add pointerEvents box-none handling --- src/__tests__/fireEvent.test.js | 15 +++++++++++++++ src/fireEvent.js | 16 ++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js index 19faa09a8..69bd534a0 100644 --- a/src/__tests__/fireEvent.test.js +++ b/src/__tests__/fireEvent.test.js @@ -264,6 +264,21 @@ test('should not fire on box-only pointerEvents View', () => { expect(handlePress).not.toHaveBeenCalled(); }); +test('should fire on box-none pointerEvents View', () => { + const handlePress = jest.fn(); + + const screen = render( + + + Trigger + + + ); + + fireEvent.press(screen.getByText('Trigger')); + expect(handlePress).toHaveBeenCalled(); +}); + test('should not fire on none pointerEvents View with nested elements', () => { const handlePress = jest.fn(); diff --git a/src/fireEvent.js b/src/fireEvent.js index 5c9d8d619..18c938e7d 100644 --- a/src/fireEvent.js +++ b/src/fireEvent.js @@ -17,17 +17,21 @@ const isTouchResponder = (element?: ReactTestInstance) => { return !!element?.props.onStartShouldSetResponder || isTextInput(element); }; -const isPointerEventEnabled = (element?: ReactTestInstance) => { - if ( - element?.props.pointerEvents === 'none' || - element?.props.pointerEvents === 'box-only' - ) { +const isPointerEventEnabled = ( + element?: ReactTestInstance, + isParent?: boolean +) => { + const parentCondition = isParent + ? element?.props.pointerEvents === 'box-only' + : element?.props.pointerEvents === 'box-none'; + + if (element?.props.pointerEvents === 'none' || parentCondition) { return false; } if (!element?.parent) return true; - return isPointerEventEnabled(element.parent); + return isPointerEventEnabled(element.parent, true); }; const isEventEnabled = ( From d59b37036bd336031884a9cdba392cdd636a9eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Parkitny?= Date: Mon, 25 Jan 2021 17:14:08 +0100 Subject: [PATCH 5/6] test: handle auto pointerEvents --- src/__tests__/fireEvent.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js index 69bd534a0..d29dd1281 100644 --- a/src/__tests__/fireEvent.test.js +++ b/src/__tests__/fireEvent.test.js @@ -279,6 +279,21 @@ test('should fire on box-none pointerEvents View', () => { expect(handlePress).toHaveBeenCalled(); }); +test('should fire on auto pointerEvents View', () => { + const handlePress = jest.fn(); + + const screen = render( + + + Trigger + + + ); + + fireEvent.press(screen.getByText('Trigger')); + expect(handlePress).toHaveBeenCalled(); +}); + test('should not fire on none pointerEvents View with nested elements', () => { const handlePress = jest.fn(); From 306e24b093e42489f6d0465cca3faf2fbe124172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Tue, 26 Jan 2021 11:50:10 +0100 Subject: [PATCH 6/6] Update src/__tests__/fireEvent.test.js --- src/__tests__/fireEvent.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/fireEvent.test.js b/src/__tests__/fireEvent.test.js index d29dd1281..90cb60e06 100644 --- a/src/__tests__/fireEvent.test.js +++ b/src/__tests__/fireEvent.test.js @@ -294,7 +294,7 @@ test('should fire on auto pointerEvents View', () => { expect(handlePress).toHaveBeenCalled(); }); -test('should not fire on none pointerEvents View with nested elements', () => { +test('should not fire on box-only pointerEvents View with nested elements', () => { const handlePress = jest.fn(); const screen = render(