-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit test cases for ChatBotButton component (#179)
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
}); |