@@ -491,6 +491,77 @@ describe('TextComposer', () => {
491491 } ) ;
492492 } ) ;
493493
494+ describe ( 'wrapSelection' , ( ) => {
495+ const message : LocalMessage = {
496+ id : 'test-message' ,
497+ type : 'regular' ,
498+ text : 'Hello world' ,
499+ } ;
500+
501+ it ( 'should wrap selection from both sides' , ( ) => {
502+ const selection = { start : 0 , end : 5 } ;
503+ const {
504+ messageComposer : { textComposer } ,
505+ } = setup ( { composition : message } ) ;
506+ textComposer . wrapSelection ( { head : '**' , tail : '**' , selection } ) ;
507+ expect ( textComposer . text ) . toBe ( '**Hello** world' ) ;
508+ expect ( textComposer . selection ) . toEqual ( { start : 2 , end : 7 } ) ;
509+ } ) ;
510+
511+ it ( 'should wrap selection from the head side' , ( ) => {
512+ const selection = { start : 0 , end : 5 } ;
513+ const {
514+ messageComposer : { textComposer } ,
515+ } = setup ( { composition : message } ) ;
516+ textComposer . wrapSelection ( { head : '**' , selection } ) ;
517+ expect ( textComposer . text ) . toBe ( '**Hello world' ) ;
518+ expect ( textComposer . selection ) . toEqual ( { start : 2 , end : 7 } ) ;
519+ } ) ;
520+
521+ it ( 'should wrap selection from the tail side' , ( ) => {
522+ const selection = { start : 0 , end : 5 } ;
523+ const {
524+ messageComposer : { textComposer } ,
525+ } = setup ( { composition : message } ) ;
526+ textComposer . wrapSelection ( { tail : '**' , selection } ) ;
527+ expect ( textComposer . text ) . toBe ( 'Hello** world' ) ;
528+ expect ( textComposer . selection ) . toEqual ( { start : 0 , end : 5 } ) ;
529+ } ) ;
530+
531+ it ( 'should wrap cursor' , ( ) => {
532+ const selection = { start : 5 , end : 5 } ;
533+ const {
534+ messageComposer : { textComposer } ,
535+ } = setup ( { composition : message } ) ;
536+ textComposer . wrapSelection ( { head : '**' , tail : '**' , selection } ) ;
537+ expect ( textComposer . text ) . toBe ( 'Hello**** world' ) ;
538+ expect ( textComposer . selection ) . toEqual ( { start : 7 , end : 7 } ) ;
539+ } ) ;
540+
541+ it ( 'should avoid changes if text composition is disabled' , ( ) => {
542+ const selection = { start : 5 , end : 5 } ;
543+ const {
544+ messageComposer : { textComposer } ,
545+ } = setup ( { composition : message , config : { enabled : false } } ) ;
546+ const initialSelection = textComposer . selection ;
547+ textComposer . wrapSelection ( { head : '**' , tail : '**' , selection } ) ;
548+ expect ( textComposer . text ) . toBe ( message . text ) ;
549+ expect ( selection ) . not . toEqual ( initialSelection ) ;
550+ expect ( textComposer . selection ) . toEqual ( initialSelection ) ;
551+ } ) ;
552+
553+ it ( 'should use current selection if custom not provided' , ( ) => {
554+ const initialSelection = { start : 2 , end : 3 } ;
555+ const {
556+ messageComposer : { textComposer } ,
557+ } = setup ( { composition : message } ) ;
558+ textComposer . setSelection ( initialSelection ) ;
559+ textComposer . wrapSelection ( { head : '**' , tail : '**' } ) ;
560+ expect ( textComposer . text ) . toBe ( 'He**l**lo world' ) ;
561+ expect ( textComposer . selection ) . toEqual ( { start : 4 , end : 5 } ) ;
562+ } ) ;
563+ } ) ;
564+
494565 describe ( 'closeSuggestions' , ( ) => {
495566 const message : LocalMessage = {
496567 id : 'test-message' ,
0 commit comments