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

[tests] Migrate TraceIDSearchInput.test from Enzyme to RTL #1691

Merged

Conversation

anshgoyalevil
Copy link
Member

@anshgoyalevil anshgoyalevil commented Aug 16, 2023

Which problem is this PR solving?

  • This PR migrates the TraceIDSearchInput.test.js from Enzyme to RTL
  • Snapshot testing is replaced with specific expect statement
  • Part of: Remove dependency on enzyme #1668

How was this change tested?

  • Using yarn lint && yarn test-ci TraceIDSearchInput --coverage

Checklist

@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (a5c02b5) 96.01% compared to head (76a6dd6) 96.01%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1691   +/-   ##
=======================================
  Coverage   96.01%   96.01%           
=======================================
  Files         241      241           
  Lines        7560     7560           
  Branches     1985     1985           
=======================================
  Hits         7259     7259           
  Misses        301      301           
Files Changed Coverage Δ
...aeger-ui/src/components/App/TraceIDSearchInput.tsx 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -36,7 +36,12 @@ class TraceIDSearchInput extends React.PureComponent<Props> {

render() {
return (
<Form layout="horizontal" onSubmit={this.goToTrace} className="TraceIDSearchInput--form">
<Form
aria-label="form"
Copy link
Member

Choose a reason for hiding this comment

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

Form as HTML element is generally invisible to user, how does accessibility label help? I think it would make more sense on the <input> with label "trace ID"

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Though, I am treating aria-label as a selector inside the rendered dom, we can have it on <input> too.

Should I go ahead adding another expect statement, to the input field as well? The more tests, the better testing regime would it be.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think testing needs is a good reason to add (permanent) attributes to HTML if they don't improve the HTML itself. I would suggest finding other ways to locate elements for tests.

Copy link
Member

Choose a reason for hiding this comment

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

Also, because form itself is invisible for the user, if some test is written that requires access to the form then the test probably does not pass the principles of testing established by RTL, "test from user perspective".

Copy link
Member Author

Choose a reason for hiding this comment

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

We can use data-test-id as a replacement for that. Going ahead with that approach.

Copy link
Member Author

@anshgoyalevil anshgoyalevil Aug 16, 2023

Choose a reason for hiding this comment

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

does not pass the principles of testing established by RTL, "test from a user perspective".

Yes, for that reason only, E2E tests work best in frontend testing, since they simulate the actual user behavior using a headless browser API.
Component testing always comes with such demerits.

@@ -27,7 +27,7 @@ const packageNames = [
...babelConfiguration.plugins,
];

const otherPackages = ['jest-environment-jsdom'];
const otherPackages = ['jest-environment-jsdom', 'babel-plugin-react-remove-properties'];
Copy link
Member

Choose a reason for hiding this comment

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

wait, why is it not auto-discovered from babelrc? I don't see babelrc change, isn't it necessary to make babel actually use the plugin, not just install it as dep?

Copy link
Member Author

@anshgoyalevil anshgoyalevil Aug 16, 2023

Choose a reason for hiding this comment

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

We are not using Babel plugins for production builds.

I was also confused earlier since we have a babel-transform.js file. I tried adding the plugin to that file, but it didn't work.
Later realized that it is only being used for tests, and not for builds.

For builds, we are using vite.config.js and depcheck can't find that out that we are using the babel plugin inside vite.config.js

Copy link
Member

Choose a reason for hiding this comment

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

that means we should parse vite config, in addition to babel cfg, when generating exclusion list for depcheck

Copy link
Member Author

Choose a reason for hiding this comment

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

Parsing it seems tricky. I applied another workaround, since depcheck by default supports .babelrc files.

Signed-off-by: Ansh Goyal <[email protected]>
@yurishkuro yurishkuro enabled auto-merge (squash) August 16, 2023 19:13
@yurishkuro yurishkuro disabled auto-merge August 16, 2023 19:14
@yurishkuro yurishkuro changed the title Migrate TraceIDSearchInput.test from Enzyme to RTL [tests] Migrate TraceIDSearchInput.test from Enzyme to RTL Aug 16, 2023
@yurishkuro yurishkuro enabled auto-merge (squash) August 16, 2023 19:15
@yurishkuro yurishkuro merged commit cebc608 into jaegertracing:main Aug 16, 2023
@anshgoyalevil anshgoyalevil deleted the TraceIDSearchInput.test.js branch August 16, 2023 19:44
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.

2 participants