-
Notifications
You must be signed in to change notification settings - Fork 245
fix(compass-global-writes): handle loading error COMPASS-8446 #6451
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/compass-global-writes/src/components/states/loading-error.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
| import { expect } from 'chai'; | ||
| import { screen } from '@mongodb-js/testing-library-compass'; | ||
| import { LoadingError } from './loading-error'; | ||
| import { renderWithStore } from '../../../tests/create-store'; | ||
|
|
||
| const error = 'Test failure'; | ||
|
|
||
| function renderWithProps( | ||
| props?: Partial<React.ComponentProps<typeof LoadingError>> | ||
| ) { | ||
| return renderWithStore(<LoadingError error={error} {...props} />); | ||
| } | ||
|
|
||
| describe('LoadingError', function () { | ||
| it('renders the error', async function () { | ||
| await renderWithProps(); | ||
| expect(screen.getByText(error)).to.exist; | ||
| }); | ||
| }); |
26 changes: 26 additions & 0 deletions
26
packages/compass-global-writes/src/components/states/loading-error.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React from 'react'; | ||
| import { ErrorSummary } from '@mongodb-js/compass-components'; | ||
| import { connect } from 'react-redux'; | ||
| import { type RootState, ShardingStatuses } from '../../store/reducer'; | ||
| import { containerStyles } from '../common-styles'; | ||
|
|
||
| interface LoadingErrorProps { | ||
| error: string; | ||
| } | ||
|
|
||
| export function LoadingError({ error }: LoadingErrorProps) { | ||
| return ( | ||
| <div className={containerStyles}> | ||
| <ErrorSummary errors={error} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default connect((state: RootState) => { | ||
| if (state.status !== ShardingStatuses.LOADING_ERROR) { | ||
| throw new Error('Error not found in LoadingError'); | ||
| } | ||
| return { | ||
| error: state.loadingError, | ||
| }; | ||
| })(LoadingError); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This special test api being a catch-all for all the tests in this file is getting a bit hard to read from my perspective, especially because it seems like most of these methods are added for just one test case. If you need a one-off mocking / stubbing for a special test case like that I would really recommend doing it right in your test:
That way you're not binding your test to a shared mock implementation which usually makes tests easier to maintain in the long run and easier to understand what's being mocked when reading through the test case
Uh oh!
There was an error while loading. Please reload this page.
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 get your point, but in this case the tests were getting very verbose and difficult to read because 'authenticatedFetch' handles 4 different things. So often the tests were repeating the whole auth fetch mock logic section only to change 1 thing. The only one that would be easy to mock and only used once would be
failsToFetchClusterDetails- because that is the very first request that happens in the flow, and it's only on init. That one I did just for consistency.