Merge pull request #9366 from backstage/emmaindal/error-page
[ErrorPage] adjust accepted properties
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/core-components': patch
|
||||
---
|
||||
|
||||
Adjust ErrorPage to accept optional supportUrl property to override app support config. Update type of additionalInfo property to be ReactNode to accept both string and component.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { ErrorPage } from './ErrorPage';
|
||||
import { Link } from '../../components/Link';
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
|
||||
describe('<ErrorPage/>', () => {
|
||||
@@ -30,4 +31,72 @@ describe('<ErrorPage/>', () => {
|
||||
).toBeInTheDocument();
|
||||
expect(getByTestId('go-back-link')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render with additional information of type string', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<ErrorPage
|
||||
status="404"
|
||||
statusMessage="PAGE NOT FOUND"
|
||||
additionalInfo="This is a string based additional information"
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
getByText(/looks like someone dropped the mic!/i),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
getByText(/This is a string based additional information/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render with additional information including link', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<ErrorPage
|
||||
status="404"
|
||||
statusMessage="PAGE NOT FOUND"
|
||||
additionalInfo={
|
||||
<>
|
||||
This is some additional information including{' '}
|
||||
<Link to="/test">a link</Link>
|
||||
</>
|
||||
}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
getByText(/looks like someone dropped the mic!/i),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText(/a link/i)).toBeInTheDocument();
|
||||
expect(getByText(/a link/i)).toHaveAttribute('href', '/test');
|
||||
});
|
||||
|
||||
it('should render with default support url if supportUrl is not provided', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<ErrorPage status="404" statusMessage="PAGE NOT FOUND" />,
|
||||
);
|
||||
expect(
|
||||
getByText(/looks like someone dropped the mic!/i),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText(/contact support/i)).toBeInTheDocument();
|
||||
expect(getByText(/contact support/i)).toHaveAttribute(
|
||||
'href',
|
||||
'https://github.com/backstage/backstage/issues',
|
||||
);
|
||||
});
|
||||
|
||||
it('should override support url if supportUrl property is provided', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<ErrorPage
|
||||
status="404"
|
||||
statusMessage="PAGE NOT FOUND"
|
||||
supportUrl="https://error-page-test-support-url.com"
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
getByText(/looks like someone dropped the mic!/i),
|
||||
).toBeInTheDocument();
|
||||
expect(getByText(/contact support/i)).toBeInTheDocument();
|
||||
expect(getByText(/contact support/i)).toHaveAttribute(
|
||||
'href',
|
||||
'https://error-page-test-support-url.com',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,7 +27,8 @@ import { MicDrop } from './MicDrop';
|
||||
interface IErrorPageProps {
|
||||
status: string;
|
||||
statusMessage: string;
|
||||
additionalInfo?: string;
|
||||
additionalInfo?: React.ReactNode;
|
||||
supportUrl?: string;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
@@ -62,7 +63,7 @@ const useStyles = makeStyles<BackstageTheme>(
|
||||
*
|
||||
*/
|
||||
export function ErrorPage(props: IErrorPageProps) {
|
||||
const { status, statusMessage, additionalInfo } = props;
|
||||
const { status, statusMessage, additionalInfo, supportUrl } = props;
|
||||
const classes = useStyles();
|
||||
const navigate = useNavigate();
|
||||
const support = useSupportConfig();
|
||||
@@ -88,7 +89,8 @@ export function ErrorPage(props: IErrorPageProps) {
|
||||
<Link to="#" data-testid="go-back-link" onClick={() => navigate(-1)}>
|
||||
Go back
|
||||
</Link>
|
||||
... or please <Link to={support.url}>contact support</Link> if you
|
||||
... or please{' '}
|
||||
<Link to={supportUrl || support.url}>contact support</Link> if you
|
||||
think this is a bug.
|
||||
</Typography>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user