@@ -5,6 +5,7 @@ import { Component, DebugElement, Provider, signal, Type, viewChild } from '@ang
55import { ComponentFixture , TestBed } from '@angular/core/testing' ;
66import { By } from '@angular/platform-browser' ;
77import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
8+ import { KbqAutocompleteTrigger } from '@koobiq/components/autocomplete' ;
89import { COMMA , createKeyboardEvent , ENTER , SEMICOLON , SPACE , TAB } from '@koobiq/components/core' ;
910import { KbqFormFieldModule } from '@koobiq/components/form-field' ;
1011import { Subject } from 'rxjs' ;
@@ -366,6 +367,64 @@ describe(KbqTagInput.name, () => {
366367 expect ( componentInstance . add ) . toHaveBeenCalledTimes ( 1 ) ;
367368 expect ( componentInstance . add ) . toHaveBeenCalledWith ( expect . objectContaining ( { value : 'a,b,c' } ) ) ;
368369 } ) ;
370+
371+ describe ( 'autocomplete interaction' , ( ) => {
372+ it ( 'should NOT emit tagEnd on ENTER when autocomplete panel is open with an active option' , ( ) => {
373+ const fixture = createComponent ( TestTagInputDefaultSeparators ) ;
374+ const directive = fixture . componentInstance . tagInput ( ) ;
375+ const inputElement = getInputElement ( fixture ) ;
376+
377+ inputElement . value = 'some text' ;
378+ directive . autocompleteTrigger = { panelOpen : true , activeOption : { } } as KbqAutocompleteTrigger ;
379+
380+ directive . onKeydown ( createKeyboardEvent ( 'keydown' , ENTER , inputElement , 'Enter' ) ) ;
381+
382+ expect ( fixture . componentInstance . add ) . not . toHaveBeenCalled ( ) ;
383+ } ) ;
384+
385+ it ( 'should emit tagEnd on ENTER when autocomplete panel is open but no active option' , ( ) => {
386+ const fixture = createComponent ( TestTagInputDefaultSeparators ) ;
387+ const directive = fixture . componentInstance . tagInput ( ) ;
388+ const inputElement = getInputElement ( fixture ) ;
389+
390+ inputElement . value = 'some text' ;
391+ directive . autocompleteTrigger = { panelOpen : true , activeOption : null } as KbqAutocompleteTrigger ;
392+
393+ directive . onKeydown ( createKeyboardEvent ( 'keydown' , ENTER , inputElement , 'Enter' ) ) ;
394+
395+ expect ( fixture . componentInstance . add ) . toHaveBeenCalledWith ( expect . objectContaining ( { value : 'some text' } ) ) ;
396+ } ) ;
397+
398+ it ( 'should emit tagEnd on ENTER when autocomplete panel is closed' , ( ) => {
399+ const fixture = createComponent ( TestTagInputDefaultSeparators ) ;
400+ const directive = fixture . componentInstance . tagInput ( ) ;
401+ const inputElement = getInputElement ( fixture ) ;
402+
403+ inputElement . value = 'some text' ;
404+ directive . autocompleteTrigger = { panelOpen : false , activeOption : { } } as KbqAutocompleteTrigger ;
405+
406+ directive . onKeydown ( createKeyboardEvent ( 'keydown' , ENTER , inputElement , 'Enter' ) ) ;
407+
408+ expect ( fixture . componentInstance . add ) . toHaveBeenCalledWith ( expect . objectContaining ( { value : 'some text' } ) ) ;
409+ } ) ;
410+
411+ it ( 'should emit tagEnd on COMMA when autocomplete panel is open with an active option' , ( ) => {
412+ const fixture = createComponent ( TestTagInputSeparators ) ;
413+ const { componentInstance } = fixture ;
414+ const directive = componentInstance . tagInput ( ) ;
415+ const inputElement = getInputElement ( fixture ) ;
416+
417+ componentInstance . separatorKeyCodes . set ( [ COMMA ] ) ;
418+ fixture . detectChanges ( ) ;
419+
420+ inputElement . value = 'some text' ;
421+ directive . autocompleteTrigger = { panelOpen : true , activeOption : { } } as KbqAutocompleteTrigger ;
422+
423+ directive . onKeydown ( createKeyboardEvent ( 'keydown' , COMMA , inputElement , ',' ) ) ;
424+
425+ expect ( componentInstance . add ) . toHaveBeenCalledWith ( expect . objectContaining ( { value : 'some text' } ) ) ;
426+ } ) ;
427+ } ) ;
369428} ) ;
370429
371430describe ( 'KbqTagInput' , ( ) => {
0 commit comments