diff --git a/src/components/UserMessage.integration.test.tsx b/src/components/UserMessage.integration.test.tsx
deleted file mode 100644
index 38747b24..00000000
--- a/src/components/UserMessage.integration.test.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { render, screen } from '@testing-library/react';
-import { UserMessage } from './UserMessage';
-
-describe('UserMessage Integration', () => {
- it('renders text parts with file attachments correctly', () => {
- // Simulate the new text parts structure that ChatPane would create
- const content = [
- { type: 'text' as const, text: 'Please analyze this file:' },
- { type: 'text' as const, text: 'Added file: /tmp/data.csv' },
- { type: 'text' as const, text: 'Let me know what you find!' }
- ];
-
- render();
-
- // Check that regular text is displayed
- expect(screen.getByText('Please analyze this file:')).toBeInTheDocument();
- expect(screen.getByText('Let me know what you find!')).toBeInTheDocument();
-
- // Check that file attachment is rendered as a badge
- expect(screen.getByText('data.csv')).toBeInTheDocument();
- // Full path should not be displayed
- expect(screen.queryByText('/tmp/data.csv')).not.toBeInTheDocument();
- });
-
- it('handles single text part with file attachment', () => {
- const content = [
- { type: 'text' as const, text: 'Added file: /tmp/script.js' }
- ];
-
- render();
-
- expect(screen.getByText('script.js')).toBeInTheDocument();
- // Full path should not be displayed
- expect(screen.queryByText('/tmp/script.js')).not.toBeInTheDocument();
- });
-
- it('handles multiple file attachments in separate parts', () => {
- const content = [
- { type: 'text' as const, text: 'Here are my files:' },
- { type: 'text' as const, text: 'Added file: /tmp/config.json' },
- { type: 'text' as const, text: 'Added file: /tmp/styles.css' },
- { type: 'text' as const, text: 'Added file: /tmp/main.js' }
- ];
-
- render();
-
- expect(screen.getByText('Here are my files:')).toBeInTheDocument();
- expect(screen.getByText('config.json')).toBeInTheDocument();
- expect(screen.getByText('styles.css')).toBeInTheDocument();
- expect(screen.getByText('main.js')).toBeInTheDocument();
- });
-
- it('handles empty content gracefully', () => {
- const content: Array<{ type: 'text'; text: string }> = [];
-
- const { container } = render();
-
- expect(container.firstChild).toBeNull();
- });
-});
\ No newline at end of file
diff --git a/src/components/UserMessage.test.tsx b/src/components/UserMessage.test.tsx
deleted file mode 100644
index 8e992edb..00000000
--- a/src/components/UserMessage.test.tsx
+++ /dev/null
@@ -1,101 +0,0 @@
-import { describe, it, expect } from 'vitest';
-import { render, screen } from '@testing-library/react';
-import { UserMessage } from './UserMessage';
-
-describe('UserMessage', () => {
- it('renders regular text without file attachments', () => {
- const content = 'This is a regular message without any file attachments.';
-
- render();
-
- expect(screen.getByText(content)).toBeInTheDocument();
- });
-
- it('renders file attachment badges for single file with text parts', () => {
- const content = [
- { type: 'text' as const, text: 'Here is my file:' },
- { type: 'text' as const, text: 'Added file: /tmp/test.txt' }
- ];
-
- render();
-
- expect(screen.getByText('Here is my file:')).toBeInTheDocument();
- expect(screen.getByText('test.txt')).toBeInTheDocument();
- // Full path should not be displayed
- expect(screen.queryByText('/tmp/test.txt')).not.toBeInTheDocument();
- });
-
- it('renders multiple file attachments with text parts', () => {
- const content = [
- { type: 'text' as const, text: 'Files uploaded:' },
- { type: 'text' as const, text: 'Added file: /tmp/document.pdf' },
- { type: 'text' as const, text: 'Added file: /tmp/image.jpg' },
- { type: 'text' as const, text: 'All done!' }
- ];
-
- render();
-
- expect(screen.getByText('Files uploaded:')).toBeInTheDocument();
- expect(screen.getByText('document.pdf')).toBeInTheDocument();
- expect(screen.getByText('image.jpg')).toBeInTheDocument();
- expect(screen.getByText('All done!')).toBeInTheDocument();
- });
-
- it('renders text files with FileText icon', () => {
- const content = [{ type: 'text' as const, text: 'Added file: /tmp/script.js' }];
-
- render();
-
- expect(screen.getByText('script.js')).toBeInTheDocument();
- // FileText icon should be rendered (we can't easily test the icon itself, but we can test the component renders)
- });
-
- it('handles files without extensions', () => {
- const content = [{ type: 'text' as const, text: 'Added file: /tmp/README' }];
-
- render();
-
- expect(screen.getByText('README')).toBeInTheDocument();
- // Full path should not be displayed
- expect(screen.queryByText('/tmp/README')).not.toBeInTheDocument();
- });
-
- it('handles complex filenames with underscores and numbers', () => {
- const content = [{ type: 'text' as const, text: 'Added file: /tmp/my_file_1.txt' }];
-
- render();
-
- expect(screen.getByText('my_file_1.txt')).toBeInTheDocument();
- // Full path should not be displayed
- expect(screen.queryByText('/tmp/my_file_1.txt')).not.toBeInTheDocument();
- });
-
- it('preserves whitespace in text content', () => {
- const content = [
- { type: 'text' as const, text: 'Line 1\n\nLine 3 with spaces \n\nFinal line' },
- { type: 'text' as const, text: 'Added file: /tmp/test.txt' }
- ];
-
- const { container } = render();
-
- // Check that the component renders and contains the expected text content
- expect(container.textContent).toContain('Line 1');
- expect(container.textContent).toContain('Line 3 with spaces');
- expect(container.textContent).toContain('Final line');
- expect(screen.getByText('test.txt')).toBeInTheDocument();
- });
-
- it('handles mixed content with file attachments in the middle', () => {
- const content = [
- { type: 'text' as const, text: 'Starting text' },
- { type: 'text' as const, text: 'Added file: /tmp/middle.txt' },
- { type: 'text' as const, text: 'ending text' }
- ];
-
- render();
-
- expect(screen.getByText('Starting text')).toBeInTheDocument();
- expect(screen.getByText('middle.txt')).toBeInTheDocument();
- expect(screen.getByText('ending text')).toBeInTheDocument();
- });
-});
\ No newline at end of file
diff --git a/src/components/UserMessage.tsx b/src/components/UserMessage.tsx
index 2e72291d..1abcd883 100644
--- a/src/components/UserMessage.tsx
+++ b/src/components/UserMessage.tsx
@@ -20,9 +20,15 @@ export function UserMessage({ content }: UserMessageProps) {
// Process each content part and categorize as text or file
const processedParts: Array<{ type: 'text' | 'file'; content: string; filepath?: string }> = [];
- contentParts.forEach(part => {
+ contentParts.forEach((part, index) => {
const text = part.text.trim();
+ // First content part is always treated as text
+ if (index === 0) {
+ processedParts.push({ type: 'text', content: text });
+ return;
+ }
+
// Matches the pattern anywhere in the text
// Regular expression to match "Added file: " patterns
const filePattern = /^Added file: (\/[^\s\n]+$)/g;