-
Notifications
You must be signed in to change notification settings - Fork 734
Dialog and Modal test drivers. #2893
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0e60717
Added drivers for modal and dialog
nitzanyiz 7efc19e
Added sanity checks with the new drivers
nitzanyiz 90daf4e
Tiny change
nitzanyiz 9091814
Added dialog dismiss test
nitzanyiz 6974988
Moved TouchableOverlay testID location
nitzanyiz 179d0a7
Changed driver deconstruct order
nitzanyiz f7caab1
Added query to handle the case the background doesn't exists
nitzanyiz ec85c42
Fixed imports. Added ref testing for dismiss
nitzanyiz 1b17b39
Merge branch 'master' into infra/DialogModalTestDriver
nitzanyiz 346acea
Name change and using pressable for the overlay
nitzanyiz 6b61202
Merged origin master
nitzanyiz c74690f
Copied old test with new button driver
nitzanyiz 3e7be33
Fixed modal test
nitzanyiz 88e0a69
Added test for modal dismiss
nitzanyiz 3a832dc
Check onDimiss callback being called
nitzanyiz 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {ModalProps} from './index'; | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
import {fireEvent} from '@testing-library/react-native'; | ||
|
||
export const ModalDriver = (props: ComponentProps) => { | ||
const {renderTree, testID} = props; | ||
const driver = useComponentDriver<ModalProps>(props); | ||
|
||
const isVisible = () => { | ||
return !!driver.getProps().visible; | ||
}; | ||
|
||
const pressOnBackground = () => { | ||
const overlay = renderTree.queryByTestId(`${testID}.TouchableOverlay`); | ||
if (overlay) { | ||
fireEvent.press(overlay); | ||
} | ||
}; | ||
|
||
return {...driver, isVisible, pressOnBackground}; | ||
}; |
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,18 @@ | ||
import React from 'react'; | ||
import {render} from '@testing-library/react-native'; | ||
import Modal, {ModalProps} from '../'; | ||
import {ModalDriver} from '../Modal.driver.new'; | ||
|
||
const testID = 'modal'; | ||
|
||
const TestCase = (props: Omit<ModalProps, 'testID'>) => { | ||
return <Modal testID={testID} {...props}/>; | ||
}; | ||
|
||
describe('Sanity modal test', () => { | ||
it('Should be visible', () => { | ||
const renderTree = render(<TestCase visible/>); | ||
const modal = ModalDriver({renderTree, testID}); | ||
expect(modal.isVisible()).toBeTruthy(); | ||
}); | ||
nitzanyiz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
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,10 @@ | ||
import {DialogProps} from './index'; | ||
import {useComponentDriver, ComponentProps} from '../../testkit/new/Component.driver'; | ||
import {ModalDriver} from '../../testkit/'; | ||
|
||
export const DialogDriver = (props: ComponentProps) => { | ||
const {renderTree, testID} = props; | ||
const driver = useComponentDriver<DialogProps>(props); | ||
const dialogModal = ModalDriver({renderTree, testID: `${testID}.modal`}); | ||
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 would call it 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. Ping |
||
return {...dialogModal, ...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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, {useRef} from 'react'; | ||
import {render, act} from '@testing-library/react-native'; | ||
import Dialog, {DialogProps} from '../index'; | ||
import {DialogDriver} from '../Dialog.driver.new'; | ||
|
||
const testID = 'dialog'; | ||
|
||
const TestCase = (props: Omit<DialogProps, 'testID'>) => { | ||
return <Dialog testID={testID} {...props}/>; | ||
}; | ||
|
||
const getDriver = (Element: React.JSX.Element) => { | ||
const renderTree = render(Element); | ||
const dialogDriver = DialogDriver({renderTree, testID}); | ||
return {renderTree, dialogDriver}; | ||
}; | ||
|
||
describe('Sanity checks', () => { | ||
it('Should show dialog', () => { | ||
const {dialogDriver} = getDriver(<TestCase visible/>); | ||
expect(dialogDriver.isVisible()).toBeTruthy(); | ||
}); | ||
|
||
it('Should dismiss dialog on background press', () => { | ||
const {dialogDriver} = getDriver(<TestCase visible/>); | ||
expect(dialogDriver.isVisible()).toBeTruthy(); | ||
dialogDriver.pressOnBackground(); | ||
expect(dialogDriver.isVisible()).toBeFalsy(); | ||
}); | ||
|
||
it('Should dismiss dialog on dismiss call', () => { | ||
let dialogRef: React.RefObject<{dismiss: () => void}>; | ||
const RefTestCase = () => { | ||
dialogRef = useRef<{dismiss:() => void}>(null); | ||
return <Dialog testID={testID} visible ref={dialogRef}/>; | ||
}; | ||
const {dialogDriver} = getDriver(<RefTestCase/>); | ||
expect(dialogDriver.isVisible()).toBeTruthy(); | ||
act(() => { | ||
dialogRef.current?.dismiss(); | ||
}); | ||
M-i-k-e-l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(dialogDriver.isVisible()).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
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.