-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RichText: List: Fix getParentIndex (#13562)
* RichText: List: Fix getParentIndex * Fill out test name * Add unit tests for getParentLineIndex * Guard against negative lineIndex
- Loading branch information
Showing
4 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters