Fix bug in XCMetrics plugin where invalid build statuses led to crashes

Signed-off-by: Niklas Granander <ngranander@spotify.com>
This commit is contained in:
Niklas Granander
2021-12-01 19:49:39 +01:00
parent b7b33e0293
commit af09b1e059
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 />;