diff --git a/RNTester/e2e/__tests__/Pressable-test.js b/RNTester/e2e/__tests__/Pressable-test.js new file mode 100644 index 00000000000000..a6e82d070774fb --- /dev/null +++ b/RNTester/e2e/__tests__/Pressable-test.js @@ -0,0 +1,66 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @emails oncall+react_native + * @format + */ + +/* global device, element, by, expect */ +const { + openComponentWithLabel, + openExampleWithTitle, +} = require('../e2e-helpers'); + +describe('Pressable', () => { + beforeAll(async () => { + await device.reloadReactNative(); + await openComponentWithLabel( + '', + ' Component for making views pressable.', + ); + }); + + it('should change console content on press', async () => { + await openExampleWithTitle('Change content based on Press'); + + const consoleID = 'pressable_press_console'; + + await element(by.text('Press Me')).tap(); + await expect(element(by.id(consoleID))).toHaveText('onPress'); + + await element(by.text('Press Me')).tap(); + await expect(element(by.id(consoleID))).toHaveText('2x onPress'); + + await element(by.text('Press Me')).tap(); + await expect(element(by.id(consoleID))).toHaveText('3x onPress'); + }); + + it('should show different text on highlight button press', async () => { + await openExampleWithTitle(' with highlight'); + + const buttonID = 'tappable_text'; + const consoleID = 'tappable_text_console'; + + await element(by.id(buttonID)).tap(); + await expect(element(by.id(consoleID))).toHaveText('text onPress'); + + await element(by.id(buttonID)).tap(); + await expect(element(by.id(consoleID))).toHaveText('2x text onPress'); + }); + + it('should change text when hitSlop prop extends touch area', async () => { + await openExampleWithTitle('Pressable Hit Slop'); + + const buttonID = 'pressable_hit_slop_extended_touch'; + const consoleID = 'pressable_hit_slop_console'; + + await element(by.id(buttonID)).tap(); + await expect(element(by.id(consoleID))).toHaveText('onPress'); + + await element(by.id(buttonID)).tap(); + await expect(element(by.id(consoleID))).toHaveText('2x onPress'); + }); +}); diff --git a/RNTester/js/examples/Pressable/PressableExample.js b/RNTester/js/examples/Pressable/PressableExample.js index 9a67af10f6c4ed..7e53ed3b0d87dd 100644 --- a/RNTester/js/examples/Pressable/PressableExample.js +++ b/RNTester/js/examples/Pressable/PressableExample.js @@ -188,7 +188,9 @@ function PressableHitSlop() { return ( - + setTimesPressed(num => num + 1)} style={styles.hitSlopWrapper} @@ -198,7 +200,7 @@ function PressableHitSlop() { - {log} + {log} );