-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle network error for SUSE Manager settings (#2470)
* Handle network error for SUSE Manager settings * Render loading and error cases through a container in settings * Reorder tests * Use `false` instead of `null` to indicate absence of network error * Properly handle scenario --------- Co-authored-by: Jamie Rodriguez <jamie.rodriguez@suse.com> Co-authored-by: Nelson Kopliku <nelson.kopliku@suse.com>
- Loading branch information
1 parent
8469773
commit 1f10bf6
Showing
9 changed files
with
184 additions
and
28 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
assets/js/common/SuseManagerConfig/SuseManagerSettingsContainer.jsx
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,39 @@ | ||
import React from 'react'; | ||
|
||
import ConnectionErrorAntenna from '@static/connection-error-antenna.svg'; | ||
|
||
import LoadingBox from '@common/LoadingBox'; | ||
import NotificationBox from '@common/NotificationBox'; | ||
|
||
function SuseManagerSettingsContainer({ error, loading, children, onRetry }) { | ||
if (loading) { | ||
return ( | ||
<LoadingBox | ||
className="shadow-none rounded-lg" | ||
text="Loading Settings..." | ||
/> | ||
); | ||
} | ||
|
||
if (error) { | ||
return ( | ||
<NotificationBox | ||
icon={ | ||
<img | ||
src={ConnectionErrorAntenna} | ||
className="m-auto w-48" | ||
alt="Connection error" | ||
/> | ||
} | ||
title="Connection Error" | ||
text="Unable to load SUSE Manager configuration. Please try reloading this section." | ||
buttonText="Reload" | ||
buttonOnClick={onRetry} | ||
/> | ||
); | ||
} | ||
|
||
return children; | ||
} | ||
|
||
export default SuseManagerSettingsContainer; |
39 changes: 39 additions & 0 deletions
39
assets/js/common/SuseManagerConfig/SuseManagerSettingsContainer.test.jsx
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,39 @@ | ||
import React from 'react'; | ||
import { faker } from '@faker-js/faker'; | ||
|
||
import { screen, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import SuseManagerSettingsContainer from './SuseManagerSettingsContainer'; | ||
|
||
describe('ChecksCatalog CatalogContainer component', () => { | ||
it('should render the loading box', () => { | ||
const text = faker.lorem.paragraph(); | ||
|
||
render( | ||
<SuseManagerSettingsContainer> | ||
<p>{text}</p> | ||
</SuseManagerSettingsContainer> | ||
); | ||
|
||
expect(screen.getByText(text)).toBeVisible(); | ||
}); | ||
|
||
it('should render the notification box in loading state', () => { | ||
render(<SuseManagerSettingsContainer loading />); | ||
|
||
expect(screen.getByText('Loading Settings...')).toBeVisible(); | ||
}); | ||
|
||
it('should render the notification box with connection error', () => { | ||
render(<SuseManagerSettingsContainer error />); | ||
|
||
expect(screen.getByText('Connection Error')).toBeVisible(); | ||
expect( | ||
screen.getByText( | ||
'Unable to load SUSE Manager configuration. Please try reloading this section.' | ||
) | ||
).toBeVisible(); | ||
expect(screen.getByRole('button')).toHaveTextContent('Reload'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import SuseManagerConfig from './SuseManagerConfig'; | ||
import SuseManagerSettingsContainer from './SuseManagerSettingsContainer'; | ||
|
||
export default SuseManagerConfig; | ||
|
||
export { SuseManagerSettingsContainer }; |
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
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
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
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
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
Oops, something went wrong.