Merge pull request #8313 from ngranander/xcmetrics/bugfix

[XCMetrics] Handle invalid build statuses
This commit is contained in:
Patrik Oldsberg
2021-12-02 11:22:25 +01:00
committed by GitHub
3 changed files with 15 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-xcmetrics': patch
---
Fix bug where invalid build statuses led to crashes
@@ -17,6 +17,7 @@
import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { StatusIcon } from './StatusIcon';
import { BuildStatus } from '../../api';
describe('StatusIcon', () => {
it('should render', async () => {
@@ -31,4 +32,11 @@ describe('StatusIcon', () => {
rendered = await renderInTestApp(<StatusIcon buildStatus="stopped" />);
expect(rendered.getByLabelText('Status warning')).toBeInTheDocument();
});
it('should render invalid statuses', async () => {
const rendered = await renderInTestApp(
<StatusIcon buildStatus={'invalid' as BuildStatus} />,
);
expect(rendered.getByLabelText('Status aborted')).toBeInTheDocument();
});
});
@@ -15,6 +15,7 @@
*/
import React from 'react';
import {
StatusAborted,
StatusError,
StatusOK,
StatusWarning,
@@ -32,4 +33,4 @@ interface StatusIconProps {
}
export const StatusIcon = ({ buildStatus }: StatusIconProps) =>
STATUS_ICONS[buildStatus];
STATUS_ICONS[buildStatus] ?? <StatusAborted />;