mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00

* Add unit tests for Markdown utility functions and CodeClassNameEnum. (#4716) Co-authored-by: gru-agent[bot] <185149714+gru-agent[bot]@users.noreply.github.com> * Add unit tests for authChatCrud and authCollectionInChat functions in chat service. (#4718) Co-authored-by: gru-agent[bot] <185149714+gru-agent[bot]@users.noreply.github.com> --------- Co-authored-by: gru-agent[bot] <185149714+gru-agent[bot]@users.noreply.github.com>
60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
||
import { mdTextFormat, CodeClassNameEnum } from '@/components/Markdown/utils';
|
||
|
||
describe('Markdown utils', () => {
|
||
describe('mdTextFormat', () => {
|
||
it('should format latex expressions correctly', () => {
|
||
const input = 'Here is some math: \\[x^2 + y^2 = z^2\\] and inline \\(a+b=c\\)';
|
||
const expected = 'Here is some math: $$x^2 + y^2 = z^2$$ and inline $a+b=c$';
|
||
expect(mdTextFormat(input)).toBe(expected);
|
||
});
|
||
|
||
it('should not format latex expressions inside code blocks', () => {
|
||
const input = '```math\n\\[x^2\\]\n```\n`\\[y^2\\]`';
|
||
expect(mdTextFormat(input)).toBe(input);
|
||
});
|
||
|
||
it('should convert quote references to proper markdown links', () => {
|
||
const input = '[123456789012345678901234]';
|
||
const expected = '[123456789012345678901234](QUOTE)';
|
||
expect(mdTextFormat(input)).toBe(expected);
|
||
});
|
||
|
||
it('should not convert invalid quote references', () => {
|
||
const input = '[12345] [abcdef] [123456789012345678901234](test)';
|
||
expect(mdTextFormat(input)).toBe(input);
|
||
});
|
||
|
||
it('should add spaces between URLs and Chinese punctuation', () => {
|
||
const input = 'Check https://example.com,here。';
|
||
const expected = 'Check https://example.com ,here。';
|
||
expect(mdTextFormat(input)).toBe(expected);
|
||
});
|
||
|
||
it('should handle complex text with multiple patterns', () => {
|
||
const input =
|
||
'Math \\[x^2\\] with link https://test.com,and quote [123456789012345678901234]';
|
||
const expected =
|
||
'Math $$x^2$$ with link https://test.com ,and quote [123456789012345678901234](QUOTE)';
|
||
expect(mdTextFormat(input)).toBe(expected);
|
||
});
|
||
});
|
||
|
||
describe('CodeClassNameEnum', () => {
|
||
it('should have correct enum values', () => {
|
||
expect(CodeClassNameEnum.guide).toBe('guide');
|
||
expect(CodeClassNameEnum.questionguide).toBe('questionguide');
|
||
expect(CodeClassNameEnum.mermaid).toBe('mermaid');
|
||
expect(CodeClassNameEnum.echarts).toBe('echarts');
|
||
expect(CodeClassNameEnum.quote).toBe('quote');
|
||
expect(CodeClassNameEnum.files).toBe('files');
|
||
expect(CodeClassNameEnum.latex).toBe('latex');
|
||
expect(CodeClassNameEnum.iframe).toBe('iframe');
|
||
expect(CodeClassNameEnum.html).toBe('html');
|
||
expect(CodeClassNameEnum.svg).toBe('svg');
|
||
expect(CodeClassNameEnum.video).toBe('video');
|
||
expect(CodeClassNameEnum.audio).toBe('audio');
|
||
});
|
||
});
|
||
});
|