Skip to content

Commit cd4bfb1

Browse files
jira-autofix-botclaude
andcommitted
RHOAIENG-58422: Hide welcome prompt when real messages exist in Playground chat
The ChatbotWelcomePrompt was rendered unconditionally when showWelcomePrompt was true, causing placeholder messages to remain visible alongside real user and assistant messages. This adds a check on the message count so the welcome prompt is only shown when there are no real messages (at most the initial bot placeholder). Closes RHOAIENG-58422 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Nick Gagan <ngagan@redhat.com>
1 parent e696068 commit cd4bfb1

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

packages/gen-ai/frontend/src/app/Chatbot/ChatbotConfigInstance.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const ChatbotConfigInstance: React.FC<ChatbotConfigInstanceProps> = ({
136136

137137
return (
138138
<MessageBox position="top">
139-
{showWelcomePrompt && (
139+
{showWelcomePrompt && messagesHook.messages.length <= 1 && (
140140
<ChatbotWelcomePrompt
141141
title={username ? `Hello, ${username}` : 'Hello'}
142142
description={welcomeDescription}

packages/gen-ai/frontend/src/app/Chatbot/__tests__/ChatbotConfigInstance.spec.tsx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import * as React from 'react';
2-
import { act, render } from '@testing-library/react';
2+
import { act, render, screen } from '@testing-library/react';
33
import { useChatbotConfigStore } from '~/app/Chatbot/store/useChatbotConfigStore';
44
import { DEFAULT_CONFIGURATION } from '~/app/Chatbot/store/types';
55
import { DEFAULT_CONFIG_ID } from '~/app/Chatbot/store';
66
import { ChatbotConfigInstance } from '~/app/Chatbot/ChatbotConfigInstance';
77

88
jest.mock('@patternfly/chatbot', () => ({
99
MessageBox: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
10-
ChatbotWelcomePrompt: () => null,
10+
ChatbotWelcomePrompt: (props: Record<string, unknown>) => (
11+
<div data-testid={props['data-testid']}>Welcome</div>
12+
),
1113
}));
1214

1315
jest.mock('~/app/Chatbot/ChatbotMessagesList', () => ({
1416
ChatbotMessages: () => null,
1517
}));
1618

19+
let mockMessages: unknown[] = [];
20+
1721
jest.mock('~/app/Chatbot/hooks/useChatbotMessages', () => ({
1822
__esModule: true,
1923
default: () => ({
20-
messages: [],
24+
get messages() {
25+
return mockMessages;
26+
},
2127
isLoading: false,
2228
isStreamingWithoutContent: false,
2329
modelDisplayName: '',
@@ -117,4 +123,31 @@ describe('ChatbotConfigInstance', () => {
117123
).toBe('vs-inline-new');
118124
});
119125
});
126+
127+
describe('welcome prompt visibility', () => {
128+
beforeEach(() => {
129+
mockMessages = [];
130+
});
131+
132+
it('should show welcome prompt when showWelcomePrompt is true and no real messages exist', () => {
133+
mockMessages = [{ id: '1', role: 'bot', content: 'placeholder' }];
134+
render(<ChatbotConfigInstance {...defaultProps} showWelcomePrompt />);
135+
expect(screen.getByTestId('chatbot-welcome-prompt')).toBeInTheDocument();
136+
});
137+
138+
it('should hide welcome prompt when real messages exist', () => {
139+
mockMessages = [
140+
{ id: '1', role: 'bot', content: 'placeholder' },
141+
{ id: '2', role: 'user', content: 'Hello' },
142+
];
143+
render(<ChatbotConfigInstance {...defaultProps} showWelcomePrompt />);
144+
expect(screen.queryByTestId('chatbot-welcome-prompt')).not.toBeInTheDocument();
145+
});
146+
147+
it('should not show welcome prompt when showWelcomePrompt is false', () => {
148+
mockMessages = [];
149+
render(<ChatbotConfigInstance {...defaultProps} showWelcomePrompt={false} />);
150+
expect(screen.queryByTestId('chatbot-welcome-prompt')).not.toBeInTheDocument();
151+
});
152+
});
120153
});

0 commit comments

Comments
 (0)