Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NoQA] fix(e2e): fix e2e search test by clicking search page #51157

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React, {forwardRef, useCallback, useEffect, useMemo, useState} from 'reac
import type {GestureResponderEvent, View} from 'react-native';
// eslint-disable-next-line no-restricted-imports
import {Pressable} from 'react-native';
import type {PressableRef} from '@components/Pressable/GenericPressable/types';
import type PressableProps from '@components/Pressable/GenericPressable/types';
import useSingleExecution from '@hooks/useSingleExecution';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import Accessibility from '@libs/Accessibility';
import HapticFeedback from '@libs/HapticFeedback';
import KeyboardShortcut from '@libs/KeyboardShortcut';
import CONST from '@src/CONST';
import type {PressableRef} from './types';
import type PressableProps from './types';

function GenericPressable(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {forwardRef} from 'react';
import type {PressableRef} from '@components/Pressable/GenericPressable/types';
import type PressableProps from '@components/Pressable/GenericPressable/types';
import GenericPressable from './BaseGenericPressable';
import type {PressableRef} from './types';
import type PressableProps from './types';

function NativeGenericPressable(props: PressableProps, ref: PressableRef) {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, {forwardRef} from 'react';
import type {Role} from 'react-native';
import type {PressableRef} from '@components/Pressable/GenericPressable/types';
import type PressableProps from '@components/Pressable/GenericPressable/types';
import GenericPressable from './BaseGenericPressable';

function WebGenericPressable({focusable = true, ...props}: PressableProps, ref: PressableRef) {
const accessible = props.accessible ?? props.accessible === undefined ? true : props.accessible;

return (
<GenericPressable
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
// change native accessibility props to web accessibility props
focusable={focusable}
tabIndex={props.tabIndex ?? (!accessible || !focusable) ? -1 : 0}
role={(props.accessibilityRole ?? props.role) as Role}
id={props.id}
aria-label={props.accessibilityLabel}
aria-labelledby={props.accessibilityLabelledBy}
aria-valuenow={props.accessibilityValue?.now}
aria-valuemin={props.accessibilityValue?.min}
aria-valuemax={props.accessibilityValue?.max}
aria-valuetext={props.accessibilityValue?.text}
dataSet={{tag: 'pressable', ...(props.noDragArea && {dragArea: false}), ...props.dataSet}}
/>
);
}

WebGenericPressable.displayName = 'WebGenericPressable';

export default forwardRef(WebGenericPressable);
34 changes: 34 additions & 0 deletions src/components/Pressable/GenericPressable/index.e2e.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, {forwardRef, useEffect} from 'react';
import GenericPressable from './implementation';
import type {PressableRef} from './types';
import type PressableProps from './types';

const pressableRegistry = new Map<string, PressableProps>();

function getPressableProps(nativeID: string): PressableProps | undefined {
return pressableRegistry.get(nativeID);
}

function E2EGenericPressableWrapper(props: PressableProps, ref: PressableRef) {
useEffect(() => {
const nativeId = props.nativeID;
if (!nativeId) {
return;
}
console.debug(`[E2E] E2EGenericPressableWrapper: Registering pressable with nativeID: ${nativeId}`);
pressableRegistry.set(nativeId, props);
}, [props]);

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

E2EGenericPressableWrapper.displayName = 'E2EGenericPressableWrapper';

export default forwardRef(E2EGenericPressableWrapper);
export {getPressableProps};
34 changes: 2 additions & 32 deletions src/components/Pressable/GenericPressable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
import React, {forwardRef} from 'react';
import type {Role} from 'react-native';
import GenericPressable from './BaseGenericPressable';
import type {PressableRef} from './types';
import type PressableProps from './types';
import GenericPressable from './implementation';

function WebGenericPressable({focusable = true, ...props}: PressableProps, ref: PressableRef) {
const accessible = props.accessible ?? props.accessible === undefined ? true : props.accessible;

return (
<GenericPressable
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
// change native accessibility props to web accessibility props
focusable={focusable}
tabIndex={props.tabIndex ?? (!accessible || !focusable) ? -1 : 0}
role={(props.accessibilityRole ?? props.role) as Role}
id={props.id}
aria-label={props.accessibilityLabel}
aria-labelledby={props.accessibilityLabelledBy}
aria-valuenow={props.accessibilityValue?.now}
aria-valuemin={props.accessibilityValue?.min}
aria-valuemax={props.accessibilityValue?.max}
aria-valuetext={props.accessibilityValue?.text}
dataSet={{tag: 'pressable', ...(props.noDragArea && {dragArea: false}), ...props.dataSet}}
/>
);
}

WebGenericPressable.displayName = 'WebGenericPressable';

export default forwardRef(WebGenericPressable);
export default GenericPressable;
1 change: 1 addition & 0 deletions src/components/Search/SearchRouter/SearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function SearchButton({style}: SearchButtonProps) {
return (
<Tooltip text={translate('common.search')}>
<PressableWithoutFeedback
nativeID="searchButton"
accessibilityLabel={translate('common.search')}
style={[styles.flexRow, styles.touchableButtonImage, style]}
onPress={Session.checkIfActionIsAllowed(() => {
Expand Down
24 changes: 24 additions & 0 deletions src/libs/E2E/tests/openSearchRouterTest.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Config from 'react-native-config';
import * as E2EGenericPressableWrapper from '@components/Pressable/GenericPressable/index.e2e';
import E2ELogin from '@libs/E2E/actions/e2eLogin';
import waitForAppLoaded from '@libs/E2E/actions/waitForAppLoaded';
import E2EClient from '@libs/E2E/client';
Expand Down Expand Up @@ -31,6 +32,29 @@ const test = () => {

Performance.subscribeToMeasurements((entry) => {
console.debug(`[E2E] Entry: ${JSON.stringify(entry)}`);
if (entry.name === CONST.TIMING.SIDEBAR_LOADED) {
const props = E2EGenericPressableWrapper.getPressableProps('searchButton');
if (!props) {
console.debug('[E2E] Search button not found, failing test!');
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
error: 'Search button not found',
name: 'Open Search Router TTI',
}).then(() => E2EClient.submitTestDone());
return;
}
if (!props.onPress) {
console.debug('[E2E] Search button found but onPress prop was not present, failing test!');
E2EClient.submitTestResults({
branch: Config.E2E_BRANCH,
error: 'Search button found but onPress prop was not present',
name: 'Open Search Router TTI',
}).then(() => E2EClient.submitTestDone());
return;
}
// Open the search router
props.onPress();
}

if (entry.name === CONST.TIMING.SEARCH_ROUTER_RENDER) {
E2EClient.submitTestResults({
Expand Down
Loading