Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Numeric string fields #2643

Closed

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
@znja znja closed this Oct 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants