-
Notifications
You must be signed in to change notification settings - Fork 245
feat: validation errors on import COMPAS-8867 #6795
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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1682c2
wip
paula-stacho 814a699
feat: validation errors on import COMPAS-8867
paula-stacho 71b89e6
add unit test
paula-stacho 505d463
e2e tests
paula-stacho 41188f9
add files
paula-stacho f0603fa
close toast when entering details
paula-stacho 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
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
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
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
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
72 changes: 72 additions & 0 deletions
72
packages/compass-import-export/src/components/import-error-details-modal.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,72 @@ | ||
| import React from 'react'; | ||
| import { | ||
| render, | ||
| screen, | ||
| userEvent, | ||
| waitFor, | ||
| } from '@mongodb-js/testing-library-compass'; | ||
| import { expect } from 'chai'; | ||
| import { configureStore } from '../stores/import-store'; | ||
| import { Provider } from 'react-redux'; | ||
|
|
||
| import { createNoopLogger } from '@mongodb-js/compass-logging/provider'; | ||
| import { createNoopTrack } from '@mongodb-js/compass-telemetry/provider'; | ||
| import ImportErrorDetailsModal from './import-error-details-modal'; | ||
|
|
||
| function renderModal(importState: any = {}) { | ||
| // TODO: mutating state directly doesn't guarantee that we are testing the | ||
| // component in a state that can actually be achieved when actions are emitted | ||
| // on the store. Refactor this to either test unconnected component, or to | ||
| // not mutate state directly for tests | ||
| const store = configureStore({ | ||
| dataService: {}, | ||
| globalAppRegistry: {}, | ||
| logger: createNoopLogger(), | ||
| track: createNoopTrack(), | ||
| connections: { | ||
| getConnectionById: () => ({ info: { id: 'TEST' } }), | ||
| }, | ||
| } as any); | ||
| const state = store.getState(); | ||
| state.import = { | ||
| ...state.import, | ||
| ...importState, | ||
| }; | ||
| const renderResult = render( | ||
| <Provider store={store}> | ||
| <ImportErrorDetailsModal /> | ||
| </Provider> | ||
| ); | ||
| return { renderResult, store }; | ||
| } | ||
|
|
||
| describe('ImportErrorDetailsModal Component', function () { | ||
| context('When import error details are open', function () { | ||
| const errorDetails = { details: 'abc' }; | ||
|
|
||
| beforeEach(function () { | ||
| renderModal({ | ||
| errorDetails: { | ||
| isOpen: true, | ||
| details: errorDetails, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('Should render error details and be closable', async function () { | ||
| const codeDetails = await screen.findByTestId('error-details-json'); | ||
| expect(codeDetails).to.be.visible; | ||
| expect(JSON.parse(codeDetails.textContent || '')).to.deep.equal( | ||
| errorDetails | ||
| ); | ||
|
|
||
| const closeBtn = await screen.findByRole('button', { name: 'Close' }); | ||
| expect(closeBtn).to.be.visible; | ||
|
|
||
| userEvent.click(closeBtn); | ||
| await waitFor(() => { | ||
| expect(screen.queryByTestId('import-error-details-modal')).not.to.exist; | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
33 changes: 33 additions & 0 deletions
33
packages/compass-import-export/src/components/import-error-details-modal.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,33 @@ | ||
| import React from 'react'; | ||
| import { ErrorDetailsModal } from '@mongodb-js/compass-components'; | ||
| import { connect } from 'react-redux'; | ||
| import type { RootImportState } from '../stores/import-store'; | ||
| import { onErrorDetailsClose } from '../modules/import'; | ||
|
|
||
| const ImportErrorDetailsModal: React.FunctionComponent<{ | ||
| isOpen: boolean; | ||
| errorDetails?: Record<string, unknown>; | ||
| onClose: () => void; | ||
| }> = ({ isOpen, errorDetails, onClose }) => { | ||
| return ( | ||
| <ErrorDetailsModal | ||
| closeAction="close" | ||
| open={isOpen} | ||
| details={errorDetails} | ||
| onClose={onClose} | ||
| data-testid="import-error-details-modal" | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const ConnectedImportErrorDetailsModal = connect( | ||
| (state: RootImportState) => ({ | ||
| isOpen: state.import.errorDetails.isOpen, | ||
| errorDetails: state.import.errorDetails.details, | ||
| }), | ||
| { | ||
| onClose: onErrorDetailsClose, | ||
| } | ||
| )(ImportErrorDetailsModal); | ||
|
|
||
| export default ConnectedImportErrorDetailsModal; |
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
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
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.
Can we close those toast when the user clicks to see the error? We currently will keep showing the toast when the modal is open, but the dismiss is not clickable as I the modal is capturing all of the clicks. I think there's a similar issue with the toast on connectivity issues, not the end of the world if it's not easily feasible, a nice to have.

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.
fixed!