@@ -353,6 +353,47 @@ ke The <br> World Go Round`)
353353 } )
354354 } )
355355
356+ describe ( 'highlightRange() - text validation' , function ( ) {
357+
358+ it ( 'returns -1 when text does not match the range' , function ( ) {
359+ setupHighlightEnv ( this , 'People Make The World Go Round' )
360+ const result = this . highlightRange ( 'wrong text' , 'myId' , 0 , 6 )
361+ expect ( result ) . to . equal ( - 1 )
362+ } )
363+
364+ it ( 'does not apply a highlight when text does not match' , function ( ) {
365+ setupHighlightEnv ( this , 'People Make The World Go Round' )
366+ this . highlightRange ( 'wrong text' , 'myId' , 0 , 6 )
367+ expect ( this . extractWithoutNativeRange ( ) ) . to . equal ( undefined )
368+ } )
369+
370+ it ( 'does not notify the dispatcher when text does not match' , function ( ) {
371+ setupHighlightEnv ( this , 'People Make The World Go Round' )
372+ let called = 0
373+ const dispatcher = { notify : ( ) => called ++ }
374+ this . highlightRange ( 'wrong text' , 'myId' , 0 , 6 , dispatcher )
375+ expect ( called ) . to . equal ( 0 )
376+ } )
377+
378+ it ( 'skips validation when text is undefined' , function ( ) {
379+ setupHighlightEnv ( this , 'People Make The World Go Round' )
380+ const result = this . highlightRange ( undefined , 'myId' , 0 , 6 )
381+ expect ( result ) . to . equal ( 0 )
382+ } )
383+
384+ it ( 'skips validation when text is null' , function ( ) {
385+ setupHighlightEnv ( this , 'People Make The World Go Round' )
386+ const result = this . highlightRange ( null , 'myId' , 0 , 6 )
387+ expect ( result ) . to . equal ( 0 )
388+ } )
389+
390+ it ( 'skips validation when text is empty string' , function ( ) {
391+ setupHighlightEnv ( this , 'People Make The World Go Round' )
392+ const result = this . highlightRange ( '' , 'myId' , 0 , 6 )
393+ expect ( result ) . to . equal ( 0 )
394+ } )
395+ } )
396+
356397 describe ( 'highlightRange() - with formatted text' , function ( ) {
357398
358399 it ( 'handles highlights surrounding <span> tags' , function ( ) {
@@ -482,7 +523,7 @@ ke The <br> World Go Round`)
482523
483524 it ( 'extracts a readable text' , function ( ) {
484525 setupHighlightEnv ( this , '๐ Make The \r\n ๐ Go \n๐' )
485- this . highlightRange ( '๐ Makeย The ๐ Go ๐' , 'myId' , 0 , 23 )
526+ this . highlightRange ( '๐ Makeย The \n ๐ Go \n ๐' , 'myId' , 0 , 23 )
486527 const expectedRanges = {
487528 myId : {
488529 text : '๐ Makeย The \n ๐ Go \n๐' ,
@@ -499,7 +540,7 @@ ke The <br> World Go Round`)
499540 setupHighlightEnv ( this , '๐ Make The \r\n ๐ Go \n๐' )
500541 let called = 0
501542 const dispatcher = { notify : ( ) => called ++ }
502- this . highlightRange ( '๐ Makeย The ๐ Go ๐' , 'myId' , 0 , 20 , dispatcher )
543+ this . highlightRange ( '๐ Makeย The \n ๐ Go \n ๐' , 'myId' , 0 , 23 , dispatcher )
503544
504545 expect ( called ) . to . equal ( 1 )
505546 } )
@@ -508,7 +549,7 @@ ke The <br> World Go Round`)
508549 setupHighlightEnv ( this , '๐ Make The \r\n ๐ Go \n๐' )
509550 let called = 0
510551 const dispatcher = { notify : ( ) => called ++ }
511- this . highlightRange ( '๐ Makeย The ๐ Go ๐' , 'myId' , 0 , 20 )
552+ this . highlightRange ( '๐ Makeย The \n ๐ Go \n ๐' , 'myId' , 0 , 23 )
512553 this . removeHighlight ( 'first' , dispatcher )
513554
514555 expect ( called ) . to . equal ( 1 )
0 commit comments