@@ -488,3 +488,83 @@ 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
+ await user . keyboard ( `{Control>}b{/Control>}` ) ;
519
+
520
+ // expect the text to be bold
521
+ expect ( screen . getByText ( "Sample text not bold" ) ) . toHaveStyle (
522
+ "font-weight: bold" ,
523
+ ) ;
524
+ await user . keyboard ( `{Control>}b{/Control>}` ) ;
525
+
526
+ // expect the text to be normal
527
+ expect ( screen . getByText ( "Sample text not bold" ) ) . not . toHaveStyle (
528
+ "font-weight: bold" ,
529
+ ) ;
530
+ } ) ;
531
+
532
+ it ( "should toggle italic text when the italic shortcut is pressed" , async ( ) => {
533
+ const user = userEvent . setup ( ) ;
534
+ const mockCancel = jest . fn ( ) ;
535
+ const mockSave = jest . fn ( ) ;
536
+ const value = JSON . stringify ( initialValue ) ;
537
+
538
+ // render the TextEditor component
539
+ render (
540
+ < TextEditor
541
+ labelText = "Example"
542
+ onCancel = { ( ) => mockCancel ( ) }
543
+ onSave = { ( ) => mockSave ( ) }
544
+ value = { value }
545
+ characterLimit = { 20 }
546
+ /> ,
547
+ ) ;
548
+
549
+ // Click the editor space and send a few key presses
550
+ const editor = screen . getByRole ( `textbox` ) ;
551
+ await user . click ( editor ) ;
552
+ await user . keyboard ( " not italic" ) ;
553
+
554
+ // expect the edited value to be visible
555
+ expect ( screen . getByText ( "Sample text not italic" ) ) . toBeInTheDocument ( ) ;
556
+ await user . tripleClick ( editor ) ;
557
+ await user . keyboard ( `{Control>}i{/Control>}` ) ;
558
+
559
+ // expect the text to be bold
560
+ expect ( screen . getByText ( "Sample text not italic" ) ) . toHaveStyle (
561
+ "font-style: italic" ,
562
+ ) ;
563
+ await user . keyboard ( `{Control>}i{/Control>}` ) ;
564
+
565
+ // expect the text to be normal
566
+ expect ( screen . getByText ( "Sample text not italic" ) ) . not . toHaveStyle (
567
+ "font-style: italic" ,
568
+ ) ;
569
+ } ) ;
570
+ } ) ;
0 commit comments