-
Notifications
You must be signed in to change notification settings - Fork 244
chore(compass-assistant): fix assistant tests #7228
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import { | |
| LgChatMessage, | ||
| LgChatMessageFeed, | ||
| LgChatInputBar, | ||
| spacing, | ||
| css, | ||
| } from '@mongodb-js/compass-components'; | ||
|
|
||
| const { ChatWindow } = LgChatChatWindow; | ||
|
|
@@ -20,6 +22,20 @@ interface AssistantChatProps { | |
| chat: Chat<AssistantMessage>; | ||
| } | ||
|
|
||
| // TODO(COMPASS-9751): These are temporary patches to make the Assistant chat take the entire | ||
| // width and height of the drawer since Leafygreen doesn't support this yet. | ||
| const assistantChatFixesStyles = css({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These aren't required for the tests but are CSS patchups that I feel like I might as well include here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raised both with LG |
||
| // Negative margin to patch the padding of the drawer. | ||
| margin: -spacing[400], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're doing more or less the same for data modeling, I wonder if we should move this to our drawer portal already
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we will raise this with Leafygreen to confirm they'll also do this and there'll be a discussion about this during the Atlas Chatbots Sync if you'd be interested (invited you as optional) |
||
| '> div, > div > div, > div > div > div, > div > div > div > div': { | ||
| height: '100%', | ||
| }, | ||
| }); | ||
| const messageFeedFixesStyles = css({ height: '100%' }); | ||
| const chatWindowFixesStyles = css({ | ||
| height: '100%', | ||
| }); | ||
|
|
||
| export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | ||
| chat, | ||
| }) => { | ||
|
|
@@ -42,19 +58,30 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({ | |
|
|
||
| const handleMessageSend = useCallback( | ||
| (messageBody: string) => { | ||
| void sendMessage({ text: messageBody }); | ||
| const trimmedMessageBody = messageBody.trim(); | ||
| if (trimmedMessageBody) { | ||
| void sendMessage({ text: trimmedMessageBody }); | ||
| } | ||
| }, | ||
| [sendMessage] | ||
| ); | ||
|
|
||
| return ( | ||
| <div data-testid="assistant-chat" style={{ height: '100%', width: '100%' }}> | ||
| <div | ||
| data-testid="assistant-chat" | ||
| className={assistantChatFixesStyles} | ||
| style={{ height: '100%', width: '100%' }} | ||
| > | ||
| <LeafyGreenChatProvider variant={Variant.Compact}> | ||
| <ChatWindow title="MongoDB Assistant"> | ||
| <MessageFeed data-testid="assistant-chat-messages"> | ||
| <ChatWindow title="MongoDB Assistant" className={chatWindowFixesStyles}> | ||
| <MessageFeed | ||
| data-testid="assistant-chat-messages" | ||
| className={messageFeedFixesStyles} | ||
| > | ||
| {lgMessages.map((messageFields) => ( | ||
| <Message | ||
| key={messageFields.id} | ||
| sourceType="markdown" | ||
| {...messageFields} | ||
| data-testid={`assistant-message-${messageFields.id}`} | ||
| /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ import { | |
| } from '@mongodb-js/compass-components'; | ||
| import type { AtlasService } from '@mongodb-js/atlas-service/provider'; | ||
| import { CompassAssistantDrawer } from './compass-assistant-drawer'; | ||
| import { createMockChat } from '../test/utils'; | ||
| import { createMockChat, withMockedScrollTo } from '../test/utils'; | ||
|
|
||
| // Test component that renders AssistantProvider with children | ||
| const TestComponent: React.FunctionComponent<{ | ||
|
|
@@ -84,8 +84,8 @@ describe('AssistantProvider', function () { | |
| ); | ||
| }); | ||
|
|
||
| // TODO: some internal logic in lg-chat breaks all these tests, re-enable the tests | ||
| describe.skip('with existing chat instance', function () { | ||
| describe('with existing chat instance', function () { | ||
| withMockedScrollTo(); | ||
| before(function () { | ||
| // TODO(COMPASS-9618): skip in electron runtime for now, drawer has issues rendering | ||
| if ((process as any).type === 'renderer') { | ||
|
|
@@ -118,7 +118,7 @@ describe('AssistantProvider', function () { | |
| ); | ||
|
|
||
| expect(screen.getByTestId('assistant-message-2')).to.exist; | ||
| expect(screen.getByTestId('assistant-message-2')).to.have.text( | ||
| expect(screen.getByTestId('assistant-message-2')).to.contain.text( | ||
| 'Test assistant message' | ||
| ); | ||
| }); | ||
|
|
@@ -138,8 +138,10 @@ describe('AssistantProvider', function () { | |
|
|
||
| await renderOpenAssistantDrawer(mockChat); | ||
|
|
||
| const input = screen.getByTestId('assistant-chat-input'); | ||
| const sendButton = screen.getByTestId('assistant-chat-send-button'); | ||
| const input = screen.getByPlaceholderText( | ||
| 'Ask MongoDB Assistant a question' | ||
| ); | ||
| const sendButton = screen.getByLabelText('Send message'); | ||
|
|
||
| userEvent.type(input, 'Hello assistant'); | ||
| userEvent.click(sendButton); | ||
|
|
@@ -176,10 +178,10 @@ describe('AssistantProvider', function () { | |
| await renderOpenAssistantDrawer(mockChat); | ||
|
|
||
| userEvent.type( | ||
| screen.getByTestId('assistant-chat-input'), | ||
| screen.getByPlaceholderText('Ask MongoDB Assistant a question'), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A good example of how not relying on test-ids would save us some refactoring time 🙂
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. funnily enough I opted for testids back then because I thought this would be less design dependent but the inability to pass it to specific subcomments did backfire.. agree generally though, with the only risk being stuff like text being duplicated in multiple components which is something I ran into a lot with context menu tests |
||
| 'Hello assistant!' | ||
| ); | ||
| userEvent.click(screen.getByTestId('assistant-chat-send-button')); | ||
| userEvent.click(screen.getByLabelText('Send message')); | ||
|
|
||
| expect(sendMessageSpy.calledOnce).to.be.true; | ||
| expect(sendMessageSpy.firstCall.args[0]).to.deep.include({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.