@@ -142,6 +142,7 @@ describe('DsDynamicOneboxComponent test suite', () => {
142142 vocabularyServiceStub = new VocabularyServiceStub ( ) ;
143143 searchServiceStub = new SearchServiceStub ( ) ;
144144
145+
145146 modal = jasmine . createSpyObj ( 'modal' ,
146147 {
147148 open : jasmine . createSpy ( 'open' ) ,
@@ -470,6 +471,33 @@ describe('DsDynamicOneboxComponent test suite', () => {
470471 } ) ;
471472
472473 } ) ;
474+
475+ describe ( 'When vocabulary type is \'suggest\'' , ( ) => {
476+ beforeEach ( ( ) => {
477+ oneboxCompFixture = TestBed . createComponent ( DsDynamicOneboxComponent ) ;
478+ oneboxComponent = oneboxCompFixture . componentInstance ; // FormComponent test instance
479+ oneboxComponent . group = ONEBOX_TEST_GROUP ;
480+ oneboxComponent . model = new DynamicOneboxModel ( ONEBOX_TEST_MODEL_CONFIG ) ;
481+ oneboxComponent . model . vocabularyOptions . type = 'suggest' ;
482+ oneboxComponent . model . vocabularyOptions . name = 'authors' ;
483+ spyOn ( oneboxComponent , 'setCurrentValue' ) . and . callThrough ( ) ;
484+ spyOn ( searchServiceStub , 'getSuggestionsFor' ) ;
485+ } ) ;
486+
487+ it ( 'should not call setCurrentValue with \'init\' during init' , ( ) => {
488+ oneboxComponent . model . value = 'hi!' ;
489+ oneboxComponent . ngOnInit ( ) ;
490+ expect ( oneboxComponent . setCurrentValue )
491+ . toHaveBeenCalledWith ( 'hi!' , false ) ;
492+ } ) ;
493+
494+ it ( 'should call getSuggestionsFor() when searching' , fakeAsync ( ( ) => {
495+ oneboxComponent . search ( of ( 'hello' ) ) . subscribe ( ) ;
496+ tick ( 400 ) ;
497+ expect ( searchServiceStub . getSuggestionsFor ) . toHaveBeenCalledWith (
498+ 'hello' , 'authors' ) ;
499+ } ) ) ;
500+ } ) ;
473501} ) ;
474502
475503// declare a test component
@@ -491,4 +519,3 @@ class TestComponent {
491519 model = new DynamicOneboxModel ( ONEBOX_TEST_MODEL_CONFIG ) ;
492520
493521}
494-
0 commit comments