File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed
packages/compass-assistant Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,15 @@ describe('AssistantChat', function () {
2929 } ,
3030 ] ;
3131
32- function renderWithChat ( messages : AssistantMessage [ ] ) {
33- const chat = createMockChat ( { messages } ) ;
32+ function renderWithChat (
33+ messages : AssistantMessage [ ] ,
34+ {
35+ status,
36+ } : {
37+ status ?: 'submitted' | 'streaming' ;
38+ } = { }
39+ ) {
40+ const chat = createMockChat ( { messages, status } ) ;
3441 const result = render ( < AssistantChat chat = { chat } /> ) ;
3542 return {
3643 result,
@@ -81,6 +88,16 @@ describe('AssistantChat', function () {
8188 . exist ;
8289 } ) ;
8390
91+ it ( 'displays loading state when chat status is submitted' , function ( ) {
92+ renderWithChat ( [ ] , { status : 'submitted' } ) ;
93+ expect ( screen . getByText ( / M o n g o D B A s s i s t a n t i s t h i n k i n g / ) ) . to . exist ;
94+ } ) ;
95+
96+ it ( 'does not display loading in all other cases' , function ( ) {
97+ renderWithChat ( mockMessages , { status : 'streaming' } ) ;
98+ expect ( screen . queryByText ( / M o n g o D B A s s i s t a n t i s t h i n k i n g / ) ) . to . not . exist ;
99+ } ) ;
100+
84101 it ( 'send button is disabled when input is empty' , function ( ) {
85102 renderWithChat ( [ ] ) ;
86103
Original file line number Diff line number Diff line change @@ -228,13 +228,6 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
228228 ) }
229229 </ Message >
230230 ) ) }
231- { status === 'submitted' && (
232- < Message
233- id = "loading"
234- messageBody = "Thinking..."
235- isSender = { false }
236- />
237- ) }
238231 </ MessageFeed >
239232 { error && (
240233 < div className = { errorBannerWrapperStyles } >
@@ -254,6 +247,7 @@ export const AssistantChat: React.FunctionComponent<AssistantChatProps> = ({
254247 data-testid = "assistant-chat-input"
255248 onMessageSend = { handleMessageSend }
256249 className = { inputBarFixesStyles }
250+ state = { status === 'submitted' ? 'loading' : undefined }
257251 textareaProps = { {
258252 placeholder : 'Ask MongoDB Assistant a question' ,
259253 } }
Original file line number Diff line number Diff line change @@ -4,13 +4,18 @@ import type { AssistantMessage } from '../src/compass-assistant-provider';
44
55export const createMockChat = ( {
66 messages,
7+ status,
78} : {
89 messages : AssistantMessage [ ] ;
10+ status ?: 'submitted' | 'streaming' ;
911} ) => {
1012 const newChat = new Chat < AssistantMessage > ( {
1113 messages,
1214 } ) ;
1315 sinon . replace ( newChat , 'sendMessage' , sinon . stub ( ) ) ;
16+ if ( status ) {
17+ sinon . replaceGetter ( newChat , 'status' , ( ) => status ) ;
18+ }
1419 return newChat as unknown as Chat < AssistantMessage > & {
1520 sendMessage : sinon . SinonStub ;
1621 } ;
You can’t perform that action at this time.
0 commit comments