mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-15 09:12:24 +02:00
test(reading-time): Unit tests for calculating reading time (#11116)
This commit is contained in:
parent
16ebd55ef6
commit
fadb6d2607
8 changed files with 233 additions and 8 deletions
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {calculateReadingTime} from '../readingTime';
|
||||
|
||||
describe('calculateReadingTime', () => {
|
||||
it('calculates reading time for empty content', () => {
|
||||
expect(calculateReadingTime('')).toBe(0);
|
||||
});
|
||||
|
||||
it('calculates reading time for short content', () => {
|
||||
const content = 'This is a short test content.';
|
||||
expect(calculateReadingTime(content)).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);
|
||||
});
|
||||
|
||||
it('respects custom words per minute', () => {
|
||||
const content = 'This is a test content. '.repeat(100);
|
||||
expect(calculateReadingTime(content, {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);
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
it('handles content with HTML tags', () => {
|
||||
const content = '<p>This is a <strong>test</strong> content.</p>';
|
||||
expect(calculateReadingTime(content)).toBe(0.025);
|
||||
});
|
||||
|
||||
it('handles content with markdown', () => {
|
||||
const content = '# Title\n\nThis is **bold** and *italic* text.';
|
||||
expect(calculateReadingTime(content)).toBe(0.04);
|
||||
});
|
||||
|
||||
it('handles CJK content', () => {
|
||||
const content = '你好,世界!这是一段测试内容。';
|
||||
expect(calculateReadingTime(content)).toBe(0.06);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue