From 1423697967d6483dcfd18e1ebb7fe50c65cebc2d Mon Sep 17 00:00:00 2001 From: Radek Podrazky Date: Tue, 3 Oct 2023 17:44:12 +0200 Subject: [PATCH] fix(Signal): handle unknown value gracefully Closes UXD-1255 --- src/components/Signal/Signal.test.tsx | 36 +++++++++++++++++++++++++++ src/components/Signal/Signal.tsx | 9 +++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/components/Signal/Signal.test.tsx diff --git a/src/components/Signal/Signal.test.tsx b/src/components/Signal/Signal.test.tsx new file mode 100644 index 000000000..ae642350d --- /dev/null +++ b/src/components/Signal/Signal.test.tsx @@ -0,0 +1,36 @@ +import { screen } from '@testing-library/react'; +import React from 'react'; + +import { renderWithProviders } from '../../utils/tests/renderWithProviders'; +import { Signal } from './index'; + +describe('Signal', () => { + it('should not render if empty "kind" prop is provided', () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + renderWithProviders(); + + expect(screen.queryByTestId('ds-severity-icon')).not.toBeInTheDocument(); + }); + it('should not render if "kind" prop is null', () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + renderWithProviders(); + + expect(screen.queryByTestId('ds-severity-icon')).not.toBeInTheDocument(); + }); + it('should not render if "kind" prop is undefined', () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + renderWithProviders(); + + expect(screen.queryByTestId('ds-severity-icon')).not.toBeInTheDocument(); + }); + it('should not render if unknown "kind" prop is provided', () => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + renderWithProviders(); + + expect(screen.queryByTestId('ds-severity-icon')).not.toBeInTheDocument(); + }); +}); diff --git a/src/components/Signal/Signal.tsx b/src/components/Signal/Signal.tsx index 1b1e038da..16b6c6e2b 100644 --- a/src/components/Signal/Signal.tsx +++ b/src/components/Signal/Signal.tsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { prop } from 'ramda'; -import { isNilOrEmpty } from 'ramda-adjunct'; +import { isNilOrEmpty, isUndefined } from 'ramda-adjunct'; import cls from 'classnames'; import { colors } from '../../theme/colors'; @@ -68,11 +68,16 @@ const Signal: React.FC = ({ }) => { if (isNilOrEmpty(kind)) return null; - const { color, paths } = prop(kind.toLowerCase())(kinds); + const severityKind = prop(kind.toLowerCase(), kinds); + + if (isUndefined(severityKind)) return null; + + const { color, paths } = severityKind; return (