1818import { ComponentFixture , TestBed } from '@angular/core/testing' ;
1919import { By } from '@angular/platform-browser' ;
2020import { SearchFilterAutocompleteChipsComponent } from './search-filter-autocomplete-chips.component' ;
21- import { EMPTY , of , ReplaySubject } from 'rxjs' ;
21+ import { of , ReplaySubject } from 'rxjs' ;
2222import { AutocompleteField , AutocompleteOption } from '../../models/autocomplete-option.interface' ;
2323import { TagService } from '../../../tag/services/tag.service' ;
2424import { SitesService } from '../../../common/services/sites.service' ;
@@ -33,13 +33,7 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
3333
3434 beforeEach ( ( ) => {
3535 TestBed . configureTestingModule ( {
36- imports : [ SearchFilterAutocompleteChipsComponent ] ,
37- providers : [
38- {
39- provide : TagService ,
40- useValue : { getAllTheTags : ( ) => EMPTY }
41- }
42- ]
36+ imports : [ SearchFilterAutocompleteChipsComponent ]
4337 } ) ;
4438
4539 fixture = TestBed . createComponent ( SearchFilterAutocompleteChipsComponent ) ;
@@ -86,23 +80,6 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
8680 } ) ;
8781 } ) ;
8882
89- it ( 'should load tags if field = TAG' , ( done ) => {
90- const tagPagingMock = {
91- list : {
92- pagination : { } ,
93- entries : [ { entry : { tag : 'tag1' , id : 'id1' } } , { entry : { tag : 'tag2' , id : 'id2' } } ]
94- }
95- } ;
96-
97- component . settings . field = AutocompleteField . TAG ;
98- spyOn ( tagService , 'getAllTheTags' ) . and . returnValue ( of ( tagPagingMock ) ) ;
99- component . ngOnInit ( ) ;
100- component . autocompleteOptions$ . subscribe ( ( result ) => {
101- expect ( result ) . toEqual ( [ { value : 'tag1' } , { value : 'tag2' } ] ) ;
102- done ( ) ;
103- } ) ;
104- } ) ;
105-
10683 it ( 'should update display value when options changes' , ( ) => {
10784 const newOption = 'option1' ;
10885 spyOn ( component , 'onOptionsChange' ) . and . callThrough ( ) ;
@@ -215,13 +192,9 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
215192 it ( 'should use id if present, otherwise value, in LOCATION query fragment' , ( ) => {
216193 component . settings . field = AutocompleteField . LOCATION ;
217194 component . settings . autocompleteOptions = [ ] ;
218- component . selectedOptions = [
219- { id : 'site1' , value : 'Marketing' } ,
220- { value : 'custom' }
221- ] ;
195+ component . selectedOptions = [ { id : 'site1' , value : 'Marketing' } , { value : 'custom' } ] ;
222196 component . submitValues ( ) ;
223- expect ( component . context . queryFragments [ component . id ] )
224- . toBe ( 'SITE:"site1" OR SITE:"custom"' ) ;
197+ expect ( component . context . queryFragments [ component . id ] ) . toBe ( 'SITE:"site1" OR SITE:"custom"' ) ;
225198 } ) ;
226199
227200 it ( 'should still call sitesService.getSites when input is empty for LOCATION field' , ( ) => {
@@ -251,14 +224,30 @@ describe('SearchFilterAutocompleteChipsComponent', () => {
251224 expect ( searchSpy ) . toHaveBeenCalledWith ( '' , 0 , 15 ) ;
252225 } ) ;
253226
227+ it ( 'should search for tags if field = TAG and input is not empty' , ( ) => {
228+ component . settings . field = AutocompleteField . TAG ;
229+ const searchSpy = spyOn ( tagService , 'searchTags' ) . and . returnValue (
230+ of ( {
231+ list : {
232+ pagination : { } ,
233+ entries : [ { entry : { tag : 'tag1' , id : 'id1' } } , { entry : { tag : 'tag2' , id : 'id2' } } ]
234+ }
235+ } )
236+ ) ;
237+
238+ component . onInputChange ( 'tag' ) ;
239+
240+ expect ( searchSpy ) . toHaveBeenCalledWith ( 'tag' , { orderBy : 'tag' , direction : 'asc' } , false , 0 , 15 ) ;
241+ } ) ;
242+
254243 describe ( 'optionComparator' , ( ) => {
255244 it ( 'should return false if either option is undefined' , ( ) => {
256245 expect ( component . optionComparator ( undefined , { value : 'A' } ) ) . toBe ( false ) ;
257246 expect ( component . optionComparator ( { value : 'A' } , undefined ) ) . toBe ( false ) ;
258247 } ) ;
259248
260249 it ( 'should compare by id if both have id' , ( ) => {
261- expect ( component . optionComparator ( { id : 'abc' , value : 'B' } , { id : 'ABC' , value : 'B' } ) ) . toBe ( true ) ;
250+ expect ( component . optionComparator ( { id : 'abc' , value : 'B' } , { id : 'ABC' , value : 'B' } ) ) . toBe ( true ) ;
262251 expect ( component . optionComparator ( { id : 'abc' , value : 'B' } , { id : 'def' , value : 'B' } ) ) . toBe ( false ) ;
263252 } ) ;
264253
0 commit comments