Skip to content

Commit 34ee825

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
Add filtering to e2e tests (facebook#22828)
Summary: This PR adds filtering for e2e test examples using the new examples filter introduced in facebook#22777 To do that we: - Add a `testID` to `RNTesterExampleFilter` to select an example - Refactor a few examples to export multiple examples for filtering - Update all tests to filter by example title Pull Request resolved: facebook#22828 Reviewed By: TheSavior Differential Revision: D13562664 Pulled By: rickhanlonii fbshipit-source-id: efb0ca8050c1ca5c10d96bd77d35dd1143c3a3b3
1 parent 9db0050 commit 34ee825

13 files changed

+481
-361
lines changed

RNTester/e2e/__tests__/Button-test.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,36 @@
99
*/
1010

1111
/* global device, element, by, expect */
12+
const {
13+
openComponentWithLabel,
14+
openExampleWithTitle,
15+
} = require('../e2e-helpers');
1216

1317
describe('Button', () => {
1418
beforeAll(async () => {
1519
await device.reloadReactNative();
16-
await element(by.id('explorer_search')).replaceText('<Button>');
17-
await element(
18-
by.label('<Button> Simple React Native button component.'),
19-
).tap();
20-
});
21-
22-
afterAll(async () => {
23-
//TODO - remove app state persistency, till then, we must go back to main screen,
24-
await element(by.label('Back')).tap();
20+
await openComponentWithLabel(
21+
'<Button>',
22+
'<Button> Simple React Native button component.',
23+
);
2524
});
2625

2726
it('Simple button should be tappable', async () => {
27+
await openExampleWithTitle('Simple Button');
2828
await element(by.id('simple_button')).tap();
2929
await expect(element(by.text('Simple has been pressed!'))).toBeVisible();
3030
await element(by.text('OK')).tap();
3131
});
3232

3333
it('Adjusted color button should be tappable', async () => {
34+
await openExampleWithTitle('Adjusted color');
3435
await element(by.id('purple_button')).tap();
3536
await expect(element(by.text('Purple has been pressed!'))).toBeVisible();
3637
await element(by.text('OK')).tap();
3738
});
3839

3940
it("Two buttons with JustifyContent:'space-between' should be tappable", async () => {
41+
await openExampleWithTitle('Fit to text layout');
4042
await element(by.id('left_button')).tap();
4143
await expect(element(by.text('Left has been pressed!'))).toBeVisible();
4244
await element(by.text('OK')).tap();
@@ -47,6 +49,7 @@ describe('Button', () => {
4749
});
4850

4951
it('Disabled button should not interact', async () => {
52+
await openExampleWithTitle('Disabled Button');
5053
await element(by.id('disabled_button')).tap();
5154
await expect(
5255
element(by.text('Disabled has been pressed!')),

RNTester/e2e/__tests__/DatePickerIOS-test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88
* @format
99
*/
1010

11-
/* global element, by, expect */
11+
/* global element, by, expect, device */
12+
13+
const {
14+
openComponentWithLabel,
15+
openExampleWithTitle,
16+
} = require('../e2e-helpers');
1217

1318
describe('DatePickerIOS', () => {
1419
beforeAll(async () => {
15-
await element(by.id('explorer_search')).replaceText('<DatePickerIOS>');
16-
await element(
17-
by.label(
18-
'<DatePickerIOS> Select dates and times using the native UIDatePicker.',
19-
),
20-
).tap();
21-
});
22-
23-
afterAll(async () => {
24-
await element(by.label('Back')).tap();
20+
await device.reloadReactNative();
21+
await openComponentWithLabel(
22+
'<DatePickerIOS>',
23+
'<DatePickerIOS> Select dates and times using the native UIDatePicker.',
24+
);
2525
});
2626

2727
it('Should change indicator with datetime picker', async () => {
28+
await openExampleWithTitle('Date and time picker');
2829
const testID = 'date-and-time';
2930
const indicatorID = 'date-and-time-indicator';
3031

@@ -45,6 +46,7 @@ describe('DatePickerIOS', () => {
4546
});
4647

4748
it('Should change indicator with date-only picker', async () => {
49+
await openExampleWithTitle('Date only');
4850
const testID = 'date-only';
4951
const indicatorID = 'date-and-time-indicator';
5052

RNTester/e2e/__tests__/Picker-test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
* @format
99
*/
1010

11-
/* global element, by, expect */
11+
/* global device, element, by, expect */
12+
const {
13+
openComponentWithLabel,
14+
openExampleWithTitle,
15+
} = require('../e2e-helpers');
1216

1317
describe('Picker', () => {
1418
beforeAll(async () => {
15-
await element(by.id('explorer_search')).replaceText('<Picker>');
16-
await element(
17-
by.label(
18-
'<Picker> Provides multiple options to choose from, using either a dropdown menu or a dialog.',
19-
),
20-
).tap();
21-
});
22-
23-
afterAll(async () => {
24-
await element(by.label('Back')).tap();
19+
await device.reloadReactNative();
20+
await openComponentWithLabel(
21+
'<Picker>',
22+
'<Picker> Provides multiple options to choose from, using either a dropdown menu or a dialog.',
23+
);
2524
});
2625

2726
it('should be selectable by ID', async () => {
27+
await openExampleWithTitle('Basic picker');
2828
await expect(element(by.id('basic-picker'))).toBeVisible();
2929
});
3030
});

RNTester/e2e/__tests__/Switch-test.js

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,71 +11,86 @@
1111
/* global device, element, by, expect */
1212

1313
const jestExpect = require('expect');
14+
const {
15+
openComponentWithLabel,
16+
openExampleWithTitle,
17+
} = require('../e2e-helpers');
1418

1519
describe('Switch', () => {
16-
beforeEach(async () => {
20+
beforeAll(async () => {
1721
await device.reloadReactNative();
18-
await element(by.id('explorer_search')).replaceText('<Switch>');
19-
await element(by.label('<Switch> Native boolean input')).tap();
22+
await openComponentWithLabel('<Switch>', '<Switch> Native boolean input');
2023
});
2124

22-
it('Switch that starts off should switch', async () => {
23-
const testID = 'on-off-initial-off';
24-
const indicatorID = 'on-off-initial-off-indicator';
25+
describe('Switches can be set to true or false', () => {
26+
beforeAll(async () => {
27+
await openExampleWithTitle('Switches can be set to true or false');
28+
});
2529

26-
await expect(element(by.id(testID))).toHaveValue('0');
27-
await expect(element(by.id(indicatorID))).toHaveText('Off');
28-
await element(by.id(testID)).tap();
29-
await expect(element(by.id(testID))).toHaveValue('1');
30-
await expect(element(by.id(indicatorID))).toHaveText('On');
31-
});
30+
it('Switch that starts off should switch', async () => {
31+
const testID = 'on-off-initial-off';
32+
const indicatorID = 'on-off-initial-off-indicator';
33+
34+
await expect(element(by.id(testID))).toHaveValue('0');
35+
await expect(element(by.id(indicatorID))).toHaveText('Off');
36+
await element(by.id(testID)).tap();
37+
await expect(element(by.id(testID))).toHaveValue('1');
38+
await expect(element(by.id(indicatorID))).toHaveText('On');
39+
});
3240

33-
it('Switch that starts on should switch', async () => {
34-
const testID = 'on-off-initial-on';
35-
const indicatorID = 'on-off-initial-on-indicator';
41+
it('Switch that starts on should switch', async () => {
42+
const testID = 'on-off-initial-on';
43+
const indicatorID = 'on-off-initial-on-indicator';
3644

37-
await expect(element(by.id(testID))).toHaveValue('1');
38-
await expect(element(by.id(indicatorID))).toHaveText('On');
39-
await element(by.id(testID)).tap();
40-
await expect(element(by.id(testID))).toHaveValue('0');
41-
await expect(element(by.id(indicatorID))).toHaveText('Off');
45+
await expect(element(by.id(testID))).toHaveValue('1');
46+
await expect(element(by.id(indicatorID))).toHaveText('On');
47+
await element(by.id(testID)).tap();
48+
await expect(element(by.id(testID))).toHaveValue('0');
49+
await expect(element(by.id(indicatorID))).toHaveText('Off');
50+
});
4251
});
4352

44-
it('disabled switch should not toggle', async () => {
45-
const onTestID = 'disabled-initial-on';
46-
const offTestID = 'disabled-initial-off';
47-
const onIndicatorID = 'disabled-initial-on-indicator';
48-
const offIndicatorID = 'disabled-initial-off-indicator';
53+
describe('Switches can be disabled', () => {
54+
beforeAll(async () => {
55+
await openExampleWithTitle('Switches can be disabled');
56+
});
57+
58+
it('disabled switch should not toggle', async () => {
59+
const onTestID = 'disabled-initial-on';
60+
const offTestID = 'disabled-initial-off';
61+
const onIndicatorID = 'disabled-initial-on-indicator';
62+
const offIndicatorID = 'disabled-initial-off-indicator';
4963

50-
await expect(element(by.id(onTestID))).toHaveValue('1');
51-
await expect(element(by.id(onIndicatorID))).toHaveText('On');
64+
await expect(element(by.id(onTestID))).toHaveValue('1');
65+
await expect(element(by.id(onIndicatorID))).toHaveText('On');
5266

53-
try {
54-
await element(by.id(onTestID)).tap();
55-
throw new Error('Does not match');
56-
} catch (err) {
57-
jestExpect(err.message.message).toEqual(
58-
jestExpect.stringContaining(
59-
'Cannot perform action due to constraint(s) failure',
60-
),
61-
);
62-
}
63-
await expect(element(by.id(onTestID))).toHaveValue('1');
64-
await expect(element(by.id(onIndicatorID))).toHaveText('On');
67+
try {
68+
await element(by.id(onTestID)).tap();
69+
throw new Error('Does not match');
70+
} catch (err) {
71+
jestExpect(err.message.message).toEqual(
72+
jestExpect.stringContaining(
73+
'Cannot perform action due to constraint(s) failure',
74+
),
75+
);
76+
}
77+
await expect(element(by.id(onTestID))).toHaveValue('1');
78+
await expect(element(by.id(onIndicatorID))).toHaveText('On');
6579

66-
await expect(element(by.id(offTestID))).toHaveValue('0');
67-
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
68-
try {
69-
await element(by.id(offTestID)).tap();
70-
throw new Error('Does not match');
71-
} catch (err) {
72-
jestExpect(err.message.message).toEqual(
73-
jestExpect.stringContaining(
74-
'Cannot perform action due to constraint(s) failure',
75-
),
76-
);
77-
}
78-
await expect(element(by.id(offTestID))).toHaveValue('0');
79-
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
80+
await expect(element(by.id(offTestID))).toHaveValue('0');
81+
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
82+
try {
83+
await element(by.id(offTestID)).tap();
84+
throw new Error('Does not match');
85+
} catch (err) {
86+
jestExpect(err.message.message).toEqual(
87+
jestExpect.stringContaining(
88+
'Cannot perform action due to constraint(s) failure',
89+
),
90+
);
91+
}
92+
await expect(element(by.id(offTestID))).toHaveValue('0');
93+
await expect(element(by.id(offIndicatorID))).toHaveText('Off');
94+
});
8095
});
8196
});

RNTester/e2e/__tests__/Touchable-test.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
* @format
99
*/
1010

11-
/* global element, by, expect */
11+
/* global device, element, by, expect */
12+
const {
13+
openComponentWithLabel,
14+
openExampleWithTitle,
15+
} = require('../e2e-helpers');
1216

1317
describe('Touchable', () => {
1418
beforeAll(async () => {
15-
await element(by.id('explorer_search')).replaceText('<Touchable*');
16-
await element(
17-
by.label('<Touchable*> and onPress Touchable and onPress examples.'),
18-
).tap();
19-
});
20-
21-
afterAll(async () => {
22-
//TODO - remove app state persistency, till then, we must go back to main screen,
23-
await element(by.label('Back')).tap();
19+
await device.reloadReactNative();
20+
await openComponentWithLabel(
21+
'<Touchable*',
22+
'<Touchable*> and onPress Touchable and onPress examples.',
23+
);
2424
});
2525

2626
it('Touchable Highlight should be tappable', async () => {
27+
await openExampleWithTitle('<TouchableHighlight>');
2728
const buttonID = 'touchable_highlight_image_button';
2829
const button2ID = 'touchable_highlight_text_button';
2930
const consoleID = 'touchable_highlight_console';
@@ -45,6 +46,8 @@ describe('Touchable', () => {
4546
});
4647

4748
it('Touchable Without Feedback should be tappable', async () => {
49+
await openExampleWithTitle('<TouchableWithoutFeedback>');
50+
4851
const buttonID = 'touchable_without_feedback_button';
4952
const consoleID = 'touchable_without_feedback_console';
5053

@@ -60,6 +63,8 @@ describe('Touchable', () => {
6063
});
6164

6265
it('Text should be tappable', async () => {
66+
await openExampleWithTitle('<Text onPress={fn}> with highlight');
67+
6368
const buttonID = 'tappable_text';
6469
const consoleID = 'tappable_text_console';
6570

RNTester/e2e/e2e-helpers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
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+
* @emails oncall+react_native
8+
* @format
9+
*/
10+
11+
/* global element, by, expect */
12+
13+
// Will open a component example from the root list
14+
// by filtering by component and then tapping on the label
15+
exports.openComponentWithLabel = async (component, label) => {
16+
await element(by.id('explorer_search')).replaceText(component);
17+
await element(by.label(label)).tap();
18+
};
19+
20+
// Will open an individual example for a component
21+
// by filtering on the example title
22+
exports.openExampleWithTitle = async title => {
23+
await element(by.id('example_search')).replaceText(title);
24+
};

0 commit comments

Comments
 (0)