-
Notifications
You must be signed in to change notification settings - Fork 734
new driver for hint testing #2898
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
Closed
Closed
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d969254
new driver for hint testing
adids1221 ea2828c
onPress & onBackgroundPress tests
adids1221 f6cdf39
merged master
adids1221 ee0c757
testing icon on Hint
adids1221 24636d4
conflict resolved
adids1221 44c6418
removed on background press test
adids1221 8511ef5
fixed most of the review notes
adids1221 d986980
Merge branch 'master' into infra/testing-hint-driver-new
adids1221 a74a46c
fixed review notes
adids1221 048de98
fix the test that failed
adids1221 7b80c45
fixed most of the review notes
adids1221 19d685c
removed test when hint isn't visible
adids1221 3b310bd
Merge branch 'master' into infra/testing-hint-driver-new
adids1221 8edd6fc
Merge branch 'master' into infra/testing-hint-driver-new
adids1221 a58a3a2
Merge branch 'master' into infra/testing-hint-driver-new
adids1221 9e11b4e
fixed ts errors
adids1221 a714528
small fixes
adids1221 a96f9c2
fixed review notes
adids1221 02830ef
Merge branch 'master' into infra/testing-hint-driver-new
M-i-k-e-l c3acf27
Fix test
M-i-k-e-l 836b56f
Fix tests and more
M-i-k-e-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import {HintProps} from './index'; | ||
import {TouchableOpacityProps} from '../touchableOpacity'; | ||
import { | ||
useComponentDriver, | ||
ComponentProps, | ||
usePressableDriver, | ||
ViewDriver, | ||
ImageDriver, | ||
ModalDriver, | ||
TextDriver | ||
} from '../../testkit'; | ||
import {ViewStyle, StyleSheet} from 'react-native'; | ||
|
||
export const HintDriver = (props: ComponentProps) => { | ||
const driver = usePressableDriver<HintProps>(useComponentDriver(props)); | ||
|
||
const modalDriver = ModalDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.modal` | ||
}); | ||
|
||
const contentDriver = ViewDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.message` | ||
}); | ||
|
||
const textDriver = TextDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.text` | ||
}); | ||
|
||
const hintPressableDriver = usePressableDriver<TouchableOpacityProps>(useComponentDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}` | ||
})); | ||
|
||
const overlayDriver = usePressableDriver<TouchableOpacityProps>(useComponentDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.overlay` | ||
})); | ||
|
||
const iconDriver = ImageDriver({ | ||
renderTree: props.renderTree, | ||
testID: `${props.testID}.icon` | ||
}); | ||
|
||
const getModal = () => { | ||
return modalDriver; | ||
}; | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const getIcon = () => { | ||
return iconDriver; | ||
}; | ||
|
||
const getBackgroundColor = (): ViewStyle => { | ||
return StyleSheet.flatten(contentDriver.getProps().style).backgroundColor as ViewStyle; | ||
}; | ||
|
||
const getMessage = () => { | ||
return textDriver.getText(); | ||
}; | ||
|
||
const getHintPressable = () => { | ||
return hintPressableDriver; | ||
}; | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const getOverlay = () => { | ||
return overlayDriver; | ||
}; | ||
|
||
const hintPress = () => { | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return hintPressableDriver.press(); | ||
}; | ||
|
||
const hintPressOnBackground = () => { | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return overlayDriver.press(); | ||
}; | ||
|
||
return { | ||
getBackgroundColor, | ||
getModal, | ||
getIcon, | ||
getMessage, | ||
getHintPressable, | ||
getOverlay, | ||
hintPress, | ||
hintPressOnBackground, | ||
...driver | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,135 @@ | ||
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 'react-native-ui-lib'; | ||
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 ( | ||
<Hint | ||
visible={showHint} | ||
message={'Hint message to hint things'} | ||
position={Hint.positions.TOP} | ||
useSideTip | ||
key={'1'} | ||
targetFrame={{x: 1, y: 1, height: 1, width: 1}} | ||
onBackgroundPress={() => {}} | ||
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} | ||
> | ||
<Button round $backgroundDefault/> | ||
</Hint> | ||
); | ||
}; | ||
|
||
describe('Hint Screen component test', () => { | ||
afterEach(() => { | ||
HintDriver.clear(); | ||
}); | ||
//TODO: Add test for Hint tip position | ||
describe('Test Hint style:', () => { | ||
it('Test Hint component background color', async () => { | ||
const expectedColor = Colors.$backgroundPrimaryHeavy; | ||
const renderTree = render(<HintTestComponent showHint/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(await driver.getElement()).toBeTruthy(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'de change this to something else, what are we really testing here? |
||
|
||
let contentColor = await driver.getBackgroundColor(); | ||
expect(contentColor).toBe(expectedColor); | ||
|
||
const whiteHintRenderTree = render(<HintTestComponent showHint color={Colors.white}/>); | ||
const whiteHintDriver = HintDriver({renderTree: whiteHintRenderTree, testID: TEST_ID}); | ||
|
||
it('Test Hint component background color', async () => { | ||
const expectedColor = Colors.$backgroundPrimaryHeavy; | ||
const component = <HintTestComponent showHint/>; | ||
contentColor = await whiteHintDriver.getBackgroundColor(); | ||
expect(contentColor).toBe(Colors.white); | ||
}); | ||
}); | ||
|
||
const driver = new HintDriver({component, testID: 'Hint'}); | ||
expect(await driver.getElement()).toBeTruthy(); | ||
describe('Test Hint icon', () => { | ||
it('Hint should include icon', async () => { | ||
const renderTree = render(<HintTestComponent showHint useIcon/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(driver.getIcon().exists()).toBeTruthy(); | ||
}); | ||
|
||
const hintContent = await driver.getHintContent(); | ||
let color = findStyle('backgroundColor', hintContent); | ||
it('Hint shouldn\'t include icon', async () => { | ||
const renderTree = render(<HintTestComponent showHint/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(driver.getIcon().exists()).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
expect(color).toBe(expectedColor); | ||
expect(hintContent).toBeTruthy(); | ||
describe('Test Hint content', () => { | ||
it('Hint should include message', async () => { | ||
const renderTree = render(<HintTestComponent showHint/>); | ||
const message = renderTree.getByTestId(`${TEST_ID}.text`).props.children; | ||
expect(message).toBe('Hint message to hint things'); | ||
}); | ||
}); | ||
|
||
const WhiteHint = <HintTestComponent showHint color={Colors.white}/>; | ||
const WhiteHintDriver = new HintDriver({component: WhiteHint, testID: 'Hint'}); | ||
describe('Test Hint modal visibility:', () => { | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it('Test Hint modal is not visible when showHint is false', async () => { | ||
const renderTree = render(<HintTestComponent showHint={false}/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(await driver.getModal().exists()).toBeFalsy(); | ||
adids1221 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
const WhiteHintContent = await WhiteHintDriver.getHintContent(); | ||
color = findStyle('backgroundColor', WhiteHintContent); | ||
expect(color).toBe(Colors.white); | ||
it('Test Hint modal is visible when showHint is true', async () => { | ||
const renderTree = render(<HintTestComponent showHint onBackgroundPress={() => {}}/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(await driver.exists()).toBeTruthy(); | ||
expect(await driver.getModal().isVisible()).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
it('Test Hint modal is not visible when showHint is false', async () => { | ||
const component = <HintTestComponent showHint={false}/>; | ||
const driver = new HintDriver({component, testID: 'Hint'}); | ||
expect(await driver.getHintModal()).toBeFalsy(); | ||
describe('Test Hint onPress', () => { | ||
let onPressCallback: jest.Mock; | ||
beforeEach(() => (onPressCallback = jest.fn())); | ||
afterEach(() => onPressCallback.mockClear()); | ||
|
||
it('should trigger onPress callback', async () => { | ||
const renderTree = render(<HintTestComponent showHint onPress={onPressCallback}/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
driver.hintPress(); | ||
await waitFor(() => expect(onPressCallback).toHaveBeenCalledTimes(1)); | ||
}); | ||
|
||
it('should not trigger onPress callback when onPress isn\'t passed', async () => { | ||
const renderTree = render(<HintTestComponent showHint/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
driver.hintPress(); | ||
await waitFor(() => expect(onPressCallback).toHaveBeenCalledTimes(0)); | ||
}); | ||
}); | ||
|
||
it('Test Hint modal is visible when showHint is true', async () => { | ||
const component = <HintTestComponent showHint/>; | ||
const driver = new HintDriver({component, testID: 'Hint'}); | ||
expect(await driver.getElement()).toBeTruthy(); | ||
expect(await driver.getHintModal()).toBeTruthy(); | ||
describe('Test Hint onBackgroundPress', () => { | ||
it('should not create touchable overlay driver when onBackgroundPress isn\'t passed', async () => { | ||
const renderTree = render(<HintTestComponent showHint/>); | ||
const driver = HintDriver({renderTree, testID: TEST_ID}); | ||
expect(driver.getOverlay().exists()).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.