Skip to content

Commit 63b3baa

Browse files
authored
test(e2e, Fabric): add e2e tests for issue/PR examples 748..758, remove Test713 (#2932)
## Description Check which example screens from issues/PRs can be used in e2e testing for tests `Test748, ..., Test758` and implement them if possible for Fabric. ### Test713 Test screen removed because the issue is not planned to be fixed, full discussion [here](#2928 (comment)). ### Test748 Skipped because the issue description does not contain enough information about the original bug. It is most likely connected with `headerRight` appearing/disappearing in the right moments when navigating between screens and `Test432` already covers even more complex cases. ### Test750 Skipped because we can't check whether insets are respected. ### Test758 Test created, only on iOS (original PR introduced `SearchBar` to iOS). It checks interactions with the search bar. ## Changes - add `Test758` e2e test - modify`Test758` test screen (change placeholder and cancel button text, fix TS issue) - add comments for every test screen from this PR in `apps/src/tests/index.ts` with the reason for (not) implementing e2e test for it ## Test code and steps to reproduce CI ## Checklist - [x] Ensured that CI passes
1 parent 442e13d commit 63b3baa

4 files changed

Lines changed: 85 additions & 114 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import { device, expect, element, by } from 'detox';
2+
import { describeIfiOS, selectIssueTestScreen } from '../e2e-utils';
3+
import isVersionEqualOrHigherThan from '../helpers/isVersionEqualOrHigherThan';
4+
5+
const { getIOSVersionNumber } = require('../../../scripts/e2e/ios-devices.js');
6+
7+
// On iOS 26+ cancel button does not contain any text.
8+
function getSearchBarCloseButton() {
9+
const iosVersion = getIOSVersionNumber();
10+
if (isVersionEqualOrHigherThan(iosVersion, '26.0')) {
11+
return element(by.label('Close').and(by.traits(['button'])));
12+
} else {
13+
return element(by.text('Cancel text'));
14+
}
15+
}
16+
17+
// PR related to iOS search bar
18+
describeIfiOS('Test758', () => {
19+
beforeAll(async () => {
20+
await device.reloadReactNative();
21+
});
22+
23+
it('Test758 should exist', async () => {
24+
await selectIssueTestScreen('Test758');
25+
});
26+
27+
it('search bar should not be initially visible', async () => {
28+
await expect(element(by.traits(['searchField']))).not.toBeVisible();
29+
});
30+
31+
it('search bar should appear on scroll', async () => {
32+
await element(by.text('Stuff')).swipe('down');
33+
await expect(element(by.traits(['searchField']))).toBeVisible();
34+
});
35+
36+
it('search bar should have correct placeholder text', async () => {
37+
await expect(element(by.text('Placeholder text'))).toBeVisible();
38+
});
39+
40+
it('search bar should show correct cancel button when focused', async () => {
41+
await element(by.traits(['searchField'])).tap();
42+
await expect(getSearchBarCloseButton()).toBeVisible();
43+
});
44+
45+
it('cancel button should disappear after being clicked', async () => {
46+
await getSearchBarCloseButton().tap();
47+
await expect(getSearchBarCloseButton()).not.toBeVisible();
48+
});
49+
50+
it('search bar should show correct results', async () => {
51+
await element(by.traits(['searchField'])).tap();
52+
await element(by.traits(['searchField'])).typeText('th');
53+
54+
await expect(element(by.text('Other'))).toBeVisible();
55+
await expect(element(by.text('The'))).toBeVisible();
56+
await expect(element(by.text('Nuggets'))).not.toBeVisible();
57+
});
58+
59+
it('search bar should not be visible on another screen', async () => {
60+
await element(by.text('Tap me for second screen')).tap();
61+
await expect(element(by.traits(['searchField']))).not.toBeVisible();
62+
});
63+
64+
it('search bar query should still be present after coming back from another screen', async () => {
65+
await element(by.text('First')).tap();
66+
await expect(element(by.text('th'))).toBeVisible();
67+
});
68+
69+
it('search results should still be correct after coming back from another screen', async () => {
70+
await expect(element(by.text('Other'))).toBeVisible();
71+
await expect(element(by.text('The'))).toBeVisible();
72+
await expect(element(by.text('Nuggets'))).not.toBeVisible();
73+
});
74+
75+
it('search should still be responsive after coming back from another screen', async () => {
76+
await element(by.traits(['searchField'])).clearText();
77+
await expect(element(by.text('Nuggets'))).toBeVisible();
78+
});
79+
});

apps/src/tests/issue-tests/Test713.js

Lines changed: 0 additions & 107 deletions
This file was deleted.

apps/src/tests/issue-tests/Test758.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ function First({ navigation }: NativeStackScreenProps<ParamListBase>) {
3838

3939
const [search, setSearch] = React.useState('');
4040

41-
const searchBarOptions = {
41+
const searchBarOptions: SearchBarProps = {
4242
barTintColor: 'powderblue',
4343
tintColor: 'red',
4444
textColor: 'red',
4545
hideWhenScrolling: true,
4646
obscureBackground: false,
4747
hideNavigationBar: false,
4848
autoCapitalize: 'sentences',
49-
placeholder: 'Some text',
49+
placeholder: 'Placeholder text',
5050
// Added in https://github.com/software-mansion/react-native-screens/pull/3186
5151
// to preserve test's original search bar configuration.
5252
placement: 'stacked',
53-
cancelButtonText: 'Some text',
53+
cancelButtonText: 'Cancel text',
5454
onChangeText: (e: NativeSyntheticEvent<{ text: string }>) =>
5555
setSearch(e.nativeEvent.text),
5656
onCancelButtonPress: () => console.warn('Cancel button pressed'),

apps/src/tests/issue-tests/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ export { default as Test662 } from './Test662'; // [E2E skipped]: can't check an
2525
export { default as Test691 } from './Test691'; // [E2E created](iOS): issue related to iOS modal behavior
2626
export { default as Test702 } from './Test702'; // [E2E skipped]: can't check animation in a meaningful way
2727
export { default as Test706 } from './Test706'; // [E2E skipped]: can't check font weight
28-
export { default as Test713 } from './Test713'; // [E2E skipped]: issue still present
2928
export { default as Test726 } from './Test726'; // [E2E created](iOS): issue related to iOS
30-
export { default as Test748 } from './Test748';
31-
export { default as Test750 } from './Test750';
32-
export { default as Test758 } from './Test758';
29+
export { default as Test748 } from './Test748'; // [E2E skipped]: issue unclear, Test432 covers more complex cases already
30+
export { default as Test750 } from './Test750'; // [E2E skipped]: can't check insets
31+
export { default as Test758 } from './Test758'; // [E2E created](iOS): PR related to iOS search bar
3332
export { default as Test761 } from './Test761'; // [E2E skipped]: can't check animation in a meaningful way
3433
export { default as Test779 } from './Test779'; // [E2E skipped]: can't check animation in a meaningful way
3534
export { default as Test780 } from './Test780'; // [E2E skipped]: can't use native swipe back gesture

0 commit comments

Comments
 (0)