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+ // Mock scrollTo method for DOM elements to prevent test failures
15+ before ( function ( ) {
16+ if ( ! Element . prototype . scrollTo ) {
17+ Element . prototype . scrollTo = function ( ) {
18+ // No-op implementation for testing
19+ } ;
20+ }
21+ } ) ;
1022 const mockMessages : AssistantMessage [ ] = [
1123 {
1224 id : 'user' ,
@@ -36,8 +48,10 @@ describe.skip('AssistantChat', function () {
3648 it ( 'renders input field and send button' , function ( ) {
3749 renderWithChat ( [ ] ) ;
3850
39- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
40- const sendButton = screen . getByTestId ( 'assistant-chat-send-button' ) ;
51+ const inputField = screen . getByPlaceholderText (
52+ 'Ask MongoDB Assistant a question'
53+ ) ;
54+ const sendButton = screen . getByLabelText ( 'Send message' ) ;
4155
4256 expect ( inputField ) . to . exist ;
4357 expect ( sendButton ) . to . exist ;
@@ -47,9 +61,9 @@ describe.skip('AssistantChat', function () {
4761 renderWithChat ( [ ] ) ;
4862
4963 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
50- const inputField = screen . getByTestId (
51- 'assistant-chat-input '
52- ) as HTMLInputElement ;
64+ const inputField = screen . getByPlaceholderText (
65+ 'Ask MongoDB Assistant a question '
66+ ) as HTMLTextAreaElement ;
5367
5468 userEvent . type ( inputField , 'What is MongoDB?' ) ;
5569
@@ -60,58 +74,67 @@ describe.skip('AssistantChat', function () {
6074 renderWithChat ( [ ] ) ;
6175
6276 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
63- const sendButton = screen . getByTestId (
64- 'assistant-chat-send-button '
77+ const sendButton = screen . getByLabelText (
78+ 'Send message '
6579 ) as HTMLButtonElement ;
6680
67- expect ( sendButton . disabled ) . to . be . true ;
81+ expect ( sendButton . getAttribute ( 'aria- disabled' ) ) . to . equal ( ' true' ) ;
6882 } ) ;
6983
7084 it ( 'send button is enabled when input has text' , function ( ) {
7185 renderWithChat ( [ ] ) ;
7286
73- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
87+ const inputField = screen . getByPlaceholderText (
88+ 'Ask MongoDB Assistant a question'
89+ ) ;
7490 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
75- const sendButton = screen . getByTestId (
76- 'assistant-chat-send-button '
91+ const sendButton = screen . getByLabelText (
92+ 'Send message '
7793 ) as HTMLButtonElement ;
7894
7995 userEvent . type ( inputField , 'What is MongoDB?' ) ;
8096
8197 expect ( sendButton . disabled ) . to . be . false ;
8298 } ) ;
8399
84- it ( 'send button is disabled for whitespace-only input' , function ( ) {
100+ // Not currently supported by the LeafyGreen Input Bar
101+ it . skip ( 'send button is disabled for whitespace-only input' , async function ( ) {
85102 renderWithChat ( [ ] ) ;
86103
87- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
104+ const inputField = screen . getByPlaceholderText (
105+ 'Ask MongoDB Assistant a question'
106+ ) ;
88107 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
89- const sendButton = screen . getByTestId (
90- 'assistant-chat-send-button '
108+ const sendButton = screen . getByLabelText (
109+ 'Send message '
91110 ) as HTMLButtonElement ;
92111
93112 userEvent . type ( inputField , ' ' ) ;
94113
95- expect ( sendButton . disabled ) . to . be . true ;
114+ await waitFor ( ( ) => {
115+ expect ( sendButton . getAttribute ( 'aria-disabled' ) ) . to . equal ( 'true' ) ;
116+ } ) ;
96117 } ) ;
97118
98119 it ( 'displays messages in the chat feed' , function ( ) {
99120 renderWithChat ( mockMessages ) ;
100121
101122 expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . exist ;
102123 expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . exist ;
103- expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . have . text (
124+ expect ( screen . getByTestId ( 'assistant-message-user' ) ) . to . contain . text (
104125 'Hello, MongoDB Assistant!'
105126 ) ;
106- expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . have . text (
127+ expect ( screen . getByTestId ( 'assistant-message-assistant' ) ) . to . contain . text (
107128 'Hello! How can I help you with MongoDB today?'
108129 ) ;
109130 } ) ;
110131
111132 it ( 'calls sendMessage when form is submitted' , function ( ) {
112133 const { chat } = renderWithChat ( [ ] ) ;
113- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
114- const sendButton = screen . getByTestId ( 'assistant-chat-send-button' ) ;
134+ const inputField = screen . getByPlaceholderText (
135+ 'Ask MongoDB Assistant a question'
136+ ) ;
137+ const sendButton = screen . getByLabelText ( 'Send message' ) ;
115138
116139 userEvent . type ( inputField , 'What is aggregation?' ) ;
117140 userEvent . click ( sendButton ) ;
@@ -124,24 +147,26 @@ describe.skip('AssistantChat', function () {
124147 renderWithChat ( [ ] ) ;
125148
126149 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
127- const inputField = screen . getByTestId (
128- 'assistant-chat-input '
129- ) as HTMLInputElement ;
150+ const inputField = screen . getByPlaceholderText (
151+ 'Ask MongoDB Assistant a question '
152+ ) as HTMLTextAreaElement ;
130153
131154 userEvent . type ( inputField , 'Test message' ) ;
132155 expect ( inputField . value ) . to . equal ( 'Test message' ) ;
133156
134- userEvent . click ( screen . getByTestId ( 'assistant-chat-send-button ') ) ;
157+ userEvent . click ( screen . getByLabelText ( 'Send message ') ) ;
135158 expect ( inputField . value ) . to . equal ( '' ) ;
136159 } ) ;
137160
138161 it ( 'trims whitespace from input before sending' , function ( ) {
139162 const { chat } = renderWithChat ( [ ] ) ;
140163
141- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
164+ const inputField = screen . getByPlaceholderText (
165+ 'Ask MongoDB Assistant a question'
166+ ) ;
142167
143168 userEvent . type ( inputField , ' What is sharding? ' ) ;
144- userEvent . click ( screen . getByTestId ( 'assistant-chat-send-button ') ) ;
169+ userEvent . click ( screen . getByLabelText ( 'Send message ') ) ;
145170
146171 expect ( chat . sendMessage . calledWith ( { text : 'What is sharding?' } ) ) . to . be
147172 . true ;
@@ -150,8 +175,10 @@ describe.skip('AssistantChat', function () {
150175 it ( 'does not call sendMessage when input is empty or whitespace-only' , function ( ) {
151176 const { chat } = renderWithChat ( [ ] ) ;
152177
153- const inputField = screen . getByTestId ( 'assistant-chat-input' ) ;
154- const chatForm = screen . getByTestId ( 'assistant-chat-form' ) ;
178+ const inputField = screen . getByPlaceholderText (
179+ 'Ask MongoDB Assistant a question'
180+ ) ;
181+ const chatForm = screen . getByTestId ( 'assistant-chat-input' ) ;
155182
156183 // Test empty input
157184 userEvent . click ( chatForm ) ;
@@ -169,16 +196,12 @@ describe.skip('AssistantChat', function () {
169196 const userMessage = screen . getByTestId ( 'assistant-message-user' ) ;
170197 const assistantMessage = screen . getByTestId ( 'assistant-message-assistant' ) ;
171198
172- // User messages should have different background color than assistant messages
199+ // User messages should have different class names than assistant messages
173200 expect ( userMessage ) . to . exist ;
174201 expect ( assistantMessage ) . to . exist ;
175202
176- const userStyle = window . getComputedStyle ( userMessage ) ;
177- const assistantStyle = window . getComputedStyle ( assistantMessage ) ;
178-
179- expect ( userStyle . backgroundColor ) . to . not . equal (
180- assistantStyle . backgroundColor
181- ) ;
203+ // Check that they have different class names (indicating different styling)
204+ expect ( userMessage . className ) . to . not . equal ( assistantMessage . className ) ;
182205 } ) ;
183206
184207 it ( 'handles messages with multiple text parts' , function ( ) {
0 commit comments