diff --git a/src/components/hint/Hint.driver.new.ts b/src/components/hint/Hint.driver.new.ts new file mode 100644 index 0000000000..3bd6b43722 --- /dev/null +++ b/src/components/hint/Hint.driver.new.ts @@ -0,0 +1,67 @@ +import { + useComponentDriver, + ComponentProps, + usePressableDriver, + ViewDriver, + ImageDriver, + ModalDriver +} from '../../testkit'; +import {ViewStyle, StyleSheet} from 'react-native'; + +export const HintDriver = (props: ComponentProps) => { + const driver = usePressableDriver(useComponentDriver(props)); + + const modalDriver = ModalDriver({ + renderTree: props.renderTree, + testID: `${props.testID}.modal` + }); + + const contentDriver = ViewDriver({ + renderTree: props.renderTree, + testID: `${props.testID}.message` + }); + + const overlayDriver = usePressableDriver(useComponentDriver({ + renderTree: props.renderTree, + testID: `${props.testID}.overlay` + })); + + const iconDriver = ImageDriver({ + renderTree: props.renderTree, + testID: `${props.testID}.icon` + }); + + const getIcon = () => { + return iconDriver; + }; + + const getBackgroundColor = (): ViewStyle => { + return StyleSheet.flatten(contentDriver.getStyle()).backgroundColor as ViewStyle; + }; + + const isBackgroundExists = () => { + return overlayDriver.exists(); + }; + + const isModalVisible = () => { + return modalDriver.isVisible(); + }; + + const press = () => { + return driver.press(); + }; + + const pressOnBackground = () => { + return overlayDriver.press(); + }; + + return { + getBackgroundColor, + getIcon, + isBackgroundExists, + pressOnBackground, + isModalVisible, + ...driver, + press + }; +}; diff --git a/src/components/hint/__tests__/index.spec.tsx b/src/components/hint/__tests__/index.spec.tsx index 102f87985b..31d08aa2ed 100644 --- a/src/components/hint/__tests__/index.spec.tsx +++ b/src/components/hint/__tests__/index.spec.tsx @@ -1,16 +1,30 @@ -import React from 'react'; -import {Hint} from 'react-native-ui-lib'; -import {Colors} from '../../../style'; -import {findStyle} from '../../../uilib-test-renderer'; -import {HintDriver} from '../Hint.driver'; +import React, {useRef} from 'react'; +import {waitFor, render} from '@testing-library/react-native'; +import {Hint, Colors, Button} from '../../../'; +import {HintDriver} from '../Hint.driver.new'; + +const TEST_ID = 'Hint'; + +const settingsIcon = require('../../../assets/icons/check.png'); const HintTestComponent = ({ showHint, - color + color, + onPress, + onBackgroundPress, + useTargetFrame = true, + useModal, + useIcon }: { showHint: boolean; color?: string; + onPress?: Function; + onBackgroundPress?: Function; + useTargetFrame?: boolean; + useModal?: boolean; + useIcon?: boolean; }) => { + const ref = useRef(); return ( {}} + targetFrame={useTargetFrame && {x: 1, y: 1, height: 1, width: 1}} + onBackgroundPress={onBackgroundPress} + onPress={onPress} color={color} removePaddings enableShadow - testID={'Hint'} - /> + testID={TEST_ID} + useModal={useModal} + icon={useIcon ? settingsIcon : undefined} + ref={ref} + > +