diff --git a/packages/module/src/ChatbotFooter/ChatbotFooternote.test.tsx b/packages/module/src/ChatbotFooter/ChatbotFooternote.test.tsx index 9a34337a..01f6a93f 100644 --- a/packages/module/src/ChatbotFooter/ChatbotFooternote.test.tsx +++ b/packages/module/src/ChatbotFooter/ChatbotFooternote.test.tsx @@ -1,6 +1,9 @@ import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'; import ChatbotFootnote from './ChatbotFootnote'; +const POPOVER_CLOSE_ERROR = + 'ChatbotFootnote: You must provide either the popover.cta or popover.showClose props in order to render a button that can close the popover.'; + describe('ChatbotFooternote', () => { const onClick = jest.fn(); const popoverProps = { @@ -20,11 +23,58 @@ describe('ChatbotFooternote', () => { } }; + let consoleErrorSpy: jest.SpyInstance; + + beforeEach(() => { + consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn()); + }); + + afterEach(() => { + consoleErrorSpy.mockRestore(); + }); + it('should render ChatbotFooternote', () => { render(); expect(screen.getByText('Chatbot footer')).toBeTruthy(); }); + it('should not log a console error when no popover is provided', () => { + render(); + expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR); + }); + + it('should not log a console error when popover has a cta', () => { + render(); + expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR); + }); + + it('should not log a console error when popover has showClose', () => { + render( + + ); + expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR); + }); + + it('should log a console error when popover is provided without cta or showClose', () => { + render( + + ); + expect(consoleErrorSpy).toHaveBeenCalledWith(POPOVER_CLOSE_ERROR); + }); + it('should render ChatbotFooternote with popover', async () => { render(); diff --git a/packages/module/src/ChatbotFooter/ChatbotFootnote.tsx b/packages/module/src/ChatbotFooter/ChatbotFootnote.tsx index f948e26b..be021352 100644 --- a/packages/module/src/ChatbotFooter/ChatbotFootnote.tsx +++ b/packages/module/src/ChatbotFooter/ChatbotFootnote.tsx @@ -63,7 +63,7 @@ export const ChatbotFootnote: FunctionComponent = ({ className, ...props }: ChatbotFootnoteProps) => { - if (!popover?.cta && !popover?.showClose) { + if (popover && !popover.cta && !popover.showClose) { // eslint-disable-next-line no-console console.error( 'ChatbotFootnote: You must provide either the popover.cta or popover.showClose props in order to render a button that can close the popover.'