-
Notifications
You must be signed in to change notification settings - Fork 2
CPLAT-14309 - adding support for multiple testIds per element #11
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
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
Merge Requirements Met ✅Request Rosie to automerge this pull request by including @Workiva/release-management-p in a comment. General InformationTicket(s): Code Review(s): #11 Reviewers: aaronlademann-wf, sydneyjodon-wk Additional InformationWatchlist Notifications: None
Note: This is a shortened report. Click here to view Rosie's full evaluation. |
Public API ChangesNo changes to the public API found for commit f8cfe96 Showing results for f8cfe96
Last edited UTC May 27 at 13:56:51 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like current tests will need to be updated to expect the "regex" flavor of failure message instead of a string one. Those tests are nested pretty deep in a bunch of shared test logic though, so if you want me to pitch in there or pair up with you - lets do it.
Also - you need to format changes before you commit each time. You can either run pub run dart_dev format
in your terminal, or I can show you how to set that up to just happen on file save in your IDE.
'data-test-id': 'testId1 testId2', | ||
}, 'Testing multiple'), | ||
react.span({ | ||
'data-test-id': 'single', | ||
}, 'Testing single')) as ReactElement); | ||
}); | ||
|
||
test('[match]', () { | ||
expect(renderResult.getByTestId('testId1'), isA<SpanElement>()); | ||
expect(renderResult.getByTestId('testId2'), isA<SpanElement>()); | ||
expect(renderResult.getByTestId('single'), isA<SpanElement>()); | ||
expect( | ||
renderResult.getByTestId(RegExp('single')), isA<SpanElement>()); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be a good idea to have a third test id in there as well to assert that the match doesn't have to be at the beginning or end of the attribute value.
I'd also add a test that involves test id's that have characters like -
/ _
, etc.
+ So that the user doesn’t see an error for a RegExp value they didn’t provide, and so we don’t have to rewrite a ton of test expectations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just had a couple comments on tests.
lib/src/dom/queries/by_testid.dart
Outdated
try { | ||
return jsQuery(TextMatch.toJs(testId)); | ||
} catch (e) { | ||
errorCaughtUsingStringTestIdValue = e; | ||
|
||
try { | ||
// Try using a regex to do a word match within the attribute value in case the element has multiple test ids. | ||
return jsQuery(_convertTestIdStringToRegExp(testId, exact: exact)); | ||
} catch (_) { | ||
// Even the string converted to regex didn't match, which means the string passed was not found at all. | ||
// Throw the original error that was thrown as a result of the string provided since that is how the | ||
// user authored it so that the failure message displayed to the user doesn't contain a strange regex | ||
// that they didn't write. | ||
throw TestingLibraryElementError.fromJs(errorCaughtUsingStringTestIdValue); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there we have something like this where one element has just one test id and the other has multiple:
react.span({
'data-test-id': 'testId3',
}, 'Testing single'),
react.div({
'data-test-id': 'testId3 testId4',
}, 'Testing allBy')
won't this just return the span
because an error wouldn't have been thrown so it never gets the chance to add the regex and get the div
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can there be a test case for something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, you're right—this doesn't account for those test cases. This also affects error throws if ...ByTestId
detects multiple. Looking into this. Thanks Sydney
lib/src/dom/queries/by_testid.dart
Outdated
if (testId is String && jsQueryResult.isEmpty) { | ||
return jsQuery(_convertTestIdStringToRegExp(testId, exact: exact)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above for this logic.
…o CPLAT-14309-getTestId-multiple-ids
…LAT-14309-getTestId-multiple-ids
I added (and continuing to add) the full range of tests for test-id queries so ensure we're not losing base functionality as we add on this multi-ID check. Still a few failing tests (outside of |
This reverts commit 8fb4c75. # Conflicts: # lib/src/dom/queries/by_testid.dart
…s_adl Provide error messages with string test ids as authored to consumers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+10
- CI passes
- Good test coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@Workiva/release-management-pp
@aaronlademann-wf I will not merge this because:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Workiva/release-management-p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 from RM
Thread:
https://workiva.slack.com/archives/GFELW7RRB/p1621465412019400
Ticket:
https://jira.atl.workiva.net/browse/CPLAT-14309