Skip to content

Commit

Permalink
Add unit tests for getParentLineIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 29, 2019
1 parent f32c2fa commit c46a0cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions packages/rich-text/src/test/get-parent-line-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* External dependencies
*/
import deepFreeze from 'deep-freeze';

/**
* Internal dependencies
*/

import { getParentLineIndex } from '../get-parent-line-index';
import { LINE_SEPARATOR } from '../special-characters';

describe( 'getParentLineIndex', () => {
const ul = { type: 'ul' };

it( 'should return undefined if there is only one line', () => {
expect( getParentLineIndex( deepFreeze( {
formats: [ , ],
text: '1',
} ), undefined ) ).toBe( undefined );
} );

it( 'should return undefined if the list is part of the first root list child', () => {
expect( getParentLineIndex( deepFreeze( {
formats: [ , ],
text: `1${ LINE_SEPARATOR }2`,
} ), 2 ) ).toBe( undefined );
} );

it( 'should return the line index of the parent list (1)', () => {
expect( getParentLineIndex( deepFreeze( {
formats: [ , , , [ ul ], , ],
text: `1${ LINE_SEPARATOR }2${ LINE_SEPARATOR }3`,
} ), 3 ) ).toBe( 1 );
} );

it( 'should return the line index of the parent list (2)', () => {
expect( getParentLineIndex( deepFreeze( {
formats: [ , [ ul ], , [ ul, ul ], , [ ul ], , ],
text: `1${ LINE_SEPARATOR }2${ LINE_SEPARATOR }3${ LINE_SEPARATOR }4`,
} ), 5 ) ).toBe( undefined );
} );
} );

0 comments on commit c46a0cd

Please sign in to comment.