From 0c0cd33619e14c4648df01e92c7566434d9567e0 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Thu, 17 Oct 2024 12:16:26 +0530 Subject: [PATCH 1/8] extended testcases for useMarkup --- __tests__/services/AudioService.test.ts | 76 +++++++++++++++++++++++++ package-lock.json | 1 + src/services/AudioService.ts | 6 +- 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/__tests__/services/AudioService.test.ts b/__tests__/services/AudioService.test.ts index 509736f4..c2a99f13 100644 --- a/__tests__/services/AudioService.test.ts +++ b/__tests__/services/AudioService.test.ts @@ -255,4 +255,80 @@ describe("AudioService.processAudio (Inline Mocks)", () => { expect(utterance.volume).toBe(settings.audio?.volume); expect(utterance.voice).toBeNull(); }); + + it("processes audio with markup when useMarkup is true", () => { + const settings: Settings = { + audio: { + disabled: false, + voiceNames: ["Google US English"], + }, + }; + + const message: Message = { + id: generateSecureUUID(), + sender: "bot", + content: "Hello! How can I assist you today?", + type: "string", + timestamp: Date.now().toString(), + }; + + const voiceToggledOn = true; + const isChatWindowOpen = true; + const useMarkup = true; + processAudio(settings, voiceToggledOn, isChatWindowOpen, message, useMarkup); + + expect(mockSpeak).toHaveBeenCalledTimes(1); + const utterance = mockSpeak.mock.calls[0][0] as SpeechSynthesisUtterance; + expect(utterance.text).toBe("Hello! How can I assist you today?"); // Assuming markup is stripped + }); + + it("processes audio without markup when useMarkup is false", () => { + const settings: Settings = { + audio: { + disabled: false, + voiceNames: ["Google US English"], + }, + }; + + const message: Message = { + id: generateSecureUUID(), + sender: "bot", + content: "Hello! How can I assist you today?", + type: "string", + timestamp: Date.now().toString(), + }; + + const voiceToggledOn = true; + const isChatWindowOpen = true; + const useMarkup = false; + processAudio(settings, voiceToggledOn, isChatWindowOpen, message, useMarkup); + + expect(mockSpeak).toHaveBeenCalledTimes(1); + const utterance = mockSpeak.mock.calls[0][0] as SpeechSynthesisUtterance; + expect(utterance.text).toBe("Hello! How can I assist you today?"); // Markup is preserved + }); + + it("handles empty message when useMarkup is true", () => { + const settings: Settings = { + audio: { + disabled: false, + voiceNames: ["Google US English"], + }, + }; + + const message: Message = { + id: generateSecureUUID(), + sender: "bot", + content: "", + type: "string", + timestamp: Date.now().toString(), + }; + + const voiceToggledOn = true; + const isChatWindowOpen = true; + const useMarkup = true; + processAudio(settings, voiceToggledOn, isChatWindowOpen, message, useMarkup); + + expect(mockSpeak).not.toHaveBeenCalled(); + }); }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 05bddd00..113abe49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6589,6 +6589,7 @@ "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, + "license": "MIT", "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", diff --git a/src/services/AudioService.ts b/src/services/AudioService.ts index 94d42e4e..378ad174 100644 --- a/src/services/AudioService.ts +++ b/src/services/AudioService.ts @@ -42,7 +42,7 @@ const speak = (message: string, language: string, voiceNames: string[], rate: nu /** * Handles logic for whether a bot message should be read out. * - * @param settings options provide to the bot + * @param settings options provided to the bot * @param voiceToggledOn boolean indicating if voice is toggled on * @param isChatWindowOpen boolean indicating if chat window is open * @param message message to read out @@ -51,8 +51,10 @@ const speak = (message: string, language: string, voiceNames: string[], rate: nu export const processAudio = (settings: Settings, voiceToggledOn: boolean, isChatWindowOpen: boolean, message: Message, useMarkup: boolean) => { + // Add check for empty message content if (settings.audio?.disabled || message.sender === "user" || typeof message.content !== "string" - || (!isChatWindowOpen && !settings.general?.embedded) || !voiceToggledOn) { + || (!isChatWindowOpen && !settings.general?.embedded) || !voiceToggledOn + || message.content.trim() === "") { // Check for empty message content return; } From d913cf29d7753983e75e963fad20498532c70543 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Sun, 20 Oct 2024 20:06:23 +0530 Subject: [PATCH 2/8] adding testcases for StylesContext.tsx --- .../components/context/StylesContext.test.tsx | 60 +++++++++++++++++++ jest.config.js | 1 + package-lock.json | 31 ++++++++-- package.json | 3 +- src/components/ChatBotLoader.tsx | 1 - viteconfig.ts | 3 +- 6 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 __tests__/components/context/StylesContext.test.tsx diff --git a/__tests__/components/context/StylesContext.test.tsx b/__tests__/components/context/StylesContext.test.tsx new file mode 100644 index 00000000..b434eb35 --- /dev/null +++ b/__tests__/components/context/StylesContext.test.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import { render, screen, act } from '@testing-library/react'; +import { StylesProvider, useStylesContext } from '../../../src/context/StylesContext'; +import { DefaultStyles } from "../../../src/constants/internal/DefaultStyles"; +import '@testing-library/jest-dom'; + + +// Mocking a child component to test context +const MockChild = () => { + const { styles, setStyles } = useStylesContext(); + + return ( +
+

Current Styles: {JSON.stringify(styles)}

+ +
+ ); +}; + +// Test suite for StylesProvider +describe('StylesProvider', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + test('provides default styles', () => { + render( + + + + ); + + // Check if the default styles are provided + const stylesElement = screen.getByText(`Current Styles: ${JSON.stringify(DefaultStyles)}`); + expect(stylesElement).toBeInTheDocument(); + }); + + test('allows updating styles through setStyles', () => { + const setStylesMock = jest.fn(); + render( + + + + ); + + // Click the button to change styles + const button = screen.getByText('Change Chat Window Style'); + act(() => { + button.click(); + }); + + // Verify that setStyles was called with the updated styles + expect(setStylesMock).toHaveBeenCalledWith({ + ...DefaultStyles, + chatWindowStyle: { backgroundColor: 'blue' }, + }); + }); +}); diff --git a/jest.config.js b/jest.config.js index 9c328857..c6115aa8 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,4 +13,5 @@ export default { testPathIgnorePatterns: [ "__tests__/__mocks__" ], + "maxWorkers": 2 }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 113abe49..b77723a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,12 +9,13 @@ "version": "2.0.0-beta.18", "license": "MIT", "devDependencies": { - "@testing-library/jest-dom": "^6.5.0", + "@testing-library/jest-dom": "^6.6.2", "@testing-library/react": "^16.0.1", "@types/dom-speech-recognition": "^0.0.4", "@types/jest": "^29.5.13", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", + "@types/testing-library__react-hooks": "^3.4.1", "@typescript-eslint/eslint-plugin": "^5.60.1", "@vitejs/plugin-react": "^4.0.4", "cypress": "^13.14.2", @@ -2095,9 +2096,9 @@ } }, "node_modules/@testing-library/jest-dom": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.5.0.tgz", - "integrity": "sha512-xGGHpBXYSHUUr6XsKBfs85TWlYKpTc37cSBBVrXcib2MkHLboWlkClhWF37JKlDb9KEq3dHs+f2xR7XJEWGBxA==", + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.6.2.tgz", + "integrity": "sha512-P6GJD4yqc9jZLbe98j/EkyQDTPgqftohZF5FBkHY5BUERZmcf4HeO2k0XaefEg329ux2p21i1A1DmyQ1kKw2Jw==", "dev": true, "license": "MIT", "dependencies": { @@ -2397,6 +2398,16 @@ "@types/react": "*" } }, + "node_modules/@types/react-test-renderer": { + "version": "18.3.0", + "resolved": "https://registry.npmjs.org/@types/react-test-renderer/-/react-test-renderer-18.3.0.tgz", + "integrity": "sha512-HW4MuEYxfDbOHQsVlY/XtOvNHftCVEPhJF2pQXXwcUiUF+Oyb0usgp48HSgpK5rt8m9KZb22yqOeZm+rrVG8gw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/react": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.0", "dev": true, @@ -2423,6 +2434,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/testing-library__react-hooks": { + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/@types/testing-library__react-hooks/-/testing-library__react-hooks-3.4.1.tgz", + "integrity": "sha512-G4JdzEcq61fUyV6wVW9ebHWEiLK2iQvaBuCHHn9eMSbZzVh4Z4wHnUGIvQOYCCYeu5DnUtFyNYuAAgbSaO/43Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/react-test-renderer": "*" + } + }, "node_modules/@types/tough-cookie": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", @@ -2491,6 +2512,8 @@ }, "node_modules/@typescript-eslint/parser": { "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.62.0.tgz", + "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, "license": "BSD-2-Clause", "peer": true, diff --git a/package.json b/package.json index 5b4fba76..faba2e8f 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,13 @@ "react-dom": ">=16.14.0 <20.0.0 || ^19.0.0-0" }, "devDependencies": { - "@testing-library/jest-dom": "^6.5.0", + "@testing-library/jest-dom": "^6.6.2", "@testing-library/react": "^16.0.1", "@types/dom-speech-recognition": "^0.0.4", "@types/jest": "^29.5.13", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", + "@types/testing-library__react-hooks": "^3.4.1", "@typescript-eslint/eslint-plugin": "^5.60.1", "@vitejs/plugin-react": "^4.0.4", "cypress": "^13.14.2", diff --git a/src/components/ChatBotLoader.tsx b/src/components/ChatBotLoader.tsx index 7cba7528..79e4a38a 100644 --- a/src/components/ChatBotLoader.tsx +++ b/src/components/ChatBotLoader.tsx @@ -1,5 +1,4 @@ import { Dispatch, MutableRefObject, SetStateAction, useEffect, useMemo } from "react"; - import { emitRcbEvent } from "../services/RcbEventService"; import { useChatBotContext } from "../context/ChatBotContext"; import { useBotRefsContext } from "../context/BotRefsContext"; diff --git a/viteconfig.ts b/viteconfig.ts index dee181be..621db2ce 100644 --- a/viteconfig.ts +++ b/viteconfig.ts @@ -2,4 +2,5 @@ export const viteConfig = { DEFAULT_URL: import.meta.env?.VITE_THEME_BASE_CDN_URL, DEFAULT_EXPIRATION: import.meta.env?.VITE_THEME_DEFAULT_CACHE_EXPIRATION, CACHE_KEY_PREFIX: import.meta.env?.VITE_THEME_CACHE_KEY_PREFIX, - }; \ No newline at end of file + }; + \ No newline at end of file From 6ffa9f63f9f1bd4bdbbf25a10e2af8c1a94094a4 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 17:15:08 +0530 Subject: [PATCH 3/8] added testcases for BotStatesContext --- .../context/BotStatesContext.test.tsx | 73 +++++++++++++++++++ package-lock.json | 1 + 2 files changed, 74 insertions(+) create mode 100644 __tests__/components/context/BotStatesContext.test.tsx diff --git a/__tests__/components/context/BotStatesContext.test.tsx b/__tests__/components/context/BotStatesContext.test.tsx new file mode 100644 index 00000000..cc33bfb9 --- /dev/null +++ b/__tests__/components/context/BotStatesContext.test.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import { BotStatesProvider, useBotStatesContext } from '../../../src/context/BotStatesContext'; +import '@testing-library/jest-dom'; + + +const TestComponent = () => { + const { + isBotTyping, + setIsBotTyping, + isChatWindowOpen, + setIsChatWindowOpen, + } = useBotStatesContext(); + + return ( +
+

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

