Skip to content
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

Adding tests for boolean control #19

Merged
merged 7 commits into from
Mar 11, 2024
Merged

Conversation

TrangPham
Copy link
Contributor

No description provided.

@TrangPham TrangPham force-pushed the add-tests-for-boolean-control branch from 94065a2 to b8454a5 Compare March 6, 2024 02:36
@TrangPham TrangPham marked this pull request as ready for review March 7, 2024 02:30
@@ -15,7 +15,7 @@ export function Checkbox({ data, className, id, enabled, uischema, schema, path,
return (
<AntDCheckbox
checked={checked}
onChange={(e: CheckboxChangeEvent) => handleChange(path, e.target.checked)}
onChange={(e: CheckboxChangeEvent) => {handleChange(path, e.target.checked)}}
Copy link
Contributor

Choose a reason for hiding this comment

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

is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I had added a console log here before. I'll update

Copy link
Contributor

@DrewHoo DrewHoo left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 37 to 49
const checkbox = await screen.findByLabelText("Name");
expect(checkbox).not.toBeChecked();
expect(updateData).not.toHaveBeenCalled();

await userEvent.click(checkbox);
expect(checkbox).toBeChecked();
// FYI the calls to updateData lag behind the actual checkbox state. Not sure why.
// It could be the difference between json-forms handleChange(path, value) and the onChange event.
expect(updateData).toHaveBeenLastCalledWith({ data: {name: false }, errors: []});

await userEvent.click(checkbox);
expect(checkbox).not.toBeChecked();
expect(updateData).toHaveBeenLastCalledWith({ data: {name: true }, errors: []});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DrewHoo i'm seeing this unexpected behavior within my test. Do you know where this could be coming from? I suspect it has something to do with how json form uses handleChange(path, value)

@@ -15,7 +15,7 @@ export function Checkbox({ data, className, id, enabled, uischema, schema, path,
return (
<AntDCheckbox
checked={checked}
onChange={(e: CheckboxChangeEvent) => handleChange(path, e.target.checked)}
onChange={(e: CheckboxChangeEvent) => {handleChange(path, e.target.checked)}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I had added a console log here before. I'll update

@TrangPham TrangPham force-pushed the add-tests-for-boolean-control branch from 5abaac6 to f0015c0 Compare March 11, 2024 22:10
@TrangPham TrangPham merged commit bda0b36 into main Mar 11, 2024
2 of 3 checks passed
@TrangPham TrangPham deleted the add-tests-for-boolean-control branch March 11, 2024 22:13
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