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

Numeric string fields #2643

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jayanth-kumar-morem
Copy link

@jayanth-kumar-morem jayanth-kumar-morem commented Apr 30, 2023

Description

  1. Update the form state comparison by converting numeric string fields to numbers, enabling correct dirty state evaluation
  2. Add isNumericString utility function to identify numeric strings and exclude empty strings
  3. Add tests to ensure isNumericString() returns true for valid numeric strings
  4. Add tests to ensure isNumericString() returns false for non-numeric strings
  5. Add tests to ensure isNumericString() returns false for non-string values

Fixes (issue #)
#2629

… state

1. Update the form state comparison by converting numeric string fields to numbers, enabling correct dirty state evaluation
2. Add isNumericString utility function to identify numeric strings and exclude empty strings

Fixes: Shopify#2629
1. Add tests to ensure isNumericString() returns true for valid numeric strings
2. Add tests to ensure isNumericString() returns false for non-numeric strings
3. Add tests to ensure isNumericString() returns false for non-string values

Fixes: Shopify#2629
Copy link

@LauraAubin LauraAubin left a comment

Choose a reason for hiding this comment

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

Thank you for addressing this!

Copy link
Member

@BPScott BPScott left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this.

Are you able to add some tests to demonstrate the behaviour that was incorrect prior to this change and is now fixed?

Also, before this is merged we need to add a changeset entry using yarn run changeset.

@@ -138,7 +138,9 @@ export function useField<Value = string>(
return undefined;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[state.value, ...dependencies],
[state.value, ...dependencies].map(value =>
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add some unit tests that showcase the behaviour that would have broken without this change?

Choose a reason for hiding this comment

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

Yes @BPScott , I have added tests in utilities.test.ts. I'll add the changeset entry now, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

The tests in utilities.test.ts test the new helper that you've added. They don't test this line we're commenting on. It would be totally possible to undo the change on this line and all the tests would continue to pass. Yet it's this line that you're fixing a bug on, the addition of utility functions is kinda incidental.

I would like to see an test of useField that uses a numeric string, that fails if this line is as it is on main, and passes when this line is changed, so that I can understand the expected behaviour that you want to see.

@ryanwilsonperkin ryanwilsonperkin removed their request for review March 25, 2024 14: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.

None yet

3 participants