Skip to content

Get element by label input value and by labels concat values #607

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

Closed

Conversation

delca85
Copy link
Member

@delca85 delca85 commented Jun 6, 2020

What:

  • getAllLabelsByText now retrieves label by input elements not empty value too

  • getByLabelText accepts a new argument named concat that enables retrieving elements by multiple concatenated labels

Why:
According to #545 retrieving element through input labels was impossible as well as using a combination of labels to get a labelled element.

How:

  1. queryAllLabelsByText now makes a query not only on elements of type label but on input elements too. The empty input are excluded.
  2. in order to make queryAllLabelsByText gets the labels even if the text to be matched is a concatenation of labels, the concat argument is passed to the matcher. The matcher checks the value of concat to decide if the condition to be satisfied is an equality or an includes (in case of concat true) condition between the text and the candidate label.
  3. a last check is performed to know if all the provided text is composed by the found labels

Checklist:

  • add input type to elements queried by queryAllLabelsByText
  • remove input elements with empty value
  • add concat argument to all the methods called in the chain
  • change matcher behavior according to concat value
  • check if the labels compose the received text to be matched

Like said in #545 comments, I am not sure this is the right way to fix this wrong behavior and probably I am not considering some use case but I would like to receive some suggestions and share thoughts on it.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 6, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a89ec7f:

Sandbox Source
fancy-worker-p3j8v Configuration

@delca85 delca85 changed the title Pr/get label concat value Pr/get element by label input value and by labels concat values Jun 6, 2020
@kentcdodds
Copy link
Member

Hi @delca85! Thank you for this. This is a pretty hard problem. Unfortunately, I'm not sure that this is the right solution, but I don't know what the right solution is 😬 To compound on that, I don't have bandwidth to invest into this myself right now, so I'm calling on the rest of the @testing-library/all-maintainers (and anyone else seeing my bat signal 🦇) to come help us collaborate on a proper solution for this use case.

Sorry I can't be of more help.

bat signal

@delca85
Copy link
Member Author

delca85 commented Jun 8, 2020

Hi @kentcdodds! It was a pleasure for me to work on this. I would be happy to understand a bit more about the right solution so I hope your call will make someone help us!

@delca85 delca85 changed the title Pr/get element by label input value and by labels concat values Get element by label input value and by labels concat values Jun 27, 2020
@delca85 delca85 mentioned this pull request Jul 3, 2020
9 tasks
@kentcdodds
Copy link
Member

I think we can close this one now :) Thanks again!

@kentcdodds kentcdodds closed this Jul 20, 2020
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