@@ -488,3 +488,87 @@ test("should toggle the an indiviual list item's type when a list is active and
488
488
await user . click ( ulButton ) ;
489
489
expect ( screen . queryAllByRole ( "list" ) . length ) . toBe ( 1 ) ;
490
490
} ) ;
491
+
492
+ describe ( "shortcut keys" , ( ) => {
493
+ it ( "should toggle bold text when the bold shortcut is pressed" , async ( ) => {
494
+ const user = userEvent . setup ( ) ;
495
+ const mockCancel = jest . fn ( ) ;
496
+ const mockSave = jest . fn ( ) ;
497
+ const value = JSON . stringify ( initialValue ) ;
498
+
499
+ // render the TextEditor component
500
+ render (
501
+ < TextEditor
502
+ labelText = "Example"
503
+ onCancel = { ( ) => mockCancel ( ) }
504
+ onSave = { ( ) => mockSave ( ) }
505
+ value = { value }
506
+ characterLimit = { 20 }
507
+ /> ,
508
+ ) ;
509
+
510
+ // Click the editor space and send a few key presses
511
+ const editor = screen . getByRole ( `textbox` ) ;
512
+ await user . click ( editor ) ;
513
+ await user . keyboard ( " not bold" ) ;
514
+
515
+ // expect the edited value to be visible
516
+ expect ( screen . getByText ( "Sample text not bold" ) ) . toBeInTheDocument ( ) ;
517
+ await user . tripleClick ( editor ) ;
518
+ const commandKey =
519
+ navigator . userAgent . indexOf ( "Mac" ) !== - 1 ? "Meta" : "Control" ;
520
+ await user . keyboard ( `{${ commandKey } >}b{/${ commandKey } >}` ) ;
521
+
522
+ // expect the text to be bold
523
+ expect ( screen . getByText ( "Sample text not bold" ) ) . toHaveStyle (
524
+ "font-weight: bold" ,
525
+ ) ;
526
+ await user . keyboard ( `{${ commandKey } >}b{/${ commandKey } >}` ) ;
527
+
528
+ // expect the text to be normal
529
+ expect ( screen . getByText ( "Sample text not bold" ) ) . not . toHaveStyle (
530
+ "font-weight: bold" ,
531
+ ) ;
532
+ } ) ;
533
+
534
+ it ( "should toggle italic text when the italic shortcut is pressed" , async ( ) => {
535
+ const user = userEvent . setup ( ) ;
536
+ const mockCancel = jest . fn ( ) ;
537
+ const mockSave = jest . fn ( ) ;
538
+ const value = JSON . stringify ( initialValue ) ;
539
+
540
+ // render the TextEditor component
541
+ render (
542
+ < TextEditor
543
+ labelText = "Example"
544
+ onCancel = { ( ) => mockCancel ( ) }
545
+ onSave = { ( ) => mockSave ( ) }
546
+ value = { value }
547
+ characterLimit = { 20 }
548
+ /> ,
549
+ ) ;
550
+
551
+ // Click the editor space and send a few key presses
552
+ const editor = screen . getByRole ( `textbox` ) ;
553
+ await user . click ( editor ) ;
554
+ await user . keyboard ( " not italic" ) ;
555
+
556
+ // expect the edited value to be visible
557
+ expect ( screen . getByText ( "Sample text not italic" ) ) . toBeInTheDocument ( ) ;
558
+ await user . tripleClick ( editor ) ;
559
+ const commandKey =
560
+ navigator . userAgent . indexOf ( "Mac" ) !== - 1 ? "Meta" : "Control" ;
561
+ await user . keyboard ( `{${ commandKey } >}i{/${ commandKey } >}` ) ;
562
+
563
+ // expect the text to be bold
564
+ expect ( screen . getByText ( "Sample text not italic" ) ) . toHaveStyle (
565
+ "font-style: italic" ,
566
+ ) ;
567
+ await user . keyboard ( `{${ commandKey } >}i{/${ commandKey } >}` ) ;
568
+
569
+ // expect the text to be normal
570
+ expect ( screen . getByText ( "Sample text not italic" ) ) . not . toHaveStyle (
571
+ "font-style: italic" ,
572
+ ) ;
573
+ } ) ;
574
+ } ) ;
0 commit comments