/** * Internal dependencies */ import { generateSummary } from '../utils'; describe( 'Summary Component', () => { describe( 'Test the generateSummary utility', () => { const testContent = '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

'; it( 'Default', async () => { const result = generateSummary( testContent ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore…

' ); } ); it( 'No max words - return full description', async () => { const result = generateSummary( testContent, 100000 ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

\n

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

\n

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

\n

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

' ); } ); it( 'Limit to 3 words', async () => { const result = generateSummary( testContent, 3 ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor…

' ); } ); it( 'Limit to 1 word', async () => { const result = generateSummary( testContent, 1 ); expect( result.trim() ).toEqual( '

Lorem…

' ); } ); it( 'Limit to 15 characters, including spaces.', async () => { const result = generateSummary( testContent, 15, 'characters_including_spaces' ); expect( result.trim() ).toEqual( '

Lorem ipsum dol…

' ); } ); it( 'Limit to 15 characters, excluding spaces.', async () => { const result = generateSummary( testContent, 15, 'characters_excluding_spaces' ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor…

' ); } ); } ); describe( 'Test the generateSummary utility with HTML tags in strings', () => { const testContent = '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.

'; it( 'Limit string to 10 characters', async () => { const result = generateSummary( testContent, 10, 'characters_excluding_spaces' ); expect( result.trim() ).toEqual( '

Lorem ipsum…

' ); } ); it( 'Limit string to 5 words', async () => { const result = generateSummary( testContent, 5, 'words' ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor sit amet…

' ); } ); it( 'First paragraph only - tags are not stripped.', async () => { const result = generateSummary( testContent, 9999, 'words' ); expect( result.trim() ).toEqual( '

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor.

' ); } ); } ); describe( 'Test the generateSummary utility with special chars', () => { const testContent = '

我不知道这是否行得通。

我是用中文写的说明,因此我们可以测试如何修剪产品摘要中的单词。

'; it( 'Default', async () => { const result = generateSummary( testContent, 15, 'characters_excluding_spaces' ); expect( result.trim() ).toEqual( '

我不知道这是否行得通。

' ); } ); it( 'Limit to 3 words', async () => { const result = generateSummary( testContent, 3, 'characters_excluding_spaces' ); expect( result.trim() ).toEqual( '

我不知…

' ); } ); } ); } );