diff --git a/frontend/src/component/banners/Banner/Banner.test.tsx b/frontend/src/component/banners/Banner/Banner.test.tsx
new file mode 100644
index 0000000000..2f974d761f
--- /dev/null
+++ b/frontend/src/component/banners/Banner/Banner.test.tsx
@@ -0,0 +1,64 @@
+import { screen } from '@testing-library/react';
+import { render } from 'utils/testRenderer';
+import { Banner } from './Banner';
+
+test('should render correctly when using basic options', () => {
+ render(
+ ,
+ );
+
+ expect(
+ screen.getByText('This is a simple banner message.'),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId('WarningAmberIcon')).toBeInTheDocument();
+});
+
+test('should render correctly when using advanced options', () => {
+ render(
+ ,
+ );
+
+ expect(
+ screen.getByText('This is a more advanced banner message.'),
+ ).toBeInTheDocument();
+
+ const link = screen.getByText('Click me');
+ expect(link).toBeInTheDocument();
+ link.click();
+
+ expect(screen.getByText('Dialog title')).toBeInTheDocument();
+ expect(screen.getByText('Dialog content')).toBeInTheDocument();
+});
+
+test('should default to info variant when an invalid variant is provided', () => {
+ render(
+ ,
+ );
+
+ expect(
+ screen.getByText('This defaulted to an info banner message.'),
+ ).toBeInTheDocument();
+ expect(screen.getByTestId('InfoOutlinedIcon')).toBeInTheDocument();
+});
diff --git a/frontend/src/component/banners/Banner/Banner.tsx b/frontend/src/component/banners/Banner/Banner.tsx
index 652c6c0f74..818ef10521 100644
--- a/frontend/src/component/banners/Banner/Banner.tsx
+++ b/frontend/src/component/banners/Banner/Banner.tsx
@@ -13,6 +13,8 @@ import ReactMarkdown from 'react-markdown';
import { BannerVariant, IBanner } from 'interfaces/banner';
import { Sticky } from 'component/common/Sticky/Sticky';
+const DEFAULT_VARIANT = 'info';
+
const StyledBar = styled('aside', {
shouldForwardProp: (prop) =>
prop !== 'variant' && prop !== 'inline' && prop !== 'maxHeight',
@@ -36,9 +38,14 @@ const StyledBar = styled('aside', {
maxHeight: maxHeight,
overflow: 'auto',
}),
- borderColor: theme.palette[variant].border,
- background: theme.palette[variant].light,
- color: theme.palette[variant].dark,
+ borderColor:
+ theme.palette[variant]?.border ??
+ theme.palette[DEFAULT_VARIANT].border,
+ background:
+ theme.palette[variant]?.light ??
+ theme.palette[DEFAULT_VARIANT].light,
+ color:
+ theme.palette[variant]?.dark ?? theme.palette[DEFAULT_VARIANT].dark,
fontSize: theme.fontSizes.smallBody,
}),
);
@@ -48,7 +55,7 @@ const StyledIcon = styled('div', {
})<{ variant: BannerVariant }>(({ theme, variant }) => ({
display: 'flex',
alignItems: 'center',
- color: theme.palette[variant].main,
+ color: theme.palette[variant]?.main ?? theme.palette[DEFAULT_VARIANT].main,
}));
interface IBannerProps {
@@ -62,7 +69,7 @@ export const Banner = ({ banner, inline, maxHeight }: IBannerProps) => {
const {
message,
- variant = 'info',
+ variant = DEFAULT_VARIANT,
sticky,
icon,
link,