+ +

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

+ +
+ ); +}; + +describe('BotStatesProvider', () => { + const renderWithProvider = (children: React.ReactNode, settings = {}) => { + return render( + + {children} + + ); + }; + + it('should initialize with default values', () => { + renderWithProvider(); + + expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument(); + expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument(); + }); + + it('should toggle bot typing state', () => { + renderWithProvider(); + + const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i }); + fireEvent.click(toggleButton); + + expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument(); + }); + + it('should toggle chat window state', () => { + renderWithProvider(); + + const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i }); + fireEvent.click(toggleButton); + + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); + + it('should respect initial settings', () => { + const settings = { + chatWindow: { defaultOpen: true }, + audio: { defaultToggledOn: true }, + }; + + renderWithProvider(, settings); + + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); +}); diff --git a/package-lock.json b/package-lock.json index 7472cf88..516b0880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2340,6 +2340,7 @@ "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.13.tgz", "integrity": "sha512-wd+MVEZCHt23V0/L642O5APvspWply/rGY5BcW4SUETo2UzPU3Z26qr8jC2qxpimI2jjx9h7+2cj2FwIr01bXg==", "dev": true, + "license": "MIT", "dependencies": { "expect": "^29.0.0", "pretty-format": "^29.0.0" From 103e95bb84848cc0a6bfa7d9a68cd06540323cfc Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 17:15:43 +0530 Subject: [PATCH 4/8] 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(); + }); }); From 0f1c85b62bca891cef66c1105e54493729400065 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 21:30:06 +0530 Subject: [PATCH 5/8] added the necessary changes on request --- .../context/BotStatesContext.test.tsx | 73 ------------------- jest.config.js | 1 - package-lock.json | 1 - src/components/ChatBotLoader.tsx | 1 + 4 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 __tests__/components/context/BotStatesContext.test.tsx diff --git a/__tests__/components/context/BotStatesContext.test.tsx b/__tests__/components/context/BotStatesContext.test.tsx deleted file mode 100644 index 4313d7d8..00000000 --- a/__tests__/components/context/BotStatesContext.test.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import React from 'react'; -import { render, screen, fireEvent } from '@testing-library/react'; -import { BotStatesProvider, useBotStatesContext } from '../../../src/context/BotStatesContext'; -import '@testing-library/jest-dom'; - - -const TestComponent = () => { - const { - isBotTyping, - setIsBotTyping, - isChatWindowOpen, - setIsChatWindowOpen, - } = useBotStatesContext(); - - return ( -
-

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

- -

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

- -
- ); -}; - -describe('BotStatesProvider', () => { - const renderWithProvider = (children: React.ReactNode, settings = {}) => { - return render( - - {children} - - ); - }; - - it('should initialize with default values', () => { - renderWithProvider(); - - expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument(); - expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument(); - }); - - it('should toggle bot typing state', () => { - renderWithProvider(); - - const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i }); - fireEvent.click(toggleButton); - - expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument(); - }); - - it('should toggle chat window state', () => { - renderWithProvider(); - - const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i }); - fireEvent.click(toggleButton); - - expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); - }); - - it('should respect initial settings', () => { - const settings = { - chatWindow: { defaultOpen: true }, - audio: { defaultToggledOn: true }, - }; - - renderWithProvider(, settings); - - expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); - }); -}); diff --git a/jest.config.js b/jest.config.js index c6115aa8..9c328857 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,5 +13,4 @@ export default { testPathIgnorePatterns: [ "__tests__/__mocks__" ], - "maxWorkers": 2 }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 516b0880..c7aa4ae8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "@types/jest": "^29.5.13", "@types/react": "^18.3.6", "@types/react-dom": "^18.3.0", - "@types/testing-library__react-hooks": "^3.4.1", "@typescript-eslint/eslint-plugin": "^5.60.1", "@vitejs/plugin-react": "^4.0.4", "cypress": "^13.14.2", diff --git a/src/components/ChatBotLoader.tsx b/src/components/ChatBotLoader.tsx index 79e4a38a..7cba7528 100644 --- a/src/components/ChatBotLoader.tsx +++ b/src/components/ChatBotLoader.tsx @@ -1,4 +1,5 @@ import { Dispatch, MutableRefObject, SetStateAction, useEffect, useMemo } from "react"; + import { emitRcbEvent } from "../services/RcbEventService"; import { useChatBotContext } from "../context/ChatBotContext"; import { useBotRefsContext } from "../context/BotRefsContext"; From 6552d54631a66873fac092f558c4252802c297a8 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 23:14:48 +0530 Subject: [PATCH 6/8] added testcases for BotStatesContext --- .../context/BotStatesContext.test.tsx | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 __tests__/components/context/BotStatesContext.test.tsx diff --git a/__tests__/components/context/BotStatesContext.test.tsx b/__tests__/components/context/BotStatesContext.test.tsx new file mode 100644 index 00000000..28b34dd2 --- /dev/null +++ b/__tests__/components/context/BotStatesContext.test.tsx @@ -0,0 +1,74 @@ +import React from 'react'; + +import { render, screen, fireEvent } from '@testing-library/react'; +import { BotStatesProvider, useBotStatesContext } from '../../../src/context/BotStatesContext'; +import '@testing-library/jest-dom'; + + +const TestComponent = () => { + const { + isBotTyping, + setIsBotTyping, + isChatWindowOpen, + setIsChatWindowOpen, + } = useBotStatesContext(); + + return ( +
+

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

+ +

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

+ +
+ ); +}; + +describe('BotStatesProvider', () => { + const renderWithProvider = (children: React.ReactNode, settings = {}) => { + return render( + + {children} + + ); + }; + + it('should initialize with default values', () => { + renderWithProvider(); + + expect(screen.getByText(/Bot Typing: No/i)).toBeInTheDocument(); + expect(screen.getByText(/Chat Window Open: No/i)).toBeInTheDocument(); + }); + + it('should toggle bot typing state', () => { + renderWithProvider(); + + const toggleButton = screen.getByRole('button', { name: /Toggle Bot Typing/i }); + fireEvent.click(toggleButton); + + expect(screen.getByText(/Bot Typing: Yes/i)).toBeInTheDocument(); + }); + + it('should toggle chat window state', () => { + renderWithProvider(); + + const toggleButton = screen.getByRole('button', { name: /Toggle Chat Window/i }); + fireEvent.click(toggleButton); + + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); + + it('should respect initial settings', () => { + const settings = { + chatWindow: { defaultOpen: true }, + audio: { defaultToggledOn: true }, + }; + + renderWithProvider(, settings); + + expect(screen.getByText(/Chat Window Open: Yes/i)).toBeInTheDocument(); + }); +}); From cb362e3d503d4fb1a8994549e2fca2e282ad9788 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Mon, 21 Oct 2024 23:22:58 +0530 Subject: [PATCH 7/8] fixed the unnecessary context folder creation --- __tests__/{components => }/context/BotStatesContext.test.tsx | 2 +- __tests__/{components => }/context/StylesContext.test.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename __tests__/{components => }/context/BotStatesContext.test.tsx (95%) rename __tests__/{components => }/context/StylesContext.test.tsx (90%) diff --git a/__tests__/components/context/BotStatesContext.test.tsx b/__tests__/context/BotStatesContext.test.tsx similarity index 95% rename from __tests__/components/context/BotStatesContext.test.tsx rename to __tests__/context/BotStatesContext.test.tsx index 28b34dd2..fa38dd0a 100644 --- a/__tests__/components/context/BotStatesContext.test.tsx +++ b/__tests__/context/BotStatesContext.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render, screen, fireEvent } from '@testing-library/react'; -import { BotStatesProvider, useBotStatesContext } from '../../../src/context/BotStatesContext'; +import { BotStatesProvider, useBotStatesContext } from '../../src/context/BotStatesContext'; import '@testing-library/jest-dom'; diff --git a/__tests__/components/context/StylesContext.test.tsx b/__tests__/context/StylesContext.test.tsx similarity index 90% rename from __tests__/components/context/StylesContext.test.tsx rename to __tests__/context/StylesContext.test.tsx index b434eb35..abae4b5a 100644 --- a/__tests__/components/context/StylesContext.test.tsx +++ b/__tests__/context/StylesContext.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { render, screen, act } from '@testing-library/react'; -import { StylesProvider, useStylesContext } from '../../../src/context/StylesContext'; -import { DefaultStyles } from "../../../src/constants/internal/DefaultStyles"; +import { StylesProvider, useStylesContext } from '../../src/context/StylesContext'; +import { DefaultStyles } from "../../src/constants/internal/DefaultStyles"; import '@testing-library/jest-dom'; From 5ba37991e91133e51ecaa319dc512b76450b9560 Mon Sep 17 00:00:00 2001 From: Suvrat1629 Date: Tue, 22 Oct 2024 19:14:49 +0530 Subject: [PATCH 8/8] Del. viteconfig.ts --- viteconfig.ts | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 viteconfig.ts diff --git a/viteconfig.ts b/viteconfig.ts deleted file mode 100644 index 621db2ce..00000000 --- a/viteconfig.ts +++ /dev/null @@ -1,6 +0,0 @@ -export const viteConfig = { - DEFAULT_URL: import.meta.env?.VITE_THEME_BASE_CDN_URL, - DEFAULT_EXPIRATION: import.meta.env?.VITE_THEME_DEFAULT_CACHE_EXPIRATION, - CACHE_KEY_PREFIX: import.meta.env?.VITE_THEME_CACHE_KEY_PREFIX, - }; - \ No newline at end of file