Skip to content

Commit

Permalink
feat: new AwareScrollView test
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 29, 2023
1 parent 85e07e3 commit 6aeb889
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion detox/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
- [ ] separate assets for local testing only (Android, with google play)
- [ ] test with keyboard resize
- [ ] test for disabled/enabled functionality
- [ ] tests for AwareScrollView
- [x] tests for AwareScrollView
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions detox/e2e/aware-scroll-view.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import waitForExpect from 'wait-for-expect';

import { expectBitmapsToBeEqual } from './asserts';
import { waitAndReplace, waitAndTap, waitAndType } from './helpers';
import setDemoMode from './utils/setDemoMode';

const BLINKING_CURSOR = 0.35;

describe('AwareScrollView test cases', () => {
beforeAll(async () => {
await setDemoMode();
await device.launchApp();
});

it('should push input above keyboard on focus', async () => {
await waitAndTap('aware_scroll_view');
await waitAndTap('TextInput#3');
await waitForExpect(async () => {
await expectBitmapsToBeEqual(
'AwareScrollViewFirstInputFocused',
BLINKING_CURSOR
);
});
});

it('should detect TextInput growth', async () => {
await waitAndType('TextInput#3', '\n\n\n\n');
await waitForExpect(async () => {
await expectBitmapsToBeEqual(
'AwareScrollViewFirstInputGrown',
BLINKING_CURSOR
);
});
});

it('should auto-scroll when new input gets focused', async () => {
// scroll while keeping a focus is not working: https://github.com/wix/Detox/issues/174
// but we may use `await element(by.id('TextInput#3')).swipe('up');` (currently focused input as event receiver)
await waitAndReplace('TextInput#3', '\n\n');
await waitAndTap('TextInput#4');
await waitForExpect(async () => {
await expectBitmapsToBeEqual(
'AwareScrollViewInputChanged',
BLINKING_CURSOR
);
});
});

it('should scroll back when keyboard dismissed', async () => {
// tap outside of input to close a keyboard
await waitAndTap('TextInput#4', { x: 0, y: -10 });
await waitForExpect(async () => {
await expectBitmapsToBeEqual(
'AwareScrollViewKeyboardClosed',
BLINKING_CURSOR
);
});
});
});
11 changes: 7 additions & 4 deletions detox/e2e/helpers/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const TIMEOUT_FOR_LONG_OPERATIONS = 30000;
export const delay = (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));

export const tap = async (id: string): Promise<void> => {
export const tap = async (id: string, point?: Detox.Point2D): Promise<void> => {
console.debug(
'---------------------------------\n',
'Tap on element with id: ',
colors.magenta(id)
);
await element(by.id(id)).tap();
await element(by.id(id)).tap(point);
};

// Not used yet. Will be used later
Expand Down Expand Up @@ -65,9 +65,12 @@ export const swipeUp = async (id: string): Promise<void> => {
await element(by.id(id)).swipe('up', 'fast', 1, NaN, 0.85);
};

export const waitAndTap = async (id: string): Promise<void> => {
export const waitAndTap = async (
id: string,
point?: Detox.Point2D
): Promise<void> => {
await waitForElementById(id, TIMEOUT_FOR_LONG_OPERATIONS);
await tap(id);
await tap(id, point);
};

export const waitAndType = async (id: string, text: string): Promise<void> => {
Expand Down
1 change: 1 addition & 0 deletions example/src/components/TextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const TextInput = (props: TextInputProps) => {
style={styles.container}
multiline
numberOfLines={2}
testID={props.placeholder}
{...props}
placeholder={`${props.placeholder} (${props.keyboardType === 'default' ? 'text' : 'numeric'})`}
/>
Expand Down
2 changes: 1 addition & 1 deletion example/src/screens/Examples/AwareScrollView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function AwareScrollView() {
useResizeMode();

return (
<KeyboardAwareScrollView bottomOffset={50} style={styles.container} contentContainerStyle={styles.content}>
<KeyboardAwareScrollView testID='aware_scroll_view_container' bottomOffset={50} style={styles.container} contentContainerStyle={styles.content}>
{new Array(10).fill(0).map((_, i) => (
<TextInput
key={i}
Expand Down

0 comments on commit 6aeb889

Please sign in to comment.