Skip to content

Commit 8bb6049

Browse files
committed
chore: add better LG loading state
1 parent ff96293 commit 8bb6049

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

packages/compass-assistant/src/assistant-chat.spec.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff 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(/MongoDB Assistant is thinking/)).to.exist;
94+
});
95+
96+
it('does not display loading in all other cases', function () {
97+
renderWithChat(mockMessages, { status: 'streaming' });
98+
expect(screen.queryByText(/MongoDB Assistant is thinking/)).to.not.exist;
99+
});
100+
84101
it('send button is disabled when input is empty', function () {
85102
renderWithChat([]);
86103

packages/compass-assistant/src/assistant-chat.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff 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
}}

packages/compass-assistant/test/utils.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ import type { AssistantMessage } from '../src/compass-assistant-provider';
44

55
export 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
};

0 commit comments

Comments
 (0)