Skip to content

Commit cda45d3

Browse files
jira-autofix-botclaude
andcommitted
RHOAIENG-58422: Replace magic number check with semantic user-message check
Address review feedback by replacing `messages.length <= 1` with an explicit check for user messages (`!messages.some(m => m.role === 'user')`). This eliminates the magic number that depended on knowing the initial bot message always occupies index 0, making the intent clear: the welcome prompt hides only when a user has actually sent a message. Added a test for the empty-messages edge case. The CI failures (Contract-Tests, test-and-build) were caused by a transient npm ETIMEDOUT in model-registry install and a pre-existing flaky mcpTab Cypress test — neither is related to this change. Closes RHOAIENG-58422 Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Nick Gagan <ngagan@redhat.com>
1 parent cd4bfb1 commit cda45d3

2 files changed

Lines changed: 9 additions & 3 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 && messagesHook.messages.length <= 1 && (
139+
{showWelcomePrompt && !messagesHook.messages.some((m) => m.role === 'user') && (
140140
<ChatbotWelcomePrompt
141141
title={username ? `Hello, ${username}` : 'Hello'}
142142
description={welcomeDescription}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ describe('ChatbotConfigInstance', () => {
129129
mockMessages = [];
130130
});
131131

132-
it('should show welcome prompt when showWelcomePrompt is true and no real messages exist', () => {
132+
it('should show welcome prompt when showWelcomePrompt is true and no user messages exist', () => {
133133
mockMessages = [{ id: '1', role: 'bot', content: 'placeholder' }];
134134
render(<ChatbotConfigInstance {...defaultProps} showWelcomePrompt />);
135135
expect(screen.getByTestId('chatbot-welcome-prompt')).toBeInTheDocument();
136136
});
137137

138-
it('should hide welcome prompt when real messages exist', () => {
138+
it('should show welcome prompt when messages array is empty', () => {
139+
mockMessages = [];
140+
render(<ChatbotConfigInstance {...defaultProps} showWelcomePrompt />);
141+
expect(screen.getByTestId('chatbot-welcome-prompt')).toBeInTheDocument();
142+
});
143+
144+
it('should hide welcome prompt when a user message exists', () => {
139145
mockMessages = [
140146
{ id: '1', role: 'bot', content: 'placeholder' },
141147
{ id: '2', role: 'user', content: 'Hello' },

0 commit comments

Comments
 (0)