mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-18 02:32:28 +02:00
refactor(content-blog): replace reading-time
with Intl.Segmenter
API (#11138)
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
c419d7ec88
commit
9f6360ba82
13 changed files with 96 additions and 69 deletions
|
@ -9,48 +9,46 @@ import {calculateReadingTime} from '../readingTime';
|
|||
|
||||
describe('calculateReadingTime', () => {
|
||||
it('calculates reading time for empty content', () => {
|
||||
expect(calculateReadingTime('')).toBe(0);
|
||||
expect(calculateReadingTime('', 'en')).toBe(0);
|
||||
});
|
||||
|
||||
it('calculates reading time for short content', () => {
|
||||
const content = 'This is a short test content.';
|
||||
expect(calculateReadingTime(content)).toBe(0.03);
|
||||
expect(calculateReadingTime(content, 'en')).toBe(0.03);
|
||||
});
|
||||
|
||||
it('calculates reading time for long content', () => {
|
||||
const content = 'This is a test content. '.repeat(100);
|
||||
expect(calculateReadingTime(content)).toBe(2.5);
|
||||
expect(calculateReadingTime(content, 'en')).toBe(2.5);
|
||||
});
|
||||
|
||||
it('respects custom words per minute', () => {
|
||||
const content = 'This is a test content. '.repeat(100);
|
||||
expect(calculateReadingTime(content, {wordsPerMinute: 100})).toBe(5);
|
||||
expect(calculateReadingTime(content, 'en', {wordsPerMinute: 100})).toBe(5);
|
||||
});
|
||||
|
||||
it('handles content with special characters', () => {
|
||||
const content = 'Hello! How are you? This is a test...';
|
||||
expect(calculateReadingTime(content)).toBe(0.04);
|
||||
expect(calculateReadingTime(content, 'en')).toBe(0.04);
|
||||
});
|
||||
|
||||
it('handles content with multiple lines', () => {
|
||||
const content = `This is line 1.
|
||||
This is line 2.
|
||||
This is line 3.`;
|
||||
expect(calculateReadingTime(content)).toBe(0.06);
|
||||
const content = `This is line 1.\n This is line 2.\n This is line 3.`;
|
||||
expect(calculateReadingTime(content, 'en')).toBe(0.06);
|
||||
});
|
||||
|
||||
it('handles content with HTML tags', () => {
|
||||
const content = '<p>This is a <strong>test</strong> content.</p>';
|
||||
expect(calculateReadingTime(content)).toBe(0.025);
|
||||
expect(calculateReadingTime(content, 'en')).toBe(0.05);
|
||||
});
|
||||
|
||||
it('handles content with markdown', () => {
|
||||
const content = '# Title\n\nThis is **bold** and *italic* text.';
|
||||
expect(calculateReadingTime(content)).toBe(0.04);
|
||||
expect(calculateReadingTime(content, 'en')).toBe(0.04);
|
||||
});
|
||||
|
||||
it('handles CJK content', () => {
|
||||
const content = '你好,世界!这是一段测试内容。';
|
||||
expect(calculateReadingTime(content)).toBe(0.06);
|
||||
expect(calculateReadingTime(content, 'zh')).toBe(0.04);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue