@@ -3,14 +3,15 @@ import { html, nothing } from 'lit';
33import { spy , stub , useFakeTimers } from 'sinon' ;
44import type IgcIconButtonComponent from '../button/icon-button.js' ;
55import IgcChipComponent from '../chip/chip.js' ;
6- import { enterKey } from '../common/controllers/key-bindings.js' ;
6+ import { enterKey , tabKey } from '../common/controllers/key-bindings.js' ;
77import { defineComponents } from '../common/definitions/defineComponents.js' ;
88import { first , last } from '../common/util.js' ;
99import {
1010 isFocused ,
1111 simulateBlur ,
1212 simulateClick ,
1313 simulateFocus ,
14+ simulateInput ,
1415 simulateKeyboard ,
1516} from '../common/utils.spec.js' ;
1617import { simulateFileUpload } from '../file-input/file-input.spec.js' ;
@@ -888,21 +889,69 @@ describe('Chat', () => {
888889 const textArea = getChatDOM ( chat ) . input . textarea ;
889890
890891 chat . options = { stopTypingDelay : 2500 } ;
891- simulateKeyboard ( textArea , 'a' ) ;
892+ simulateKeyboard ( textArea , 'a' , 15 ) ;
892893 await elementUpdated ( chat ) ;
893894
894895 expect ( eventSpy ) . calledWith ( 'igcTypingChange' ) ;
895- expect ( eventSpy . firstCall . args [ 1 ] ?. detail ) . to . eql ( { isTyping : true } ) ;
896+ expect ( eventSpy . firstCall . args [ 1 ] ?. detail ) . to . be . true ;
896897
897898 clock . setSystemTime ( 2501 ) ;
898899 await clock . runAllAsync ( ) ;
899900
900901 expect ( eventSpy ) . calledWith ( 'igcTypingChange' ) ;
901- expect ( eventSpy . lastCall . args [ 1 ] ?. detail ) . to . eql ( { isTyping : false } ) ;
902+ expect ( eventSpy . lastCall . args [ 1 ] ?. detail ) . to . be . false ;
902903
903904 clock . restore ( ) ;
904905 } ) ;
905906
907+ it ( 'emits igcTypingChange after sending a message' , async ( ) => {
908+ const eventSpy = spy ( chat , 'emitEvent' ) ;
909+ const textArea = getChatDOM ( chat ) . input . textarea ;
910+ const internalInput = textArea . renderRoot . querySelector ( 'textarea' ) ! ;
911+
912+ chat . options = { stopTypingDelay : 2500 } ;
913+
914+ // Simulate typing some text and the event sequence following after sending a message
915+
916+ // Fires igcTypingChange
917+ simulateKeyboard ( textArea , 'a' , 15 ) ;
918+ await elementUpdated ( textArea ) ;
919+
920+ // Fires igcInputChange
921+ simulateInput ( internalInput , { value : 'a' . repeat ( 15 ) } ) ;
922+ await elementUpdated ( textArea ) ;
923+
924+ // Fires igcMessageCreated -> igcTypingChange -> igcInputFocus since sending a message refocuses
925+ // the textarea
926+ simulateKeyboard ( textArea , enterKey ) ;
927+ await elementUpdated ( chat ) ;
928+
929+ const expectedEventSequence = [
930+ 'igcTypingChange' ,
931+ 'igcInputChange' ,
932+ 'igcMessageCreated' ,
933+ 'igcTypingChange' ,
934+ 'igcInputFocus' ,
935+ ] ;
936+
937+ for ( const [ idx , event ] of expectedEventSequence . entries ( ) ) {
938+ expect ( eventSpy . getCall ( idx ) . firstArg ) . to . equal ( event ) ;
939+ }
940+ } ) ;
941+
942+ it ( 'should not emit igcTypingChange on Tab key' , async ( ) => {
943+ const eventSpy = spy ( chat , 'emitEvent' ) ;
944+ const textArea = getChatDOM ( chat ) . input . textarea ;
945+ const internalInput = textArea . renderRoot . querySelector ( 'textarea' ) ! ;
946+
947+ chat . options = { stopTypingDelay : 2500 } ;
948+
949+ simulateKeyboard ( internalInput , tabKey ) ;
950+ await elementUpdated ( chat ) ;
951+
952+ expect ( eventSpy . getCalls ( ) ) . is . empty ;
953+ } ) ;
954+
906955 it ( 'emits igcInputFocus' , async ( ) => {
907956 const eventSpy = spy ( chat , 'emitEvent' ) ;
908957
0 commit comments