-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
71 changed files
with
1,952 additions
and
516 deletions.
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
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 |
---|---|---|
@@ -1,2 +1,10 @@ | ||
// __mocks__/fileMock.ts | ||
export const botAvatar = "../../assets/bot_avatar.svg"; | ||
export const botAvatar = "../../assets/bot_avatar.svg"; | ||
export const actionDisabledIcon = "../../assets/action_disabled_icon.svg"; | ||
export const emojiIcon = "../../assets/emoji_icon.svg"; | ||
export const closeChatIcon = "../../assets/close_chat_icon.svg"; | ||
export const notificationIcon = "../../assets/notification_icon.svg"; | ||
export const notificationIconDisabled = "../../assets/notification_icon_disabled.svg"; | ||
export const audioIcon = "../../assets/audio_icon.svg"; | ||
export const audioIconDisabled = "../../assets/audio_icon_disabled.svg"; | ||
export const sendIcon = "../../assets/send_icon.svg"; |
121 changes: 121 additions & 0 deletions
121
__tests__/components/ChatBotTooltip/ChatBotTooltip.test.tsx
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,121 @@ | ||
import React from "react"; | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import ChatBotTooltip from "../../../src/components/ChatBotTooltip/ChatBotTooltip"; | ||
import { useIsDesktopInternal } from "../../../src/hooks/internal/useIsDesktopInternal"; | ||
import { useChatWindowInternal } from "../../../src/hooks/internal/useChatWindowInternal"; | ||
import { useSettingsContext } from "../../../src/context/SettingsContext"; | ||
import { useStylesContext } from "../../../src/context/StylesContext"; | ||
|
||
// Mock the contexts and hooks | ||
jest.mock("../../../src/hooks/internal/useIsDesktopInternal"); | ||
jest.mock("../../../src/hooks/internal/useChatWindowInternal"); | ||
jest.mock("../../../src/context/SettingsContext"); | ||
jest.mock("../../../src/context/StylesContext"); | ||
|
||
describe("ChatBotTooltip Component", () => { | ||
// Set up default mock return values before each test | ||
beforeEach(() => { | ||
(useIsDesktopInternal as jest.Mock).mockReturnValue(true); | ||
(useChatWindowInternal as jest.Mock).mockReturnValue({ | ||
isChatWindowOpen: false, | ||
openChat: jest.fn(), | ||
}); | ||
(useSettingsContext as jest.Mock).mockReturnValue({ | ||
settings: { | ||
general: { primaryColor: "blue", secondaryColor: "#000", embedded: false }, | ||
tooltip: { text: "Chatbot Tooltip" }, | ||
}, | ||
}); | ||
(useStylesContext as jest.Mock).mockReturnValue({ | ||
styles: { | ||
chatButtonStyle: { width: 75 }, | ||
chatWindowStyle: { width: 375 }, | ||
tooltipStyle: {}, | ||
}, | ||
}); | ||
}); | ||
|
||
// Clear all mocks after each test case to avoid test interference | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
// Test: Render the tooltip when mode is "ALWAYS" and on desktop | ||
it('renders tooltip when mode is "ALWAYS" and isDesktop is true', () => { | ||
// Mock the context to return settings with mode "ALWAYS" | ||
(useSettingsContext as jest.Mock).mockReturnValueOnce({ | ||
settings: { | ||
tooltip: { mode: "ALWAYS", text: "Chatbot Tooltip" }, | ||
}, | ||
}); | ||
|
||
// Render the component and ensure the tooltip is shown | ||
render(<ChatBotTooltip />); | ||
const tooltip = screen.getByTestId("chat-tooltip"); | ||
expect(tooltip).toBeInTheDocument(); | ||
expect(tooltip).toHaveClass("rcb-tooltip-show"); | ||
}); | ||
|
||
// Test: Ensure the tooltip is hidden when mode is "NEVER" | ||
it('hides tooltip when mode is "NEVER"', () => { | ||
// Mock the context to return settings with mode "NEVER" | ||
(useSettingsContext as jest.Mock).mockReturnValueOnce({ | ||
settings: { | ||
tooltip: { mode: "NEVER", text: "Chatbot Tooltip" }, | ||
}, | ||
}); | ||
|
||
// Render the component and ensure the tooltip is rendered but hidden | ||
render(<ChatBotTooltip />); | ||
const tooltip = screen.getByTestId("chat-tooltip"); | ||
expect(tooltip).toBeInTheDocument(); | ||
expect(tooltip).toHaveClass("rcb-tooltip-hide"); | ||
}); | ||
|
||
// Test: Show the tooltip when mode is "START" (when component is rendered for the first time) | ||
it('shows tooltip when mode is "START" and shownTooltipOnStart is false', () => { | ||
// Mock the context to return settings with mode "START" | ||
(useSettingsContext as jest.Mock).mockReturnValueOnce({ | ||
settings: { | ||
tooltip: { mode: "START", text: "Chatbot Tooltip" }, | ||
}, | ||
}); | ||
|
||
// Render the component and ensure the tooltip is shown | ||
render(<ChatBotTooltip />); | ||
const tooltip = screen.getByText("Chatbot Tooltip"); | ||
expect(tooltip).toBeInTheDocument(); | ||
}); | ||
|
||
// Test: Ensure the tooltip shows when mode is "CLOSE" | ||
it('shows tooltip when mode is "CLOSE"', () => { | ||
// Mock the context to return settings with mode "CLOSE" | ||
(useSettingsContext as jest.Mock).mockReturnValueOnce({ | ||
settings: { | ||
tooltip: { mode: "CLOSE", text: "Chatbot Tooltip" }, | ||
}, | ||
}); | ||
|
||
// Render the component and ensure the tooltip is shown | ||
render(<ChatBotTooltip />); | ||
const tooltip = screen.getByText("Chatbot Tooltip"); | ||
expect(tooltip).toBeInTheDocument(); | ||
}); | ||
|
||
// Test: Ensure clicking the tooltip calls the openChat function | ||
it("calls openChat function when tooltip is clicked", () => { | ||
// Mock the function that opens the chat | ||
const mockOpenChat = jest.fn(); | ||
(useChatWindowInternal as jest.Mock).mockReturnValue({ | ||
isChatWindowOpen: false, | ||
openChat: mockOpenChat, | ||
}); | ||
|
||
// Render the component, simulate click event and verify that openChat is called | ||
render(<ChatBotTooltip />); | ||
const tooltip = screen.getByText("Chatbot Tooltip"); | ||
fireEvent.click(tooltip); | ||
expect(mockOpenChat).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
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
87 changes: 87 additions & 0 deletions
87
__tests__/components/ChatHistoryLineBreak/ChatHistoryLineBreak.test.tsx
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,87 @@ | ||
import React from "react"; | ||
|
||
import { expect } from "@jest/globals"; | ||
import { render, screen} from "@testing-library/react"; | ||
import "@testing-library/jest-dom/jest-globals"; | ||
|
||
import ChatHistoryLineBreak from "../../../src/components/ChatHistoryLineBreak/ChatHistoryLineBreak"; | ||
import { useSettingsContext } from "../../../src/context/SettingsContext"; | ||
import { useStylesContext } from "../../../src/context/StylesContext"; | ||
import { DefaultStyles } from "../../../src/constants/internal/DefaultStyles"; | ||
import { DefaultSettings } from "../../../src/constants/internal/DefaultSettings"; | ||
|
||
jest.mock("../../../src/context/SettingsContext"); | ||
jest.mock("../../../src/context/StylesContext"); | ||
|
||
/** | ||
* Test for ChatHistoryLineBreak component. | ||
*/ | ||
describe("ChatHistoryLineBreak Component", () => { | ||
const mockText = DefaultSettings.chatHistory?.chatHistoryLineBreakText ?? "test break line"; | ||
const mockColor = DefaultStyles.chatHistoryLineBreakStyle?.color ?? "blue"; | ||
|
||
// Mock default settings and styles before each test | ||
beforeEach(() => { | ||
(useSettingsContext as jest.Mock).mockReturnValue({ | ||
settings: { | ||
chatHistory: { | ||
chatHistoryLineBreakText: mockText | ||
} | ||
} | ||
}); | ||
|
||
(useStylesContext as jest.Mock).mockReturnValue({ | ||
styles: { | ||
chatHistoryLineBreakStyle: { | ||
color: mockColor | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it("renders mock line break text and style", () => { | ||
render(<ChatHistoryLineBreak />); | ||
|
||
// check if the default text is rendered | ||
const lineBreak = screen.getByText(mockText); | ||
expect(lineBreak).toBeInTheDocument(); | ||
|
||
// check if line break color is correct | ||
expect(lineBreak).toHaveStyle(`color: ${mockColor}`); | ||
}); | ||
|
||
it("renders empty div when chatHistoryLineBreakText is not provided", () => { | ||
// Mock settings without chatHistoryLineBreakText | ||
(useSettingsContext as jest.Mock).mockReturnValue({ | ||
settings: { | ||
chatHistory: {} // Simulate missing chatHistoryLineBreakText | ||
} | ||
}); | ||
|
||
render(<ChatHistoryLineBreak />); | ||
|
||
// check that line break div exists but text is empty | ||
const lineBreak = screen.getByTestId("chat-history-line-break-text"); | ||
expect(lineBreak).toBeInTheDocument(); | ||
expect(lineBreak).toBeEmptyDOMElement(); | ||
|
||
// check if line break color is applied even when chatHistoryLineBreakText is empty | ||
expect(lineBreak).toHaveStyle(`color: ${DefaultStyles.chatHistoryLineBreakStyle?.color ?? mockColor}`); | ||
}); | ||
|
||
it("renders empty when chatHistory is not provided", () => { | ||
(useSettingsContext as jest.Mock).mockReturnValue({ | ||
settings: {} | ||
}); | ||
|
||
render(<ChatHistoryLineBreak />); | ||
|
||
// check that line break div exists but text is empty | ||
const lineBreak = screen.getByTestId("chat-history-line-break-text"); | ||
expect(lineBreak).toBeInTheDocument(); | ||
expect(lineBreak).toBeEmptyDOMElement(); | ||
|
||
// check line break color is applied even when chatHistory is empty | ||
expect(lineBreak).toHaveStyle(`color: ${DefaultStyles.chatHistoryLineBreakStyle?.color ?? mockColor}`); | ||
}); | ||
}); |
Oops, something went wrong.