From 103e95bb84848cc0a6bfa7d9a68cd06540323cfc Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 17:15:43 +0530 Subject: [PATCH] added testcases for BotStatesContext --- .../context/BotStatesContext.test.tsx | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/__tests__/components/context/BotStatesContext.test.tsx b/__tests__/components/context/BotStatesContext.test.tsx index cc33bfb9..4313d7d8 100644 --- a/__tests__/components/context/BotStatesContext.test.tsx +++ b/__tests__/components/context/BotStatesContext.test.tsx @@ -5,69 +5,69 @@ import '@testing-library/jest-dom'; const TestComponent = () => { - const { - isBotTyping, - setIsBotTyping, - isChatWindowOpen, - setIsChatWindowOpen, - } = useBotStatesContext(); + const { + isBotTyping, + setIsBotTyping, + isChatWindowOpen, + setIsChatWindowOpen, + } = useBotStatesContext(); - return ( -
-

Bot Typing: {isBotTyping ? 'Yes' : 'No'}

- -

Chat Window Open: {isChatWindowOpen ? 'Yes' : 'No'}

- -
- ); + return ( +
+

Bot Typing: {isBotTyping ? 'Yes' : 'No'}

+ +

Chat Window Open: {isChatWindowOpen ? 'Yes' : 'No'}

+ +
+ ); }; describe('BotStatesProvider', () => { - const renderWithProvider = (children: React.ReactNode, settings = {}) => { - return render( - - {children} - - ); - }; + const renderWithProvider = (children: React.ReactNode, settings = {}) => { + return render( + + {children} + + ); + }; - it('should initialize with default values', () => { - renderWithProvider(); + it('should initialize with default values', () => { + renderWithProvider(); - expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument(); - expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument(); - }); + expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument(); + expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument(); + }); - it('should toggle bot typing state', () => { - renderWithProvider(); + it('should toggle bot typing state', () => { + renderWithProvider(); - const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i }); - fireEvent.click(toggleButton); + const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i }); + fireEvent.click(toggleButton); - expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument(); - }); + expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument(); + }); - it('should toggle chat window state', () => { - renderWithProvider(); + it('should toggle chat window state', () => { + renderWithProvider(); - const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i }); - fireEvent.click(toggleButton); + const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i }); + fireEvent.click(toggleButton); - expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); - }); + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); - it('should respect initial settings', () => { - const settings = { - chatWindow: { defaultOpen: true }, - audio: { defaultToggledOn: true }, - }; + it('should respect initial settings', () => { + const settings = { + chatWindow: { defaultOpen: true }, + audio: { defaultToggledOn: true }, + }; - renderWithProvider(, settings); + renderWithProvider(, settings); - expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); - }); + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); });