Skip to content

Commit 85a63e2

Browse files
rotemmizfacebook-github-bot
authored andcommitted
Initial Detox E2E iOS configuration to be run on RNTester (#20235)
Summary: This PR adds initial setup for Detox E2E iOS and some tests for ButtonExample. Pull Request resolved: facebook/react-native#20235 Reviewed By: hramos Differential Revision: D8924525 Pulled By: TheSavior fbshipit-source-id: 8117fc1559c2e9cb831f7b081aa8f4ddc8ba7401
1 parent 7e7d88c commit 85a63e2

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

e2e/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"setupTestFrameworkScriptFile" : "./init.js",
3+
"testEnvironment": "node",
4+
"bail": true,
5+
"verbose": true
6+
}

e2e/init.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const detox = require('detox');
9+
const config = require('../../package.json').detox;
10+
const adapter = require('detox/runners/jest/adapter');
11+
12+
jest.setTimeout(480000);
13+
jasmine.getEnv().addReporter(adapter);
14+
15+
beforeAll(async () => {
16+
await detox.init(config);
17+
});
18+
19+
beforeEach(async function() {
20+
await adapter.beforeEach();
21+
});
22+
23+
afterAll(async () => {
24+
await adapter.afterAll();
25+
await detox.cleanup();
26+
});
27+
28+
process.on('unhandledRejection', (reason, p) => {
29+
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
30+
});

e2e/sanity.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/* global device, element, by, expect */
9+
10+
describe('Sanity', () => {
11+
beforeEach(async () => {
12+
await device.reloadReactNative();
13+
await element(by.label(`<Button> Simple React Native button component.`)).tap();
14+
});
15+
16+
afterEach(async () => {
17+
//TODO - remove app state persistency, till then, we must go back to main screen,
18+
await element(by.label('Back')).tap();
19+
});
20+
21+
it('Simple button should be tappable', async () => {
22+
await element(by.label('Press Me')).tap();
23+
await expect(element(by.text('Simple has been pressed!'))).toBeVisible();
24+
await element(by.text('OK')).tap();
25+
});
26+
27+
it('Adjusted color button should be tappable', async () => {
28+
await element(by.label('Press Purple')).tap();
29+
await expect(element(by.text('Purple has been pressed!'))).toBeVisible();
30+
await element(by.text('OK')).tap();
31+
});
32+
33+
it(`Two buttons with JustifyContent:'space-between' should be tappable`, async () => {
34+
await element(by.label('This looks great!')).tap();
35+
await expect(element(by.text('Left has been pressed!'))).toBeVisible();
36+
await element(by.text('OK')).tap();
37+
38+
await element(by.label('Ok!')).tap();
39+
await expect(element(by.text('Right has been pressed!'))).toBeVisible();
40+
await element(by.text('OK')).tap();
41+
});
42+
43+
it('Disabled button should not interact', async () => {
44+
await element(by.label('I Am Disabled')).tap();
45+
await expect(element(by.text('Disabled has been pressed!'))).toBeNotVisible();
46+
});
47+
});

js/ButtonExample.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const React = require('react');
1414
const ReactNative = require('react-native');
1515
const {Alert, Button, View} = ReactNative;
1616

17-
const onButtonPress = () => {
18-
Alert.alert('Button has been pressed!');
19-
};
17+
function onButtonPress(buttonName) {
18+
Alert.alert(`${buttonName} has been pressed!`);
19+
}
2020

2121
exports.displayName = 'ButtonExample';
2222
exports.framework = 'React';
@@ -33,7 +33,7 @@ exports.examples = [
3333
render: function() {
3434
return (
3535
<Button
36-
onPress={onButtonPress}
36+
onPress={() => onButtonPress('Simple')}
3737
title="Press Me"
3838
accessibilityLabel="See an informative alert"
3939
/>
@@ -49,7 +49,7 @@ exports.examples = [
4949
render: function() {
5050
return (
5151
<Button
52-
onPress={onButtonPress}
52+
onPress={() => onButtonPress('Purple')}
5353
title="Press Purple"
5454
color="#841584"
5555
accessibilityLabel="Learn more about purple"
@@ -65,12 +65,12 @@ exports.examples = [
6565
return (
6666
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
6767
<Button
68-
onPress={onButtonPress}
68+
onPress={() => onButtonPress('Left')}
6969
title="This looks great!"
7070
accessibilityLabel="This sounds great!"
7171
/>
7272
<Button
73-
onPress={onButtonPress}
73+
onPress={() => onButtonPress('Right')}
7474
title="Ok!"
7575
color="#841584"
7676
accessibilityLabel="Ok, Great!"
@@ -86,7 +86,7 @@ exports.examples = [
8686
return (
8787
<Button
8888
disabled
89-
onPress={onButtonPress}
89+
onPress={() => onButtonPress('Disabled')}
9090
title="I Am Disabled"
9191
accessibilityLabel="See an informative alert"
9292
/>

0 commit comments

Comments
 (0)