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

feat(ByRole): Allow filter by value state #1223

Merged
merged 3 commits into from Mar 24, 2023

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Mar 8, 2023

Part of a larger committment to unify APIs for /react-native and /react (which is just /react-dom at the moment)

What:

Enables ByRole(role, { value })

Note that we don't support valuenow but rather value.now (same pattern for other aria-value* attributes). One reason is parity with @testing-library/react-native.

The other reason is that value.* works a bit different in that it looks at all value.* and combines them with && instead of returning on the first match. Today, { pressed: true, selected: true} has kind of an odd behavior since it only looks at whatever comes first in the implementation. We could combine them with && as well but it's not clear to me yet that this is always good. So by putting them in a single object makes it clear that we look at the whole object which wouldn't be that obvious for { name, valuemin, valuemax}. I don't feel too strongly about this specific rationale. I care more about parity with /react-native.

Why:

Makes writing tests for react-native and react-dom easier by removing barriers when changing the target platform that's being tested.

How:

Same patterns as for expanded, selected etc

Checklist:

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 8, 2023

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 c9a2416:

Sandbox Source
react-testing-library-examples Configuration

@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #1223 (daf92b3) into main (8c40a21) will not change coverage.
The diff coverage is 100.00%.

❗ Current head daf92b3 differs from pull request most recent head c9a2416. Consider uploading reports for the commit c9a2416 to get more accurate results

@@            Coverage Diff            @@
##              main     #1223   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          999      1035   +36     
  Branches       323       346   +23     
=========================================
+ Hits           999      1035   +36     
Flag Coverage Δ
node-14 100.00% <100.00%> (ø)
node-16 100.00% <100.00%> (ø)
node-18 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/queries/role.ts 100.00% <100.00%> (ø)
src/role-helpers.js 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@eps1lon eps1lon changed the title feat(ByRole): All filter by value state feat(ByRole): Allow filter by value state Mar 9, 2023
@eps1lon eps1lon marked this pull request as ready for review March 9, 2023 10:06
Copy link
Member

@timdeschryver timdeschryver left a comment

Choose a reason for hiding this comment

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

One small nit, but can be ignored if you want.

if (valueNow !== undefined) {
// guard against unknown roles
if (
allRoles.get(role as ARIARoleDefinitionKey)?.props['aria-valuenow'] ===
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about declaring a variable for allRoles.get(role as ARIARoleDefinitionKey) ?
It seems like this is repeated a few times in this meethod.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with repeating stuff. Makes it easier to grok the flow for a single option. If we change this pattern often we can reconsider but for now it seems like it's just an excercise in clean code.

@eps1lon eps1lon merged commit eadf748 into testing-library:main Mar 24, 2023
1 of 4 checks passed
@eps1lon eps1lon deleted the feat/byrole-value branch March 24, 2023 18:42
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

2 participants