-
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
Conversation
This is waiting for the Button driver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I would call it modalDriver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
@nitzanwix |
BTW, |
const renderTree = render(<TestCase visible/>); | ||
const modal = ModalDriver({renderTree, testID}); | ||
expect(modal.isVisible()).toBeTruthy(); | ||
it('Should be not visible at first and visible at second render', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('Should be not visible at first and visible at second render', () => { | |
it('Test visibility', () => { |
expect(modalDriver.isVisible()).toBeTruthy(); | ||
}); | ||
|
||
it('Should press on background', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test close when background is pressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or Should dismiss modal on background press
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't think this causes the modal to dismiss it just lets you press on the background. On the dialog pressing on the background of the modal makes it dismiss.
it('Should dismiss modal', () => { | ||
const onDismissHandler = jest.fn(); | ||
const TestCase = () => { | ||
const [showModal, setShowModal] = useState(true); | ||
return ( | ||
<View> | ||
<Modal testID={testID} onDismiss={onDismissHandler} visible={showModal}/> | ||
<Button testID={'button-dismiss'} onPress={() => setShowModal(false)}/> | ||
</View> | ||
); | ||
}; | ||
const renderTree = render(<TestCase/>); | ||
const modalDriver = ModalDriver({renderTree, testID}); | ||
const buttonDriver = ButtonDriver({renderTree, testID: 'button-dismiss'}); | ||
expect(modalDriver.isVisible()).toBeTruthy(); | ||
expect(onDismissHandler).not.toHaveBeenCalled(); | ||
buttonDriver.press(); | ||
expect(modalDriver.isVisible()).toBeFalsy(); | ||
expect(onDismissHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test for the dismiss callback.
Description
Dialog and Modal new test kit drivers.
Changelog
None
Additional info
None