import { Platform } from 'react-native'; import _ from 'lodash'; type TypeTestProps = { accessible: boolean; testID?: string; accessibilityLabel?: string; }; /** * E2E관련 Platform별 testID props 가져오는 함수 * @param testID `string`, View에 적용할 ID값 * @param groupsChildrenIos `boolean` true일시 하위 컴포넌트를 모두 grouping 하도록 되어있음. */ export const getTestProps = (testID: string, groupsChildrenIos = false): TypeTestProps | null => { if (testID === '') return null; if (Platform.OS === 'ios') { return { // ios의 경우 accessible 값이 true일 경우 하위 컴포넌트들에 대해서 검색하지 않고, 하위 컴포넌트들이 가진 id값들을 모두 취합됨. // 기본 false값으로 두고, 옵션으로 조정 가능하도록 수정 accessible: groupsChildrenIos, testID: testID, }; } return { accessible: true, testID: testID, accessibilityLabel: testID, }; }; /** * object안에 해당 property가 존재하는 검사하는 함수 */ export const hasOwnProperty = ( object: X, property: Y, ): object is X & Record => { return Object.prototype.hasOwnProperty.call(object, property); }; /** * 주어진 값이 null이거나 undefined인지 확인합니다. * * null이거나 undefined일경우 true, 아닐경우 false를 반환합니다. */ export const isNil = (value: unknown): value is null | undefined => _.isNil(value); /** * 주어진 값이 null이거나 undefined이 아닌지 확인합니다. * * null이거나 undefined일경우 false, 아닐경우 true를 반환합니다. */ export const isNotNil = (value: T | null | undefined): value is T => !_.isNil(value); /** * 주어진 값이 빈 값인지 확인합니다. */ export const isNotEmpty = (value: unknown): boolean => !_.isEmpty(value); export const isEmpty = (value: unknown): boolean => _.isEmpty(value); export function noop() {} export function isIos() { return Platform.OS === 'ios'; } export function isAndroid() { return Platform.OS === 'android'; } export async function sleep(ms: number): Promise { return new Promise((r) => setTimeout(r, ms)); }