Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap system configuration elements in error boundary. (#10472)
* Wrap configlets in individual error boundaries. * Typing `ConfigurationsPage`. * Turning class into functional component. * Replacing `connect` with `useStore`. * Adding tests. * Extending console suppression. * Adding license header. * Use `Promise.allSettled` to make sure loaded flag is set in case of rejections. * Extracting helper components.
- Loading branch information
1 parent
59eaf3b
commit d919a44
Showing
8 changed files
with
384 additions
and
258 deletions.
There are no files selected for viewing
This file contains 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
254 changes: 0 additions & 254 deletions
254
graylog2-web-interface/src/pages/ConfigurationsPage.jsx
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
graylog2-web-interface/src/pages/ConfigurationsPage.test.tsx
This file contains 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,66 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import * as React from 'react'; | ||
import { render, screen } from 'wrappedTestingLibrary'; | ||
import asMock from 'helpers/mocking/AsMock'; | ||
import suppressConsole from 'helpers/suppressConsole'; | ||
|
||
import ConfigurationsPage from 'pages/ConfigurationsPage'; | ||
import usePluginEntities from 'views/logic/usePluginEntities'; | ||
import SidecarConfig from 'components/configurations/SidecarConfig'; | ||
|
||
jest.mock('views/logic/usePluginEntities'); | ||
jest.mock('components/configurations/SearchesConfig', () => () => <span>Search Configuration</span>); | ||
jest.mock('components/configurations/MessageProcessorsConfig', () => () => <span>Message Processors Configuration</span>); | ||
jest.mock('components/configurations/SidecarConfig'); | ||
|
||
const ComponentThrowingError = () => { | ||
throw Error('Boom!'); | ||
}; | ||
|
||
const ComponentWorkingFine = () => ( | ||
<span>It is all good!</span> | ||
); | ||
|
||
describe('ConfigurationsPage', () => { | ||
it('wraps core configuration elements with error boundary', async () => { | ||
asMock(usePluginEntities).mockReturnValue([]); | ||
|
||
asMock(SidecarConfig).mockImplementation(ComponentThrowingError); | ||
|
||
await suppressConsole(async () => { | ||
render(<ConfigurationsPage />); | ||
|
||
await screen.findByText('Message Processors Configuration'); | ||
await screen.findByText('Boom!'); | ||
}); | ||
}); | ||
|
||
it('wraps plugin configuration elements with error boundary', async () => { | ||
asMock(usePluginEntities).mockReturnValue([ | ||
{ configType: 'foo', component: ComponentThrowingError }, | ||
{ configType: 'bar', component: ComponentWorkingFine }, | ||
]); | ||
|
||
suppressConsole(() => { | ||
render(<ConfigurationsPage />); | ||
}); | ||
|
||
await screen.findByText('It is all good!'); | ||
await screen.findByText('Boom!'); | ||
}); | ||
}); |
Oops, something went wrong.