Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add E2E tests for Pressable component #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions RNTester/e2e/__tests__/Pressable-test.js
Original file line number Diff line number Diff line change
@@ -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(
'<Pressable>',
'<Pressable> 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('<Text onPress={fn}> 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');
});
});
6 changes: 4 additions & 2 deletions RNTester/js/examples/Pressable/PressableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ function PressableHitSlop() {

return (
<View testID="pressable_hit_slop">
<View style={[styles.row, styles.centered]}>
<View
testID="pressable_hit_slop_extended_touch"
style={[styles.row, styles.centered]}>
<Pressable
onPress={() => setTimesPressed(num => num + 1)}
style={styles.hitSlopWrapper}
Expand All @@ -198,7 +200,7 @@ function PressableHitSlop() {
</Pressable>
</View>
<View style={styles.logBox}>
<Text>{log}</Text>
<Text testID="pressable_hit_slop_console">{log}</Text>
</View>
</View>
);
Expand Down