refactor(comments): extract CommentMessage component from CommentThread (#198)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
40
frontend/src/lib/utils/comment.spec.ts
Normal file
40
frontend/src/lib/utils/comment.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { extractQuote } from './comment';
|
||||
|
||||
describe('extractQuote', () => {
|
||||
it('returns null quote and full body for plain text', () => {
|
||||
const result = extractQuote('Hello world');
|
||||
expect(result.quote).toBeNull();
|
||||
expect(result.body).toBe('Hello world');
|
||||
});
|
||||
|
||||
it('extracts quote and body with double newline separator', () => {
|
||||
const result = extractQuote('> "Some quoted text"\n\nReply body');
|
||||
expect(result.quote).toBe('Some quoted text');
|
||||
expect(result.body).toBe('Reply body');
|
||||
});
|
||||
|
||||
it('extracts quote and body with single newline separator', () => {
|
||||
const result = extractQuote('> "Quote"\nBody');
|
||||
expect(result.quote).toBe('Quote');
|
||||
expect(result.body).toBe('Body');
|
||||
});
|
||||
|
||||
it('returns null quote when format does not match', () => {
|
||||
const result = extractQuote('> Not a quote format');
|
||||
expect(result.quote).toBeNull();
|
||||
expect(result.body).toBe('> Not a quote format');
|
||||
});
|
||||
|
||||
it('handles empty string', () => {
|
||||
const result = extractQuote('');
|
||||
expect(result.quote).toBeNull();
|
||||
expect(result.body).toBe('');
|
||||
});
|
||||
|
||||
it('does not match when quotes are missing', () => {
|
||||
const result = extractQuote('> just a blockquote\n\nbody');
|
||||
expect(result.quote).toBeNull();
|
||||
expect(result.body).toBe('> just a blockquote\n\nbody');
|
||||
});
|
||||
});
|
||||
5
frontend/src/lib/utils/comment.ts
Normal file
5
frontend/src/lib/utils/comment.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export function extractQuote(content: string): { quote: string | null; body: string } {
|
||||
const match = content.match(/^>\s*"(.+?)"\s*\n\n?([\s\S]*)$/);
|
||||
if (match) return { quote: match[1], body: match[2] };
|
||||
return { quote: null, body: content };
|
||||
}
|
||||
Reference in New Issue
Block a user