Skip to content

Commit

Permalink
Added unit test cases for ChatBotButton component (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
tasbi03 authored Oct 10, 2024
1 parent 671679f commit 8c46322
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __tests__/components/ChatBotFooter/ChatBotFooter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ChatBotFooter from "../../../src/components/ChatBotFooter/ChatBotFooter"
const renderChatBotFooter = ({ buttons }: { buttons: JSX.Element[] }) => {
return render(

<ChatBotFooter buttons={buttons}></ChatBotFooter>
<ChatBotFooter buttons={buttons}></ChatBotFooter>

);
};
Expand Down
37 changes: 37 additions & 0 deletions __tests__/components/buttons/ChatBotButton.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { expect } from "@jest/globals";
import { render, screen, fireEvent } from '@testing-library/react';
import "@testing-library/jest-dom/jest-globals";
import ChatBotButton from '../../../src/components/ChatBotButton/ChatBotButton';
import { TestChatBotProvider } from '../../__mocks__/TestChatBotContext';
import { DefaultSettings } from "../../../src/constants/internal/DefaultSettings";

// Helper function to render ChatBotButton within TestChatBotProvider
const renderChatBotButton = () => {
return render(
<TestChatBotProvider initialSettings={DefaultSettings}>
<ChatBotButton />
</TestChatBotProvider>
);
};

describe('ChatBotButton', () => {
it('renders ChatBotButton correctly', () => {
renderChatBotButton();
const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
});

// Mock visibility toggle function (assuming it's triggered by a button click)
it('toggles visibility classes correctly based on internal function', () => {
renderChatBotButton();
const button = screen.getByRole('button');

// Initially visible
expect(button).toHaveClass('rcb-button-show');

// Simulate state change or function that hides the button
fireEvent.click(button); // Assuming the button click triggers visibility toggle
expect(button).toHaveClass('rcb-button-hide'); // Check if the class changes to hidden
});
});

0 comments on commit 8c46322

Please sign in to comment.