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

ui: Tests on react-routing components #44078

Merged
merged 20 commits into from
Jan 30, 2020
Merged

Conversation

koorosh
Copy link
Collaborator

@koorosh koorosh commented Jan 16, 2020

Depends on PR: #43846
yarn-vendor PR has to be merged: cockroachdb/yarn-vendored#15

Current PR includes minimal changes to functionality (only those which are required to isolate or get
access to individual components under tests):

  • src/index.tsx file has been refactored into two parts: rendering to DOM and independent App component;
  • component (react-helmet library) has been refactored to avoid known issue during tests execution (Uncaught RangeError: Maximum call stack size exceeded nfl/react-helmet#373)
  • old version of react-router and connect component in tandem do not work well because connected
    component aren't valid react components. As result validation for correct routing was done by re-exporting wrapped components (instead of connected). It allowed to simplify testing with enzyme#find function which requires valid react component as an argument;
  • Tests are grouped in suites per route to maintain related tests per route;
  • There is two kinds of tests which test correct rendering of component for
    specific test and another test which validates correct redirection for routes;
  • Tests can be refactored to be constructed from configuration to reduce repeated
    tests, but it will be actual after migrating to latest version of react-router lib.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@koorosh koorosh marked this pull request as ready for review January 24, 2020 15:28
@koorosh koorosh requested a review from a team January 24, 2020 15:28
@dhartunian dhartunian changed the base branch from master to staging January 27, 2020 16:37
@dhartunian dhartunian changed the base branch from staging to master January 27, 2020 16:37
@koorosh koorosh changed the title ui: Tests on components routing ui: Tests on react-routing components Jan 30, 2020
@koorosh koorosh changed the base branch from master to staging January 30, 2020 09:29
@koorosh koorosh changed the base branch from staging to master January 30, 2020 09:30
With current changes, react is upgraded to latest version (16.12.0) and
following libraries are upgraded as well: react-redux, redux, redux-saga.
These upgrades of major versions has required to do some code adjustments
to properly migrate to newest versions.
- redux. Provide valid type arguments for Dispatch type.
- redux-saga. Changed import and usage of 'delay' function.
- react-redux. `connect` function failed to correctly resolve returned type
for `mapDispatchToProps` argument. As result it is provided as a function
instead of object argument. This hack allows implicitly resolve types.
- `CachedDataReducer` class is extended with one more optional type argument
to specify the list of allowed `actionNamespace` literals instead of `string`.
It was necessary to have strictly defined CachedDataReducer interface.
- `normalizeConnectedComponent` function is used to do simple mapping from
react's ExoticComponent to valid react component. This resolves issue of
providing ConnectedComponents (which are ExoticComponent's, not regular react
components) to Route component which has strict type validation of component types.

Release note: None
- tests command is disabled for now because current state doesn't
contain all fixes to run tests without failure.
- Decommissioned Node History page was added so code has to be adjusted.

Release note: None
- Decoupled App from rendering app into DOM.
- Defined tests structure and initial tests.

Release note: None
- Karma produced warning messages related to compilation of .ts|.tsx files to .js
due to incorrect webpack configuration.
- Added macha reporter to get readable test reports.

Release note: None
- Tests are grouped in suites per route to maintain related tests per route;
- There is two kinds of tests which test correct rendering of component for
specific test and another test which validates correct redirection for routes;
- Tests can be refactored to be constructed from configuration to reduce repeated
tests, but it will be actual after migrating to latest version of react-router lib.
- Added additional exports for components which is wrapped by Connect HOC because
connect doesn't return valid react component, as result `enzym` library cannot find
wrapped component in mounted components tree. This can be changed back with latest
version of `react-router` + `react-connected-router` library which don't have this issue.

Release note: None
Release note: None
Change back subscription to alertDataSync out of App context so
it doesn't break existing behaviour.

Release note: None
- Wrap NodeCanvasContainer and statementsPage components with `bindActionCreators`
- Add route for DecommissionedNodeHistory page

Release note: None
Release note: None
Testing with Enzyme framework is straight-froward and easy, but there is once
gotcha: ConnectedComponents (wrapped with Connect function) are not recognized
by Enzyme as react components and it is not possible to use enzymeWrapper.find(Component)
helper function to check whether connected component is rendered in DOM or not.

To make it clear there is an example how Connected Component is recognized in dom:
```
<[object Object] location={{...}} params={{...}} route={{...}} ...
```
as [object] not a Component.

To overcome this problem "not connected" child components are exported in
addition to connected. It allows to write tests against these components.

Release note: None
It is not necessary to wrap action creator object
with function when connecting it to component.

Release note: None
- Remove unnecessary re-exporting from index.ts file
- Simplify exporting of DecommissionedNodeList component

Release note: None
@dhartunian
Copy link
Collaborator

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 30, 2020

Build failed (retrying...)

craig bot pushed a commit that referenced this pull request Jan 30, 2020
44078: ui: Tests on react-routing components r=dhartunian a=Koorosh

Depends on PR: #43846
`yarn-vendor` PR has to be merged: cockroachdb/yarn-vendored#15

Current PR includes minimal changes to functionality (only those which are required to isolate or get
access to individual components under tests):
- `src/index.tsx` file has been refactored into two parts: rendering to DOM and independent `App` component;
-  <Helmet> component (`react-helmet` library) has been refactored to avoid known issue during tests execution (nfl/react-helmet#373)
- old version of react-router and `connect` component in tandem do not work well because connected
component aren't valid react components. As result validation for correct routing was done by re-exporting wrapped components (instead of connected). It allowed to simplify testing with `enzyme#find` function which requires valid react component as an argument;
- Tests are grouped in suites per route to maintain related tests per route;
- There is two kinds of tests which test correct rendering of component for
specific test and another test which validates correct redirection for routes;
- Tests can be refactored to be constructed from configuration to reduce repeated
tests, but it will be actual after migrating to latest version of react-router lib.

44545: sqlbase: add table generator for edge case datums r=rohany a=rohany

Part of work for #44322.

This PR adds a testing utility to generate a table
full of edge case datums to test a variety of things in the future.

Release note: None

Co-authored-by: Andrii Vorobiov <[email protected]>
Co-authored-by: Rohan Yadav <[email protected]>
@craig
Copy link
Contributor

craig bot commented Jan 30, 2020

Build succeeded

@craig craig bot merged commit 043019e into cockroachdb:master Jan 30, 2020
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.

3 participants