agent-ecosystem/test/renderer/utils/mentionLinkify.test.ts
iliya bec8a6184a fix: refine regex patterns and improve utility functions for mention handling
- Updated regex patterns in chipUtils and mentionLinkify to enhance boundary detection for mentions.
- Refactored taskChangeRequest to simplify earliest date calculation using array destructuring.
- Improved taskReferenceUtils by replacing character boundary checks with a more concise regex.
- Enhanced teamMessageFiltering to ensure boolean checks for message filtering conditions.
- Adjusted urlMatchUtils to refine URL matching regex for better accuracy.
- Updated crossTeam constants to include comments for regex patterns, improving code clarity.
- Removed unused CommentAttachmentPayload type from api.ts to clean up type definitions.
- Introduced McpInstallScope type for better type safety in mcp.ts.
- Enhanced extensionNormalizers to improve URL normalization and added tests for parseGitHubOwnerRepo function.
- Cleaned up pricing.ts by removing unnecessary eslint disable comments.
- Added tests for new functionality in chipUtils and crossTeam constants, ensuring robust coverage.
2026-03-19 13:35:51 +02:00

65 lines
2.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
linkifyAllMentionsInMarkdown,
linkifyMentionsInMarkdown,
linkifyTeamMentionsInMarkdown,
} from '@renderer/utils/mentionLinkify';
describe('mentionLinkify', () => {
it('linkifies @member after space', () => {
const m = new Map([['Alice', 'blue']]);
const r = linkifyMentionsInMarkdown('hello @Alice world', m);
expect(r).toContain('mention://');
expect(r).toContain('Alice');
expect(r).not.toBe('hello @Alice world');
});
it('does NOT linkify @ in email', () => {
const m = new Map([['Alice', 'blue']]);
const r = linkifyMentionsInMarkdown('email@test.com', m);
expect(r).toBe('email@test.com');
});
it('linkifies @team after (', () => {
const r = linkifyTeamMentionsInMarkdown('(@TeamAlpha)', ['TeamAlpha']);
expect(r).toContain('team://');
expect(r).toContain('TeamAlpha');
});
it('linkifyAll applies both member and team', () => {
const m = new Map([['Alice', 'blue']]);
const r = linkifyAllMentionsInMarkdown('Hi @Alice from @TeamX', m, ['TeamX']);
expect(r).toContain('mention://');
expect(r).toContain('team://');
});
it('linkifies @ after start of string', () => {
const m = new Map([['Alice', 'blue']]);
const r = linkifyMentionsInMarkdown('@Alice hello', m);
expect(r).toContain('mention://');
});
it('linkifies @ after [ { (', () => {
const m = new Map([['Bob', 'red']]);
expect(linkifyMentionsInMarkdown('[@Bob]', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('{@Bob}', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('(@Bob)', m)).toContain('mention://');
});
it('does NOT linkify @ when followed by word char', () => {
const m = new Map([['Alice', 'blue']]);
expect(linkifyMentionsInMarkdown('@AliceX', m)).toBe('@AliceX');
expect(linkifyMentionsInMarkdown('@Alice123', m)).toBe('@Alice123');
});
it('linkifies when followed by boundary: space, comma, dot, ), ], }', () => {
const m = new Map([['Alice', 'blue']]);
expect(linkifyMentionsInMarkdown('@Alice ', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('@Alice,', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('@Alice.', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('@Alice)', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('@Alice]', m)).toContain('mention://');
expect(linkifyMentionsInMarkdown('@Alice}', m)).toContain('mention://');
});
});