-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9aba3e8
commit 843666f
Showing
6 changed files
with
125 additions
and
8 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
113 changes: 113 additions & 0 deletions
113
app/client/packages/design-system/widgets/src/components/AIChat/tests/AIChat.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,113 @@ | ||
import React from "react"; | ||
import "@testing-library/jest-dom"; | ||
import { render, screen, within } from "@testing-library/react"; | ||
import { faker } from "@faker-js/faker"; | ||
|
||
import { AIChat, type AIChatProps } from ".."; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const renderComponent = (props: Partial<AIChatProps> = {}) => { | ||
const defaultProps: AIChatProps = { | ||
username: "", | ||
thread: [], | ||
prompt: "", | ||
onPromptChange: jest.fn(), | ||
}; | ||
|
||
return render(<AIChat {...defaultProps} {...props} />); | ||
}; | ||
|
||
describe("@appsmith/wds/AIChat", () => { | ||
it("should render chat's title", () => { | ||
const chatTitle = faker.lorem.words(2); | ||
|
||
renderComponent({ chatTitle }); | ||
|
||
expect(screen.getByTestId("t--aichat-chat-title")).toHaveTextContent( | ||
chatTitle, | ||
); | ||
}); | ||
|
||
it("should render username", () => { | ||
const username = faker.name.firstName(); | ||
|
||
renderComponent({ username }); | ||
|
||
expect(screen.getByTestId("t--aichat-username")).toHaveTextContent( | ||
username, | ||
); | ||
}); | ||
|
||
it("should render thread", () => { | ||
const thread = [ | ||
{ | ||
id: faker.datatype.uuid(), | ||
content: faker.lorem.paragraph(1), | ||
isAssistant: false, | ||
}, | ||
{ | ||
id: faker.datatype.uuid(), | ||
content: faker.lorem.paragraph(2), | ||
isAssistant: true, | ||
}, | ||
]; | ||
|
||
renderComponent({ thread }); | ||
|
||
const messages = within( | ||
screen.getByTestId("t--aichat-thread"), | ||
).getAllByRole("listitem"); | ||
|
||
expect(messages).toHaveLength(thread.length); | ||
expect(messages[0]).toHaveTextContent(thread[0].content); | ||
expect(messages[1]).toHaveTextContent(thread[1].content); | ||
}); | ||
|
||
it("should render prompt input placeholder", () => { | ||
const promptInputPlaceholder = faker.lorem.words(3); | ||
|
||
renderComponent({ | ||
promptInputPlaceholder, | ||
}); | ||
|
||
expect(screen.getByRole("textbox")).toHaveAttribute( | ||
"placeholder", | ||
promptInputPlaceholder, | ||
); | ||
}); | ||
|
||
it("should render prompt input value", () => { | ||
const prompt = faker.lorem.words(3); | ||
|
||
renderComponent({ | ||
prompt, | ||
}); | ||
|
||
expect(screen.getByRole("textbox")).toHaveValue(prompt); | ||
}); | ||
|
||
it("should trigger user's prompt", async () => { | ||
const onPromptChange = jest.fn(); | ||
|
||
renderComponent({ | ||
onPromptChange, | ||
}); | ||
|
||
await userEvent.type(screen.getByRole("textbox"), "A"); | ||
|
||
expect(onPromptChange).toHaveBeenCalledWith("A"); | ||
}); | ||
|
||
it("should submit user's prompt", async () => { | ||
const onSubmit = jest.fn(); | ||
|
||
renderComponent({ | ||
prompt: "ABCD", | ||
onSubmit, | ||
}); | ||
|
||
await userEvent.click(screen.getByRole("button", { name: "Send" })); | ||
|
||
expect(onSubmit).toHaveBeenCalled(); | ||
}); | ||
}); |
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,3 +1,5 @@ | ||
import React from "react"; | ||
|
||
jest.mock("react-markdown", () => (props: { children: unknown }) => { | ||
return <>{props.children}</>; | ||
}); |