Skip to content

Query by role and accessibilityState and improve ByRole query errors - #1161

Merged
mdjastrzebski merged 11 commits into
callstack:mainfrom
AugustinLF:feat/by-role-accessibilityStates-support
Oct 20, 2022
Merged

Query by role and accessibilityState and improve ByRole query errors#1161
mdjastrzebski merged 11 commits into
callstack:mainfrom
AugustinLF:feat/by-role-accessibilityStates-support

Conversation

@AugustinLF

Copy link
Copy Markdown
Collaborator

Summary

RTL does have some form of validation to make sure that we don't use incompatible combinations (roles/states that don't make sense, like a checked button), but I'm not sure about that, and it is out of scope, we can create an additional issue if we feel like it.

Closes #1134

Comment thread src/queries/role.ts Outdated
Comment thread src/queries/role.ts Outdated
Comment thread src/queries/role.ts Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated

@mdjastrzebski mdjastrzebski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Kudos for implementing this feature @AugustinLF

  1. This implementation should automatically support upcoming aria-states props, when checked on host components, as they are taken into consideration when passing them from exported composite component. See here, not sure if these are present in the current released version of RN.

  2. It seems that some components take into account other props as well, when calcualting accessibilityState that gets passed to host component, e.g. TouchableOpacity also checks disabled prop. The current implementation already handles that but we might add some tests to verify it.

Comment thread src/queries/role.ts Outdated
Comment thread src/queries/role.ts Outdated
Comment thread src/queries/role.ts Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we simplify this test to only contain a single TouchableOpacity with disabled={true}?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Those three RN component use different implementation behind the hood, so my goal was to test all of them (TouchableOpacity and TouchableHighlight extend TouchableWithoutFeedback), and I felt like covering our bases.

On the other hand I do see your point, since we're just testing RN internal implementation.

I'll keep the three ones, if you feel strongly about that (or splitting it in three tests) let me know).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It makes sense to test all three TouchablesXxx and I would also metion Pressable in that context. Maybe you can use test.each to automate testing over these component variants?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I tried, but the difference in types (Button doesn't use children), it leads to pretty ugly code, and I'd say that it's not worth it, it'll make the tests harder to read, and here it's fairly simple.

Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated
Comment thread src/queries/__tests__/role.test.tsx Outdated

@mdjastrzebski mdjastrzebski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The overall structure looks correct now 💯

I've added some comments related to various implementation details to polish things out.

We also need to have our documentation updated to account for new options.

I've logged a separate #1165 to fix make *ByA11yStates to have the same matching behaviour as in this PR.

Comment thread src/queries/role.ts Outdated
@AugustinLF

Copy link
Copy Markdown
Collaborator Author

@mdjastrzebski should have addressed all your comments I believe!

@mdjastrzebski

Copy link
Copy Markdown
Member

@AugustinLF I'll need pause a couple of days on open source work as I've got cold-like symptoms. I'll review the PRs as soon as I get better.

@mdjastrzebski mdjastrzebski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've done a final round of review. Overall looks very good for me:

  • All the logic seems correct
  • we have a comprehensive set of tests

I've left two readability/style final comments & requested to document behaviour around defaulting or not to false for each prop.

I didn't give approve, only because as I worry that @thymikee could merge it before addressing these ;-)

Comment thread src/queries/role.ts Outdated
Comment thread src/queries/role.ts Outdated
Comment thread website/docs/Queries.md Outdated
@AugustinLF

Copy link
Copy Markdown
Collaborator Author

@mdjastrzebski a bit delayed, but everything should have been addressed now :)

@AugustinLF
AugustinLF force-pushed the feat/by-role-accessibilityStates-support branch from 2f11472 to 3e01734 Compare October 19, 2022 14:12
@AugustinLF

Copy link
Copy Markdown
Collaborator Author

Also added typedefs following the changes in #1175, see 3e01734

Comment thread website/docs/Queries.md Outdated
Comment thread website/docs/Queries.md Outdated
Comment thread website/docs/Queries.md Outdated

@mdjastrzebski mdjastrzebski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome work @AugustinLF!

*ByRole gets really powerful these days: first name, and now a11y states

@mdjastrzebski

Copy link
Copy Markdown
Member

Let's merge it!

@mdjastrzebski
mdjastrzebski merged commit 7ae763f into callstack:main Oct 20, 2022
@AugustinLF

Copy link
Copy Markdown
Collaborator Author

Thanks for the help! When are we shipping a new release, we've had at least two improvements to getByRole in since 11.2 👀

@AugustinLF
AugustinLF deleted the feat/by-role-accessibilityStates-support branch October 20, 2022 11:30
@mdjastrzebski

Copy link
Copy Markdown
Member

I could do a release on Friday if I will have enough time

@mdjastrzebski

Copy link
Copy Markdown
Member

@AugustinLF we've published 11.3.0 a couple of days ago, but I just created a release docs in GH: https://github.com/callstack/react-native-testing-library/releases/tag/v11.3.0

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.

Supports accessibilityStates in ByRole queries

2 participants