import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import ChatbotToggle from './ChatbotToggle';
describe('ChatbotToggle', () => {
it('should render tooltipLabel correctly', async () => {
render();
await userEvent.click(screen.getByRole('button', { name: /Tooltip toggle/i }));
expect(screen.getByRole('tooltip', { name: /Tooltip/i })).toBeTruthy();
});
it('should render toggleButtonLabel correctly', async () => {
render();
expect(screen.getByRole('button', { name: /Button/i })).toBeTruthy();
});
it('should call onToggleChatbot when clicked', async () => {
const spy = jest.fn();
render();
await userEvent.click(screen.getByRole('button'));
expect(spy).toHaveBeenCalledTimes(1);
});
it('should handle isChatbotVisible correctly when true', () => {
render();
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button');
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button--active');
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true');
expect(screen.getByTestId('Open')).toBeTruthy();
});
it('should handle isChatbotVisible correctly when false', () => {
render();
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button');
expect(screen.getByRole('button')).not.toHaveClass('pf-chatbot__button--active');
expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false');
expect(screen.queryByTestId('Open')).toBeFalsy();
});
it('should handle isRound correctly', () => {
render();
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button');
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button--round');
});
it('should handle className correctly', () => {
render();
expect(screen.getByRole('button')).toHaveClass('pf-chatbot__button');
expect(screen.getByRole('button')).toHaveClass('test');
});
});