11import { ChangeDetectionStrategy , CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
2+ import { RouterModule } from '@angular/router' ;
23
34import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
4- import { RouterTestingModule } from '@angular/router/testing' ;
55import { TranslateModule } from '@ngx-translate/core' ;
66import { Observable , of as observableOf } from 'rxjs' ;
77import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
@@ -16,10 +16,22 @@ import { SequenceService } from '../../../../core/shared/sequence.service';
1616import { BrowserOnlyMockPipe } from '../../../testing/browser-only-mock.pipe' ;
1717import { SearchServiceStub } from '../../../testing/search-service.stub' ;
1818import { SearchFilterServiceStub } from '../../../testing/search-filter-service.stub' ;
19+ import { cold } from 'jasmine-marbles' ;
20+ import { AppliedFilter } from '../../models/applied-filter.model' ;
21+ import { FacetValues } from '../../models/facet-values.model' ;
22+ import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils' ;
1923
2024describe ( 'SearchFilterComponent' , ( ) => {
2125 let comp : SearchFilterComponent ;
2226 let fixture : ComponentFixture < SearchFilterComponent > ;
27+
28+ const appliedFilter1 : AppliedFilter = Object . assign ( new AppliedFilter ( ) , {
29+ operator : 'equals' ,
30+ } ) ;
31+ const appliedFilter2 : AppliedFilter = Object . assign ( new AppliedFilter ( ) , {
32+ operator : 'notauthority' ,
33+ } ) ;
34+
2335 const filterName1 = 'test name' ;
2436
2537 const mockFilterConfig : SearchFilterConfig = Object . assign ( new SearchFilterConfig ( ) , {
@@ -30,24 +42,29 @@ describe('SearchFilterComponent', () => {
3042 } ) ;
3143 let searchFilterService : SearchFilterServiceStub ;
3244 let sequenceService ;
33- const mockResults = observableOf ( [ 'test' , 'data' ] ) ;
3445 let searchService : SearchServiceStub ;
46+ let searchConfigurationService : SearchConfigurationServiceStub ;
3547
3648 beforeEach ( waitForAsync ( ( ) => {
3749 searchFilterService = new SearchFilterServiceStub ( ) ;
3850 searchService = new SearchServiceStub ( ) ;
51+ searchConfigurationService = new SearchConfigurationServiceStub ( ) ;
3952 sequenceService = jasmine . createSpyObj ( 'sequenceService' , { next : 17 } ) ;
4053
4154 TestBed . configureTestingModule ( {
42- imports : [ TranslateModule . forRoot ( ) , RouterTestingModule . withRoutes ( [ ] ) , NoopAnimationsModule ] ,
55+ imports : [
56+ NoopAnimationsModule ,
57+ RouterModule . forRoot ( [ ] ) ,
58+ TranslateModule . forRoot ( ) ,
59+ ] ,
4360 declarations : [
4461 SearchFilterComponent ,
4562 BrowserOnlyMockPipe ,
4663 ] ,
4764 providers : [
4865 { provide : SearchService , useValue : searchService } ,
4966 { provide : SearchFilterService , useValue : searchFilterService } ,
50- { provide : SEARCH_CONFIG_SERVICE , useValue : new SearchConfigurationServiceStub ( ) } ,
67+ { provide : SEARCH_CONFIG_SERVICE , useValue : searchConfigurationService } ,
5168 { provide : SequenceService , useValue : sequenceService } ,
5269 ] ,
5370 schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
@@ -57,7 +74,6 @@ describe('SearchFilterComponent', () => {
5774 } ) ) ;
5875
5976 beforeEach ( ( ) => {
60- spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( mockResults ) ;
6177 fixture = TestBed . createComponent ( SearchFilterComponent ) ;
6278 comp = fixture . componentInstance ; // SearchPageComponent test instance
6379 comp . filter = mockFilterConfig ;
@@ -121,4 +137,59 @@ describe('SearchFilterComponent', () => {
121137 sub . unsubscribe ( ) ;
122138 } ) ;
123139 } ) ;
140+
141+ describe ( 'isActive' , ( ) => {
142+ it ( 'should return true when there are facet value suggestions & no valid applied values' , ( ) => {
143+ spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( Object . assign ( new FacetValues ( ) , {
144+ pageInfo : {
145+ totalElements : 5 ,
146+ } ,
147+ } as FacetValues ) ) ) ;
148+ comp . appliedFilters$ = observableOf ( [ appliedFilter2 ] ) ;
149+
150+ expect ( comp . isActive ( ) ) . toBeObservable ( cold ( '(tt)' , {
151+ t : true ,
152+ } ) ) ;
153+ } ) ;
154+
155+ it ( 'should return false when there are no facet value suggestions & no valid applied values' , ( ) => {
156+ spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( Object . assign ( new FacetValues ( ) , {
157+ pageInfo : {
158+ totalElements : 0 ,
159+ } ,
160+ } as FacetValues ) ) ) ;
161+ comp . appliedFilters$ = observableOf ( [ appliedFilter2 ] ) ;
162+
163+ expect ( comp . isActive ( ) ) . toBeObservable ( cold ( '(tf)' , {
164+ t : true ,
165+ f : false ,
166+ } ) ) ;
167+ } ) ;
168+
169+ it ( 'should return true when there are no facet value suggestions & but there are valid applied values' , ( ) => {
170+ spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( Object . assign ( new FacetValues ( ) , {
171+ pageInfo : {
172+ totalElements : 0 ,
173+ } ,
174+ } as FacetValues ) ) ) ;
175+ comp . appliedFilters$ = observableOf ( [ appliedFilter1 , appliedFilter2 ] ) ;
176+
177+ expect ( comp . isActive ( ) ) . toBeObservable ( cold ( '(tt)' , {
178+ t : true ,
179+ } ) ) ;
180+ } ) ;
181+
182+ it ( 'should return true when there are facet value suggestions & there are valid applied values' , ( ) => {
183+ spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( createSuccessfulRemoteDataObject$ ( Object . assign ( new FacetValues ( ) , {
184+ pageInfo : {
185+ totalElements : 5 ,
186+ } ,
187+ } as FacetValues ) ) ) ;
188+ comp . appliedFilters$ = observableOf ( [ appliedFilter1 , appliedFilter2 ] ) ;
189+
190+ expect ( comp . isActive ( ) ) . toBeObservable ( cold ( '(tt)' , {
191+ t : true ,
192+ } ) ) ;
193+ } ) ;
194+ } ) ;
124195} ) ;
0 commit comments