Skip to content

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

Merged
merged 20 commits into from
May 28, 2021

Conversation

brianphillips-wk
Copy link
Contributor

@aviary2-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

@rmconsole-wf
Copy link

rmconsole-wf commented May 24, 2021

Merge Requirements Met ✅

Request Rosie to automerge this pull request by including @Workiva/release-management-p in a comment.

General Information

Ticket(s):

Code Review(s): #11
Release Image Tags:

Reviewers: aaronlademann-wf, sydneyjodon-wk

Additional Information

Watchlist Notifications: None

	When this pull is merged I will add it to the following release:
	Current version: react_testing_library 0.3.3
	Version after merge: react_testing_library 0.3.3
	Release Ticket(s): RM-104146

	This pull is considered a release pull
	The options defined for this repo will be carried out


Note: This is a shortened report. Click here to view Rosie's full evaluation.
Last updated on Friday, May 28 03:08 PM CST

@brianphillips-wk brianphillips-wk removed their assignment May 24, 2021
@semveraudit-wf
Copy link

semveraudit-wf commented May 24, 2021

Public API Changes

No changes to the public API found for commit f8cfe96

Showing results for f8cfe96

Powered by semver-audit-service. Please report any problems by filing an issue.
Reported by the dart semver audit client 2.2.1
Browse public API.

Last edited UTC May 27 at 13:56:51

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a 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.

Comment on lines 45 to 58
'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>());
});
Copy link
Contributor

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.
Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a 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.

@brianphillips-wk brianphillips-wk removed the request for review from greglittlefield-wf May 25, 2021 17:07
Comment on lines 180 to 196
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);
}
}
}
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines 290 to 292
if (testId is String && jsQueryResult.isEmpty) {
return jsQuery(_convertTestIdStringToRegExp(testId, exact: exact));
}
Copy link
Contributor

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.

@brianphillips-wk
Copy link
Contributor Author

brianphillips-wk commented May 26, 2021

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 by_testid-test.dart), so investigating that. We tried adding a try...catch to account for test result mismatches on some older tests, but that caused some troubles on the core logic of this fix. Werkin on it!

aaronlademann-wf and others added 3 commits May 26, 2021 15:33
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
Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a 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

Copy link
Contributor

@aaronlademann-wf aaronlademann-wf left a 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

@rmconsole-wf
Copy link

@aaronlademann-wf I will not merge this because:

  • 'All commits reviewed' is False
  • Last commit does not have code review

Copy link
Contributor

@sydneyjodon-wk sydneyjodon-wk left a 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

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole2-wf rmconsole2-wf deleted the CPLAT-14309-getTestId-multiple-ids branch May 28, 2021 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants