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

CIF-1657: [React Components] Clean up the unit tests warnings #419

Merged
merged 6 commits into from
Oct 22, 2020

Conversation

hbacila
Copy link
Contributor

@hbacila hbacila commented Oct 8, 2020

The unit tests for the React Components module all pass, but they throw a lot of warnings regarding missing props and the ever present "Warning: An update to XXXX inside a test was not wrapped in act(...)."

Description

This change fixes the warnings above. It also fixes a styling issue for AccountDetails/editForm due to empty editForm.css

Motivation and Context

We must cleanup these warnings as they can potentially hide some implementation issues.

How Has This Been Tested?

  • running unit test
  • verify if components render correctly

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

@codecov
Copy link

codecov bot commented Oct 8, 2020

Codecov Report

Merging #419 into master will decrease coverage by 1.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #419      +/-   ##
============================================
- Coverage     85.85%   84.84%   -1.01%     
  Complexity     1023     1023              
============================================
  Files           209      214       +5     
  Lines          5244     5320      +76     
  Branches        751      773      +22     
============================================
+ Hits           4502     4514      +12     
- Misses          593      657      +64     
  Partials        149      149              
Flag Coverage Δ Complexity Δ
#integration 67.60% <ø> (ø) 760.00 <ø> (ø)
#jest 79.22% <100.00%> (-2.48%) 0.00 <0.00> (ø)
#karma 93.96% <ø> (ø) 0.00 <ø> (ø)
#unittests 85.91% <ø> (ø) 991.00 <ø> (ø)

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

Impacted Files Coverage Δ Complexity Δ
...mponents/src/components/AccountDetails/editForm.js 100.00% <ø> (ø) 0.00 <0.00> (ø)
...src/components/AccountDetails/useAccountDetails.js 94.59% <ø> (ø) 0.00 <0.00> (ø)
...act-components/src/components/Password/password.js 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
react-components/src/utils/test-utils.js 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
react-components/src/actions/cart/actions.js 84.74% <0.00%> (-1.70%) 0.00% <0.00%> (ø%)
...eact-components/src/components/AuthBar/userChip.js 33.33% <0.00%> (ø) 0.00% <0.00%> (?%)
react-components/src/components/App/app.js 15.38% <0.00%> (ø) 0.00% <0.00%> (?%)
react-components/src/components/AuthBar/authBar.js 16.66% <0.00%> (ø) 0.00% <0.00%> (?%)
...act-components/src/components/AuthBar/container.js 14.28% <0.00%> (ø) 0.00% <0.00%> (?%)
...omponents/src/components/AuthBar/myAccountPanel.js 8.69% <0.00%> (ø) 0.00% <0.00%> (?%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8dfd9a...af18858. Read the comment docs.

@@ -17,6 +17,9 @@ const setCartCookie = jest.fn();
const setUserCookie = jest.fn();
const dispatch = jest.fn();

// avoid console errors logged during testing
console.error = jest.fn();
Copy link
Member

Choose a reason for hiding this comment

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

I would rather add the --silent parameter to the jest call than mocking the console.error calls here. This has the advantage that you can easily decide whether or not you want to print the console statements. Sometimes they are useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with --silent is that it supresses all console logs including the warnings that may indicate an issue (such the ones we fixed here).

<ConfigContextProvider config={configObject}>
<Component {...props} />
</ConfigContextProvider>
<I18nextProvider i18n={i18n}>
Copy link
Contributor

@dplaton dplaton Oct 12, 2020

Choose a reason for hiding this comment

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

Since this the root of our custom component tree that we use in a lot of tests I propose we decorate render so that it includes it automatically (like in https://github.com/adobe/aem-core-cif-components/blob/master/react-components/src/utils/test-utils.js#L105).
Same with ConfigContextProvider.

Alternately, we can mock useTranslation so that it doesn't require the context provider anymore. Either way, we should simplify our mock components

@mhaack mhaack added the bug Something isn't working label Oct 14, 2020
@dplaton dplaton self-requested a review October 14, 2020 08:10
Copy link
Contributor

@dplaton dplaton left a comment

Choose a reason for hiding this comment

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

Simplify the mock components so that they won't require the I18nextProvider and the ConfigContextProvider every time. For the latter, we can always provide the full configuration.
We can do the same for the MockedProvider, but we need to allow passing the mock array to the render function

…ls/test-utils.js) which decorates the mock component with MockedProvider, ConfigContextProvider, UserContextProvider and I18nextProvider
@hbacila
Copy link
Contributor Author

hbacila commented Oct 14, 2020

Refactored the unit tests so they all use the custom render (from utils/test-utils.js) which wraps the mock component with MockedProvider, ConfigContextProvider, UserContextProvider and I18nextProvider. The render's options parameter is extended with the following props:

  • config - provides configuration object for ConfigContextProvider
  • userContext - provides initialState for UserContextProvider
  • mocks - provides mocks data for MockedProvider

@hbacila hbacila requested a review from dplaton October 21, 2020 08:47
</UserContextProvider>
</MockedProvider>
);
const { getByTestId } = render(<ContextWrapper />, { mocks: mocks });
Copy link
Contributor

Choose a reason for hiding this comment

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

You can write {mocks} instead of {mocks: mocks} - shorthand notation in ES6

Copy link
Contributor

@dplaton dplaton left a comment

Choose a reason for hiding this comment

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

Great work! This would make the tests so much more readable.

@alkim91 alkim91 self-assigned this Oct 22, 2020
@alkim91 alkim91 self-requested a review October 22, 2020 01:42
@alkim91 alkim91 merged commit d33ee62 into master Oct 22, 2020
@alkim91 alkim91 deleted the issues/CIF-1657 branch October 22, 2020 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants