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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use regex based TextMatch for suggestions #617

Merged
merged 3 commits into from Jun 11, 2020

Conversation

smeijer
Copy link
Member

@smeijer smeijer commented Jun 11, 2020

What:
I've adjusted the query suggestions to use regex-based text matchers when possible. This impacts all query methods, except for the Role variants. I believe roles need to be exact.

Currently, suggestions like these are made:

screen.getByRole('button', { name: /google search/i }) // regex name option
screen.getByText('A privacy reminder from Google')     // string text arg

With this PR, the same suggestions look like:

screen.getByRole('button', { name: /google search/i }) // regex name option
screen.getByText(/a privacy reminder from google/i)    // regex text arg

Why:
Because I believe that tests shouldn't fail due to a change in capitalization.

For that same reason, we already did this for name option in Role queries:

// current suggestion results 
screen.getByRole('button', { name: /search/i });
screen.getByRole('link', { name: /english/i });

So it only makes sense to do this for other queries as well.

How:
In the makeSuggestion function, the TextMatch is now wrapped in a regex when the query name isn't Role. Nothing fancy, just query !== 'Role' => text = new RegExp(text.toLowerCase(), 'i')

Checklist:

I've also added .idea to .gitignore. Am I really the only one who's using WebStorm? 馃槺

@smeijer smeijer self-assigned this Jun 11, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 11, 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 9e903d7:

Sandbox Source
jolly-blackburn-q8pf6 Configuration

@smeijer smeijer changed the title Feature/regex based suggestions feat: use regex based text matchers for suggestions Jun 11, 2020
@smeijer smeijer changed the title feat: use regex based text matchers for suggestions feat: use regex based TextMatch for suggestions Jun 11, 2020
@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #617 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #617   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          555       558    +3     
  Branches       138       140    +2     
=========================================
+ Hits           555       558    +3     
Impacted Files Coverage 螖
src/suggestions.js 100.00% <100.00%> (酶)

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 281eb8b...9e903d7. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Super duper. Thanks!

@kentcdodds kentcdodds merged commit b23a2bc into master Jun 11, 2020
@kentcdodds kentcdodds deleted the feature/regex-based-suggestions branch June 11, 2020 15:24
@kentcdodds
Copy link
Member

馃帀 This PR is included in version 7.12.0 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants