-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add AIChat stories and tests #36700
Conversation
WalkthroughThe pull request implements several modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
843666f
to
ba99a27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (10)
app/client/packages/design-system/widgets/src/components/AIChat/stories/AIChat.stories.tsx (4)
12-22
: Good job on setting up the Main story, but let's discuss theassistantName
prop.Your Main story provides a comprehensive set of default props, which is excellent. However, I noticed that the
assistantName
prop is set to an empty string. Is this intentional? If not, consider setting a default name for the assistant to enhance the user experience.Would you like to revise the
assistantName
prop? If so, you might want to update it like this:export const Main: Story = { args: { // ... other props - assistantName: "", + assistantName: "AI Assistant", // ... remaining props }, };
24-43
: Excellent work on the EmptyHistory and Loading stories! Let's make a small improvement.Your stories effectively demonstrate different states of the AIChat component. The Loading story, in particular, is well-defined with
isWaitingForResponse
set to true.For the EmptyHistory story, consider explicitly setting
isWaitingForResponse
to false. This will make the story's intent clearer and ensure consistent behavior.Here's a suggested modification for the EmptyHistory story:
export const EmptyHistory: Story = { args: { thread: [], prompt: "", username: "John Doe", promptInputPlaceholder: "Type your message here", chatTitle: "Chat with Assistant", + isWaitingForResponse: false, }, };
45-78
: A gold star for your WithHistory story! Let's add a finishing touch.Your WithHistory story provides an excellent example of a conversation thread, showcasing both assistant and user messages. This will be very helpful for testing and demonstrating the component's capabilities.
To make it even better, consider the following suggestions:
- Add the
isWaitingForResponse
prop for consistency with other stories.- Include an example of a message with rich formatting (e.g., bold text, links) to demonstrate how the component handles such content.
Here's how you might implement these suggestions:
export const WithHistory: Story = { args: { thread: [ // ... existing messages { id: "5", content: "Here's an example of a message with **bold text** and a [link](https://example.com).", isAssistant: true, }, ], prompt: "", username: "John Doe", promptInputPlaceholder: "Type your message here", chatTitle: "Chat with Assistant", + isWaitingForResponse: false, }, };
1-78
: Excellent work on your AIChat stories! Here's your report card:You've done a commendable job creating a comprehensive set of stories for the AIChat component. Each story effectively demonstrates different aspects and states of the component, which will be invaluable for testing and documentation.
To take your work to the next level, consider adding these extra credit assignments:
- Create a story demonstrating error handling (e.g., network errors, invalid inputs).
- Add a story showcasing any special features of the AIChat component (e.g., file uploads, code highlighting).
- Include a story with a very long conversation to test scrolling behavior.
Remember, thorough testing leads to robust components. Keep up the great work!
app/client/packages/design-system/widgets/src/components/AIChat/src/AIChat.tsx (1)
65-66
: Let's examine our TextArea component, students.Good thinking on disabling the TextArea when waiting for a response! It's like putting up a "Do Not Disturb" sign when you're busy. However, we have some homework left to do. There's a TODO comment that needs our attention.
Would you like me to create a GitHub issue to track this TODO item? This way, we won't forget to complete our homework later.
app/client/packages/design-system/widgets/src/components/AIChat/tests/AIChat.test.tsx (5)
1-18
: Well done on setting up the test environment, class!The imports and helper function are well-structured. The
renderComponent
function is a great way to keep our test setup consistent. However, let's make a small improvement to make it even better!Consider adding a type annotation to the
renderComponent
function's return value. This will make it clearer what the function is returning:const renderComponent = (props: Partial<AIChatProps> = {}): ReturnType<typeof render> => { // ... existing code ... }This change will help your fellow students understand the function's output more easily.
31-64
: Good job on these test cases, class!Your tests for rendering the username and thread are well-structured. I'm pleased to see you're using
faker
to generate test data - that's a gold star practice!However, let's make our thread test even better. Currently, we're only checking the content of the messages. Let's also verify the
isAssistant
property:expect(messages[0]).toHaveTextContent(thread[0].content); expect(messages[0]).toHaveAttribute('data-is-assistant', thread[0].isAssistant.toString()); expect(messages[1]).toHaveTextContent(thread[1].content); expect(messages[1]).toHaveAttribute('data-is-assistant', thread[1].isAssistant.toString());This change assumes that the
isAssistant
property is reflected in the DOM. If it's not, consider adding it as a data attribute in the AIChat component. Remember, in testing, we want to be as thorough as possible!
89-99
: Great job on testing user interaction, class!Your test for triggering the user's prompt is well-structured. You've correctly used
userEvent
to simulate typing, which is more realistic than directly manipulating the input value.To make this test even more robust, let's add an assertion to check that the input field's value has actually changed:
await userEvent.type(screen.getByRole("textbox"), "A"); expect(screen.getByRole("textbox")).toHaveValue("A"); expect(onPromptChange).toHaveBeenCalledWith("A");This extra check ensures that both the UI and the callback are working as expected. Remember, in testing, it's always good to verify both the cause and the effect!
101-112
: Good effort on testing the submit functionality, students!Your test for submitting the user's prompt is on the right track. You've correctly simulated clicking the "Send" button and verified that the
onSubmit
callback is called.However, let's make this test even more thorough. Currently, we're not checking what argument is passed to
onSubmit
. Let's improve it:const prompt = "ABCD"; const onSubmit = jest.fn(); renderComponent({ prompt, onSubmit, }); await userEvent.click(screen.getByRole("button", { name: "Send" })); expect(onSubmit).toHaveBeenCalledWith(prompt);This change verifies that
onSubmit
is called with the correct prompt value. Remember, in testing, we want to be as specific as possible about what we're checking!
1-113
: Excellent work on your AIChat component tests, class!You've done a commendable job creating a comprehensive test suite for the AIChat component. Your tests cover the main functionality including rendering, user input, and submission. The use of
faker
for generating test data is particularly praiseworthy.To make your test suite even more robust, consider adding the following test cases:
- Test with an empty thread to ensure the component handles this case gracefully.
- Test with a very long message in the thread to check if any truncation or wrapping is applied correctly.
- Test the behavior when the
onSubmit
function is not provided (if the component should handle this case).- Test for any loading or error states the component might have.
Remember, thorough testing is like a safety net for your code. The more scenarios you cover, the more confident you can be in your component's reliability!
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (8)
- app/client/packages/design-system/widgets/src/components/AIChat/src/AIChat.tsx (2 hunks)
- app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/ChatTitle.tsx (1 hunks)
- app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/types.ts (1 hunks)
- app/client/packages/design-system/widgets/src/components/AIChat/src/types.ts (1 hunks)
- app/client/packages/design-system/widgets/src/components/AIChat/stories/AIChat.stories.tsx (1 hunks)
- app/client/packages/design-system/widgets/src/components/AIChat/tests/AIChat.test.tsx (1 hunks)
- app/client/src/modules/ui-builder/ui/wds/WDSAIChatWidget/widget/index.tsx (1 hunks)
- app/client/test/mocks/reactMarkdown.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
- app/client/test/mocks/reactMarkdown.tsx
🔇 Additional comments (11)
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/types.ts (1)
4-4
: Well done, class! This change deserves a gold star! ⭐Now, let's review what we've learned today:
We've made the
title
property optional, which is a smart move. It gives us more flexibility in how we use ourChatTitle
component.However, remember to raise your hand if you see any documentation that needs updating because of this change. It's important to keep our notes in order!
Lastly, we should check if this change affects other parts of our project. It's like when we rearrange the classroom - we need to make sure everyone can still find their seat!
Let's do a little homework to make sure everything is in order:
Remember, if you need any help understanding these results, don't hesitate to ask! That's what teachers are here for.
✅ Verification successful
Alright, it looks like there was a little hiccup with our search commands. Let’s adjust those scripts to ensure everything runs smoothly. Here are the revised shell scripts for us to try:
Once these scripts are executed, we'll have a clearer picture of how the changes affect the rest of the codebase. Let me know the results, and we'll take it from there!
Oh no! It looks like our last search included some files we wanted to exclude. Let's fine-tune our scripts to ensure we're only looking in the right places. Here's an updated set of shell scripts to help us get accurate results:
Please run these scripts, and we'll take it from there to ensure everything is in tip-top shape!
Fantastic job! 🎉
You've successfully made the
title
property optional in theChatTitleProps
interface. This change enhances the flexibility of theChatTitle
component without affecting other parts of the codebase.Keep up the great work!
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential impacts of the ChatTitleProps change # Test 1: Look for uses of ChatTitleProps in other files echo "Searching for uses of ChatTitleProps:" rg --type typescript "ChatTitleProps" --glob '!*/types.ts' # Test 2: Check for any hardcoded uses of the title property echo "Checking for hardcoded uses of the title property:" rg --type typescript 'title="[^"]+"' --glob '**/AIChat/**' # Test 3: Look for any tests that might need updating echo "Searching for tests that might need updating:" rg --type typescript "ChatTitleProps" --glob '**/*.test.ts*'Length of output: 582
Script:
#!/bin/bash # Description: Re-check for potential impacts of the ChatTitleProps change with corrected file types # Test 1: Look for uses of ChatTitleProps in other files echo "Searching for uses of ChatTitleProps:" rg --type ts "ChatTitleProps" --glob '!*/types.ts' # Test 2: Check for any hardcoded uses of the title property echo "Checking for hardcoded uses of the title property:" rg --type ts 'title="[^"]+"' --glob '**/AIChat/**' # Test 3: Look for any tests that might need updating echo "Searching for tests that might need updating:" rg --type ts "ChatTitleProps" --glob '**/*.test.ts*'Length of output: 917
Script:
#!/bin/bash # Description: Re-check for potential impacts of the ChatTitleProps change with improved exclusion patterns # Test 1: Look for uses of ChatTitleProps in other files, excluding all types.ts files echo "Searching for uses of ChatTitleProps:" rg --type ts "ChatTitleProps" --glob '!**/types.ts' # Test 2: Check for any hardcoded uses of the title property echo "Checking for hardcoded uses of the title property:" rg --type ts 'title="[^"]+"' --glob '**/AIChat/**' # Test 3: Look for any tests that might need updating echo "Searching for tests that might need updating:" rg --type ts "ChatTitleProps" --glob '**/*.test.ts*'Length of output: 763
app/client/packages/design-system/widgets/src/components/AIChat/src/types.ts (1)
13-13
: Class, pay attention to this change!Good job on renaming the
description
property tochatDescription
. This change improves the clarity of our code and helps avoid potential confusion with other description properties. Remember, clear naming is crucial for maintaining readable and maintainable code.However, we must ensure that all our other code is updated to use this new property name. Don't forget to check your homework!
Let's run a quick pop quiz to make sure we've updated all instances of the old property name:
Class, please review the results of this quiz carefully. If you see any instances of the old 'description' property, make sure to update them!
✅ Verification successful
Alright, class, it looks like our previous search attempts hit a snag because
rg
didn't recognize thetypescript
file type. Let's adjust our approach to ensure we effectively locate all instances of the properties we're interested in.
Excellent work!
The
description
property has been successfully renamed tochatDescription
across the codebase. All instances have been updated accordingly, ensuring consistency and clarity in our code.Keep up the great work!
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any remaining uses of the old 'description' property in AIChatProps # Test 1: Search for 'description' in relation to AIChatProps echo "Test 1: Searching for 'description' in relation to AIChatProps" rg --type typescript "AIChatProps.*description" -C 3 # Test 2: Search for uses of 'chatDescription' echo "Test 2: Searching for uses of 'chatDescription'" rg --type typescript "chatDescription" -C 3 # Explanation of expected results: # Test 1 should ideally return no results, indicating all instances have been updated. # Test 2 should show our new property being used in relevant files.Length of output: 420
Script:
#!/bin/bash # Description: Check for any remaining uses of the old 'description' property in AIChatProps # Test 1: Search for 'description' in relation to AIChatProps in .ts and .tsx files echo "Test 1: Searching for 'description' in relation to AIChatProps in TypeScript files" rg "AIChatProps.*description" --glob "*.ts*" -C 3 # Test 2: Search for uses of 'chatDescription' in .ts and .tsx files echo "Test 2: Searching for uses of 'chatDescription' in TypeScript files" rg "chatDescription" --glob "*.ts*" -C 3 # Explanation of expected results: # Test 1 should ideally return no results, indicating all instances have been updated. # Test 2 should show our new property being used in relevant files.Length of output: 2074
app/client/packages/design-system/widgets/src/components/AIChat/src/ChatTitle/ChatTitle.tsx (1)
8-12
: Well done, class! A gold star for adding a test identifier.Children, pay attention to this excellent addition. The new
data-testid
attribute is like putting your name on your homework - it helps us identify and test this component easily. This is a very responsible thing to do in your code.Remember, just as we use name tags in class to recognize each other, we use these test IDs in our code to help our testing tools recognize different parts of our application. It's a small change, but it makes a big difference in how we can check if everything is working correctly.
Keep up the good work! This change gets an A+.
app/client/packages/design-system/widgets/src/components/AIChat/stories/AIChat.stories.tsx (1)
1-10
: Well done, class! Your imports and meta configuration are spot on.You've correctly imported the necessary components and types, and set up the meta configuration for our AIChat component. This is a great foundation for our Storybook stories.
app/client/packages/design-system/widgets/src/components/AIChat/src/AIChat.tsx (4)
51-53
: Attention to the username display, students!Excellent work adding the data-testid attribute to the Text component! It's like labeling your test tubes in a science experiment. This will make our tests more reliable and easier to write.
57-57
: Now, let's look at our message thread, class.Great job adding the data-testid attribute to the ul element! It's like putting a bookmark in your textbook. This will help us easily find and test our message thread in our test suite.
Line range hint
15-24
: Let's review our component's props, class.Well done on removing the unused 'description' prop! It's like erasing unnecessary notes from your notebook. However, we should make sure this doesn't affect any other parts of our application.
Let's do a quick check to see if 'description' is used elsewhere:
#!/bin/bash # Description: Check if 'description' prop is used in other files # Test: Search for 'description' prop usage in AIChat component rg --type typescript 'description.*AIChatProps' app/client/packages/design-system/widgets
1-1
: Class, let's examine our import statement.Good job removing the unused Spinner import! It's like tidying up your desk before starting your homework. However, we should double-check if we still need the Spinner somewhere else in our code.
Let's run a quick search to make sure we're not missing anything:
✅ Verification successful
Great job removing the unused
Spinner
import!
I’ve verified thatSpinner
is no longer used inAIChat.tsx
, ensuring our codebase stays clean and efficient.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if Spinner is used elsewhere in the component # Test: Search for Spinner usage in the file rg --type typescript 'Spinner' app/client/packages/design-system/widgets/src/components/AIChat/src/AIChat.tsxLength of output: 199
Script:
#!/bin/bash # Description: Check if Spinner is used elsewhere in the AIChat component # Test: Search for Spinner usage in AIChat.tsx without relying on file type rg 'Spinner' app/client/packages/design-system/widgets/src/components/AIChat/src/AIChat.tsxLength of output: 91
app/client/packages/design-system/widgets/src/components/AIChat/tests/AIChat.test.tsx (2)
20-29
: Excellent work on your first test case, students!This test for rendering the chat title is well-crafted. You've used
faker
to generate random data, which is a great practice for robust testing. The assertion is clear and checks exactly what we want to verify.Keep up the good work! Remember, thorough testing is like doing your homework - it pays off in the long run!
66-87
: Wonderful job on these input field tests, students!Your tests for the prompt input placeholder and value are concise and to the point. You've correctly used the appropriate matchers (
toHaveAttribute
andtoHaveValue
) to verify the input field's properties.These tests are like well-written essays - they clearly state what they're checking and then prove it. Keep up the excellent work!
app/client/src/modules/ui-builder/ui/wds/WDSAIChatWidget/widget/index.tsx (1)
207-207
: Well done, class! This change deserves a gold star!Now, let's examine why this modification is praiseworthy:
- It addresses the bug where
username
was undefined.- It employs a common and effective JavaScript pattern to provide a default value.
- This small change significantly enhances the component's reliability.
Remember, children, in programming as in life, it's often the little things that make a big difference. This change is like always bringing a spare pencil to class - it ensures you're prepared, even if something unexpected happens!
isWaitingForResponse={this.state.isWaitingForResponse} | ||
onPromptChange={this.handlePromptChange} | ||
onSubmit={this.handleMessageSubmit} | ||
prompt={this.state.prompt} | ||
promptInputPlaceholder={this.props.promptInputPlaceholder} | ||
thread={this.adaptMessages(this.state.messages)} | ||
username={this.props.username} | ||
username={this.props.username || ""} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to do the check directly in the component, since the consumer does not have to validate edge cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is actually not about edge cases, but about the contract. I made some props required, some optional. There is no one proper answer. Current contract seems reasonable to me. If you don't find them so, let's discuss it later, since this PR is only about covering current one.
Description
username
isundefined
Fixes #
Issue Number
or
Fixes
Issue URL
Warning
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.
Automation
/ok-to-test tags="@tag.Sanity"
🔍 Cypress test results
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11177693011
Commit: ba99a27
Cypress dashboard.
Tags:
@tag.Sanity
Spec:
Fri, 04 Oct 2024 10:27:03 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
Release Notes
New Features
AIChat
component, showcasing various states includingMain
,EmptyHistory
,Loading
, andWithHistory
.Improvements
AIChat
andChatTitle
components by addingdata-testid
attributes.AIChat
component to streamline props and improve rendering logic.Bug Fixes
username
prop defaults to an empty string in theWDSAIChatWidget
component.Tests
AIChat
component, validating its rendering and functionality across different scenarios.