11import React from 'react' ;
2- import { render , screen , userEvent } from '@mongodb-js/testing-library-compass' ;
2+ import {
3+ render ,
4+ screen ,
5+ userEvent ,
6+ waitFor ,
7+ } from '@mongodb-js/testing-library-compass' ;
38import { AssistantChat } from './assistant-chat' ;
49import { expect } from 'chai' ;
510import { createMockChat } from '../test/utils' ;
611import type { AssistantMessage } from './compass-assistant-provider' ;
712
8- // TODO: some internal logic in lg-chat breaks all these tests, re-enable the tests
9- describe . skip ( 'AssistantChat' , function ( ) {
13+ describe ( 'AssistantChat' , function ( ) {
14+ let originalScrollTo : typeof Element . prototype . scrollTo ;
15+ // Mock scrollTo method for DOM elements to prevent test failures
16+ before ( function ( ) {
17+ originalScrollTo = Element . prototype . scrollTo . bind ( Element . prototype ) ;
18+ Element . prototype . scrollTo = ( ) => { } ;
19+ } ) ;
20+ after ( function ( ) {
21+ Element . prototype . scrollTo = originalScrollTo ;
22+ } ) ;
23+
1024 const mockMessages : AssistantMessage [ ] = [
1125 {
1226 id : 'user' ,
@@ -36,8 +50,10 @@ describe.skip('AssistantChat', function () {
3650 it ( 'renders input field and send button' , function ( ) {
3751 renderWithChat ( [ ] ) ;
3852
39- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
40- const sendButton = screen . getByTestId ( 'assistant-chat-send-button' ) ;
53+ const inputField = screen . getByPlaceholderText (
54+ 'Ask MongoDB Assistant a question'
55+ ) ;
56+ const sendButton = screen . getByLabelText ( 'Send message' ) ;
4157
4258 expect ( inputField ) . to . exist ;
4359 expect ( sendButton ) . to . exist ;
@@ -47,9 +63,9 @@ describe.skip('AssistantChat', function () {
4763 renderWithChat ( [ ] ) ;
4864
4965 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
50- const inputField = screen . getByTestId (
51- 'assistant-chat-input '
52- ) as HTMLInputElement ;
66+ const inputField = screen . getByPlaceholderText (
67+ 'Ask MongoDB Assistant a question '
68+ ) as HTMLTextAreaElement ;
5369
5470 userEvent . type ( inputField , 'What is MongoDB?' ) ;
5571
@@ -60,58 +76,67 @@ describe.skip('AssistantChat', function () {
6076 renderWithChat ( [ ] ) ;
6177
6278 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
63- const sendButton = screen . getByTestId (
64- 'assistant-chat-send-button '
79+ const sendButton = screen . getByLabelText (
80+ 'Send message '
6581 ) as HTMLButtonElement ;
6682
67- expect ( sendButton . disabled ) . to . be . true ;
83+ expect ( sendButton . getAttribute ( 'aria- disabled' ) ) . to . equal ( ' true' ) ;
6884 } ) ;
6985
7086 it ( 'send button is enabled when input has text' , function ( ) {
7187 renderWithChat ( [ ] ) ;
7288
73- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
89+ const inputField = screen . getByPlaceholderText (
90+ 'Ask MongoDB Assistant a question'
91+ ) ;
7492 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
75- const sendButton = screen . getByTestId (
76- 'assistant-chat-send-button '
93+ const sendButton = screen . getByLabelText (
94+ 'Send message '
7795 ) as HTMLButtonElement ;
7896
7997 userEvent . type ( inputField , 'What is MongoDB?' ) ;
8098
8199 expect ( sendButton . disabled ) . to . be . false ;
82100 } ) ;
83101
84- it ( 'send button is disabled for whitespace-only input' , function ( ) {
102+ // Not currently supported by the LeafyGreen Input Bar
103+ it . skip ( 'send button is disabled for whitespace-only input' , async function ( ) {
85104 renderWithChat ( [ ] ) ;
86105
87- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
106+ const inputField = screen . getByPlaceholderText (
107+ 'Ask MongoDB Assistant a question'
108+ ) ;
88109 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
89- const sendButton = screen . getByTestId (
90- 'assistant-chat-send-button '
110+ const sendButton = screen . getByLabelText (
111+ 'Send message '
91112 ) as HTMLButtonElement ;
92113
93114 userEvent . type ( inputField , ' ' ) ;
94115
95- expect ( sendButton . disabled ) . to . be . true ;
116+ await waitFor ( ( ) => {
117+ expect ( sendButton . getAttribute ( 'aria-disabled' ) ) . to . equal ( 'true' ) ;
118+ } ) ;
96119 } ) ;
97120
98121 it ( 'displays messages in the chat feed' , function ( ) {
99122 renderWithChat ( mockMessages ) ;
100123
101124 expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . exist ;
102125 expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . exist ;
103- expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . have . text (
126+ expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . contain . text (
104127 'Hello, MongoDB Assistant!'
105128 ) ;
106- expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . have . text (
129+ expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . contain . text (
107130 'Hello! How can I help you with MongoDB today?'
108131 ) ;
109132 } ) ;
110133
111134 it ( 'calls sendMessage when form is submitted' , function ( ) {
112135 const { chat } = renderWithChat ( [ ] ) ;
113- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
114- const sendButton = screen . getByTestId ( 'assistant-chat-send-button' ) ;
136+ const inputField = screen . getByPlaceholderText (
137+ 'Ask MongoDB Assistant a question'
138+ ) ;
139+ const sendButton = screen . getByLabelText ( 'Send message' ) ;
115140
116141 userEvent . type ( inputField , 'What is aggregation?' ) ;
117142 userEvent . click ( sendButton ) ;
@@ -124,24 +149,26 @@ describe.skip('AssistantChat', function () {
124149 renderWithChat ( [ ] ) ;
125150
126151 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
127- const inputField = screen . getByTestId (
128- 'assistant-chat-input '
129- ) as HTMLInputElement ;
152+ const inputField = screen . getByPlaceholderText (
153+ 'Ask MongoDB Assistant a question '
154+ ) as HTMLTextAreaElement ;
130155
131156 userEvent . type ( inputField , 'Test message' ) ;
132157 expect ( inputField . value ) . to . equal ( 'Test message' ) ;
133158
134- userEvent . click ( screen . getByTestId ( 'assistant-chat-send-button ') ) ;
159+ userEvent . click ( screen . getByLabelText ( 'Send message ') ) ;
135160 expect ( inputField . value ) . to . equal ( '' ) ;
136161 } ) ;
137162
138163 it ( 'trims whitespace from input before sending' , function ( ) {
139164 const { chat } = renderWithChat ( [ ] ) ;
140165
141- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
166+ const inputField = screen . getByPlaceholderText (
167+ 'Ask MongoDB Assistant a question'
168+ ) ;
142169
143170 userEvent . type ( inputField , ' What is sharding? ' ) ;
144- userEvent . click ( screen . getByTestId ( 'assistant-chat-send-button ') ) ;
171+ userEvent . click ( screen . getByLabelText ( 'Send message ') ) ;
145172
146173 expect ( chat . sendMessage . calledWith ( { text : 'What is sharding?' } ) ) . to . be
147174 . true ;
@@ -150,8 +177,10 @@ describe.skip('AssistantChat', function () {
150177 it ( 'does not call sendMessage when input is empty or whitespace-only' , function ( ) {
151178 const { chat } = renderWithChat ( [ ] ) ;
152179
153- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
154- const chatForm = screen . getByTestId ( 'assistant-chat-form' ) ;
180+ const inputField = screen . getByPlaceholderText (
181+ 'Ask MongoDB Assistant a question'
182+ ) ;
183+ const chatForm = screen . getByTestId ( 'assistant-chat-input' ) ;
155184
156185 // Test empty input
157186 userEvent . click ( chatForm ) ;
@@ -169,16 +198,12 @@ describe.skip('AssistantChat', function () {
169198 const userMessage = screen . getByTestId ( 'assistant-message-user' ) ;
170199 const assistantMessage = screen . getByTestId ( 'assistant-message-assistant' ) ;
171200
172- // User messages should have different background color than assistant messages
201+ // User messages should have different class names than assistant messages
173202 expect ( userMessage ) . to . exist ;
174203 expect ( assistantMessage ) . to . exist ;
175204
176- const userStyle = window . getComputedStyle ( userMessage ) ;
177- const assistantStyle = window . getComputedStyle ( assistantMessage ) ;
178-
179- expect ( userStyle . backgroundColor ) . to . not . equal (
180- assistantStyle . backgroundColor
181- ) ;
205+ // Check that they have different class names (indicating different styling)
206+ expect ( userMessage . className ) . to . not . equal ( assistantMessage . className ) ;
182207 } ) ;
183208
184209 it ( 'handles messages with multiple text parts' , function ( ) {
0 commit comments