Skip to content

Commit

Permalink
Merge pull request Expensify#47176 from margelo/e2e/fix-typing-test
Browse files Browse the repository at this point in the history
[NoQA] fix: e2e typing test
  • Loading branch information
mountiny authored Aug 12, 2024
2 parents 0980fcd + 3bb381e commit 334c270
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ForwardedRef} from 'react';
import React, {forwardRef, useEffect} from 'react';
import React, {forwardRef, useEffect, useRef} from 'react';
import {Keyboard} from 'react-native';
import E2EClient from '@libs/E2E/client';
import type {ComposerRef} from '@pages/home/report/ReportActionCompose/ReportActionCompose';
Expand All @@ -24,6 +24,8 @@ function ComposerWithSuggestionsE2e(props: ComposerWithSuggestionsProps, ref: Fo
// for this component. This file is only used for e2e tests, so it's okay to
// disable compiler for this file.

const textInputRef = useRef<ComposerRef | null>();

// Eventually Auto focus on e2e tests
useEffect(() => {
const testConfig = E2EClient.getCurrentActiveTestConfig();
Expand All @@ -34,33 +36,39 @@ function ComposerWithSuggestionsE2e(props: ComposerWithSuggestionsProps, ref: Fo
// We need to wait for the component to be mounted before focusing
setTimeout(() => {
const setFocus = () => {
if (!(ref && 'current' in ref)) {
if (!(textInputRef && 'current' in textInputRef)) {
return;
}

ref.current?.focus(true);
textInputRef.current?.focus(true);

setTimeout(() => {
// and actually let's verify that the keyboard is visible
if (Keyboard.isVisible()) {
return;
}

ref.current?.blur();
textInputRef.current?.blur();
setFocus();
// 500ms is enough time for any keyboard to open
}, 500);
// 1000ms is enough time for any keyboard to open
}, 1000);
};

setFocus();
}, 1);
}, [ref]);
}, [textInputRef]);

return (
<ComposerWithSuggestions
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
ref={(composerRef) => {
textInputRef.current = composerRef;

if (typeof ref === 'function') {
ref(composerRef);
}
}}
>
{/* Important:
this has to be a child, as this container might not
Expand Down

0 comments on commit 334c270

Please sign in to comment.