Skip to content

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 15 commits into from
Jan 18, 2024
Merged

Dialog and Modal test drivers. #2893

merged 15 commits into from
Jan 18, 2024

Conversation

nitzanyiz
Copy link
Collaborator

@nitzanyiz nitzanyiz commented Jan 15, 2024

Description

Dialog and Modal new test kit drivers.

Changelog

None

Additional info

None

@nitzanyiz nitzanyiz marked this pull request as ready for review January 16, 2024 10:24
@nitzanyiz nitzanyiz requested a review from M-i-k-e-l January 16, 2024 10:24
@nitzanyiz nitzanyiz marked this pull request as draft January 16, 2024 11:39
@nitzanyiz
Copy link
Collaborator Author

This is waiting for the Button driver

Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a 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`});
Copy link
Collaborator

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping

@M-i-k-e-l
Copy link
Collaborator

@nitzanwix
You missed one comment and you need to resolve the conflicts

@M-i-k-e-l
Copy link
Collaborator

BTW, Additional info is generally used in the public repo for ticket number, I think you can leave it empty here

@nitzanyiz nitzanyiz marked this pull request as ready for review January 17, 2024 09:54
@nitzanyiz nitzanyiz requested a review from M-i-k-e-l January 17, 2024 10:12
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', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('Should be not visible at first and visible at second render', () => {
it('Test visibility', () => {

expect(modalDriver.isVisible()).toBeTruthy();
});

it('Should press on background', () => {
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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.

Comment on lines +32 to +52
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);
});
});
Copy link
Collaborator Author

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.

@nitzanyiz nitzanyiz merged commit 068b4d0 into master Jan 18, 2024
@nitzanyiz nitzanyiz deleted the infra/DialogModalTestDriver branch January 18, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants