-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show errors when parsing Config (#957)
* Show errors when parsing Config * Move getConfig call to component * Update ConfigLoader.test.tsx * Wrap test in describe function
- Loading branch information
1 parent
4ac4f0a
commit 33581dc
Showing
8 changed files
with
117 additions
and
7 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
35 changes: 35 additions & 0 deletions
35
dashboard/src/components/ConfigLoader/ConfigLoader.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,35 @@ | ||
import { shallow } from "enzyme"; | ||
import context from "jest-plugin-context"; | ||
import * as React from "react"; | ||
|
||
import ConfigLoader from "."; | ||
import UnexpectedErrorPage from "../../components/ErrorAlert/UnexpectedErrorAlert"; | ||
import itBehavesLike from "../../shared/specs"; | ||
|
||
context("when the config is not ready", () => { | ||
itBehavesLike("aLoadingComponent", { | ||
component: ConfigLoader, | ||
props: { | ||
loaded: false, | ||
getConfig: jest.fn(), | ||
}, | ||
}); | ||
}); | ||
|
||
context("when there is an error", () => { | ||
it("renders the error details", () => { | ||
const wrapper = shallow( | ||
<ConfigLoader error={new Error("Wrong config!")} getConfig={jest.fn()} />, | ||
); | ||
expect(wrapper.find(UnexpectedErrorPage)).toExist(); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe("componentDidMount", () => { | ||
it("calls getConfig", () => { | ||
const getConfig = jest.fn(); | ||
shallow(<ConfigLoader getConfig={getConfig} />); | ||
expect(getConfig).toHaveBeenCalled(); | ||
}); | ||
}) |
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,31 @@ | ||
import * as React from "react"; | ||
|
||
import UnexpectedErrorPage from "../../components/ErrorAlert/UnexpectedErrorAlert"; | ||
import LoadingWrapper, { ILoadingWrapperProps } from "../../components/LoadingWrapper"; | ||
|
||
interface IConfigLoaderProps extends ILoadingWrapperProps { | ||
getConfig: () => void; | ||
error?: Error; | ||
} | ||
|
||
class ConfigLoader extends React.Component<IConfigLoaderProps> { | ||
public componentDidMount() { | ||
this.props.getConfig(); | ||
} | ||
|
||
public render() { | ||
const { error, ...otherProps } = this.props; | ||
if (error) { | ||
return ( | ||
<UnexpectedErrorPage | ||
raw={true} | ||
showGenericMessage={true} | ||
text={`Unable to load Kubeapps configuration: ${error.message}`} | ||
/> | ||
); | ||
} | ||
return <LoadingWrapper {...otherProps} />; | ||
} | ||
} | ||
|
||
export default ConfigLoader; |
25 changes: 25 additions & 0 deletions
25
dashboard/src/components/ConfigLoader/__snapshots__/ConfigLoader.test.tsx.snap
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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`when the config is not ready loading spinner matches the snapshot 1`] = ` | ||
<LoadingWrapper | ||
getConfig={ | ||
[MockFunction] { | ||
"calls": Array [ | ||
Array [], | ||
Array [], | ||
], | ||
} | ||
} | ||
loaded={false} | ||
type={0} | ||
/> | ||
`; | ||
|
||
exports[`when there is an error renders the error details 1`] = ` | ||
<UnexpectedErrorPage | ||
raw={true} | ||
showGenericMessage={true} | ||
text="Unable to load Kubeapps configuration: Wrong config!" | ||
title="Sorry! Something went wrong." | ||
/> | ||
`; |
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,3 @@ | ||
import ConfigLoader from "./ConfigLoader"; | ||
|
||
export default ConfigLoader; |
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