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

Fix issue of getByDisplayValue not checking TextInputs defaultValue #656

Merged

Conversation

MattAgn
Copy link
Collaborator

@MattAgn MattAgn commented Jan 23, 2021

Summary

This PR aims to solve this issue. Basically the issue to fix is that the byDisplayValue helpers don't check the defaultValue prop of TextInputs.

Requirements

  • If a TextInput only has a defaultValue and no value, getByDisplayValue should find it
  • If a TextInput has a defaultValue AND a value, getByDisplayValue should only find it by its value and not its defaultValue (since if a value is provided, the default value won't be displayed)

Test plan

  • Check that getByDisplayValue and queryByDisplayValue get the TextInput by defaultValue if no value is provided
  • Check that getByDisplayValue and queryByDisplayValue don't get the TextInput by defaultValue if a value is provided

@MattAgn MattAgn changed the title refactor: extract method filterNodeByType Fix issue of getByDisplayValue not checking TextInputs defaultValue Jan 23, 2021
@@ -107,11 +107,10 @@ const getTextInputNodeByPlaceholderText = (node, placeholder) => {
const getTextInputNodeByDisplayValue = (node, value) => {
try {
const { TextInput } = require('react-native');
const nodeValue = node.props.value || node.props.defaultValue;
Copy link
Member

@thymikee thymikee Jan 25, 2021

Choose a reason for hiding this comment

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

I think we want to be explicit here and check if node.props.value === undefined. Would be great to also have a test for value being 0 and empty string to test that

Copy link
Collaborator Author

@MattAgn MattAgn Jan 25, 2021

Choose a reason for hiding this comment

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

indeed that would be better! which value do we use if value is empty string?
for 0, is is possible that it is the number 0 in an input field ? or will it be "0" ?

Copy link
Member

@thymikee thymikee Jan 25, 2021

Choose a reason for hiding this comment

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

I think it's always gonna be a string for Text, but the only way to be sure would be to test it. I recall numbers also work here, so the Text component may perform some implicit conversion to string.

Nevertheless, if the value is "" the defaultValue is no longer used as the value is set to not-undefined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh alright I did not know that, I'll make the changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Flow does not let me put 0 in the value prop of the TextInput, it wants a string. Should I ignore it or do we consider it's fine? (especially since we'll now be checking for undefined and not false values)

Copy link
Member

Choose a reason for hiding this comment

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

No need to test the number then :)

if the value of TextInput is an empty string, then the TextInput will not use the defaultValue and display the empty string. Our tests now do the same
Copy link
Member

@thymikee thymikee 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!

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.

3 participants