Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions packages/module/src/ChatbotFooter/ChatbotFooternote.test.tsx
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -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(<ChatbotFootnote label="Chatbot footer" />);
expect(screen.getByText('Chatbot footer')).toBeTruthy();
});

it('should not log a console error when no popover is provided', () => {
render(<ChatbotFootnote label="Chatbot footer" />);
expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR);
});

it('should not log a console error when popover has a cta', () => {
render(<ChatbotFootnote label="Chatbot footer" popover={popoverProps} />);
expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR);
});

it('should not log a console error when popover has showClose', () => {
render(
<ChatbotFootnote
label="Chatbot footer"
popover={{
title: 'Verify accuracy',
description: 'description',
showClose: true
}}
/>
);
expect(consoleErrorSpy).not.toHaveBeenCalledWith(POPOVER_CLOSE_ERROR);
});

it('should log a console error when popover is provided without cta or showClose', () => {
render(
<ChatbotFootnote
label="Chatbot footer"
popover={{
title: 'Verify accuracy',
description: 'description'
}}
/>
);
expect(consoleErrorSpy).toHaveBeenCalledWith(POPOVER_CLOSE_ERROR);
});

it('should render ChatbotFooternote with popover', async () => {
render(<ChatbotFootnote label="Chatbot footer" popover={popoverProps} />);

Expand Down
2 changes: 1 addition & 1 deletion packages/module/src/ChatbotFooter/ChatbotFootnote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const ChatbotFootnote: FunctionComponent<ChatbotFootnoteProps> = ({
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.'
Expand Down
Loading