1- import { ChangeDetectionStrategy , NO_ERRORS_SCHEMA } from '@angular/core' ;
1+ import { ChangeDetectionStrategy , CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ;
22
33import { ComponentFixture , TestBed , waitForAsync } from '@angular/core/testing' ;
44import { RouterTestingModule } from '@angular/router/testing' ;
@@ -14,51 +14,28 @@ import { SearchConfigurationServiceStub } from '../../../testing/search-configur
1414import { SEARCH_CONFIG_SERVICE } from '../../../../my-dspace-page/my-dspace-page.component' ;
1515import { SequenceService } from '../../../../core/shared/sequence.service' ;
1616import { BrowserOnlyMockPipe } from '../../../testing/browser-only-mock.pipe' ;
17+ import { SearchServiceStub } from '../../../testing/search-service.stub' ;
18+ import { SearchFilterServiceStub } from '../../../testing/search-filter-service.stub' ;
1719
1820describe ( 'SearchFilterComponent' , ( ) => {
1921 let comp : SearchFilterComponent ;
2022 let fixture : ComponentFixture < SearchFilterComponent > ;
2123 const filterName1 = 'test name' ;
22- const filterName2 = 'test2' ;
23- const filterName3 = 'another name3' ;
24- const nonExistingFilter1 = 'non existing 1' ;
25- const nonExistingFilter2 = 'non existing 2' ;
24+
2625 const mockFilterConfig : SearchFilterConfig = Object . assign ( new SearchFilterConfig ( ) , {
2726 name : filterName1 ,
2827 filterType : FilterType . text ,
2928 hasFacets : false ,
3029 isOpenByDefault : false
3130 } ) ;
32- const mockFilterService = {
33- /* eslint-disable no-empty,@typescript-eslint/no-empty-function */
34- toggle : ( filter ) => {
35- } ,
36- collapse : ( filter ) => {
37- } ,
38- expand : ( filter ) => {
39- } ,
40- initializeFilter : ( filter ) => {
41- } ,
42- getSelectedValuesForFilter : ( filter ) => {
43- return observableOf ( [ filterName1 , filterName2 , filterName3 ] ) ;
44- } ,
45- isFilterActive : ( filter ) => {
46- return observableOf ( [ filterName1 , filterName2 , filterName3 ] . indexOf ( filter ) >= 0 ) ;
47- } ,
48- isCollapsed : ( filter ) => {
49- return observableOf ( true ) ;
50- }
51- /* eslint-enable no-empty, @typescript-eslint/no-empty-function */
52-
53- } ;
54- let filterService ;
31+ let searchFilterService : SearchFilterServiceStub ;
5532 let sequenceService ;
5633 const mockResults = observableOf ( [ 'test' , 'data' ] ) ;
57- const searchServiceStub = {
58- getFacetValuesFor : ( filter ) => mockResults
59- } ;
34+ let searchService : SearchServiceStub ;
6035
6136 beforeEach ( waitForAsync ( ( ) => {
37+ searchFilterService = new SearchFilterServiceStub ( ) ;
38+ searchService = new SearchServiceStub ( ) ;
6239 sequenceService = jasmine . createSpyObj ( 'sequenceService' , { next : 17 } ) ;
6340
6441 TestBed . configureTestingModule ( {
@@ -68,26 +45,23 @@ describe('SearchFilterComponent', () => {
6845 BrowserOnlyMockPipe ,
6946 ] ,
7047 providers : [
71- { provide : SearchService , useValue : searchServiceStub } ,
72- {
73- provide : SearchFilterService ,
74- useValue : mockFilterService
75- } ,
48+ { provide : SearchService , useValue : searchService } ,
49+ { provide : SearchFilterService , useValue : searchFilterService } ,
7650 { provide : SEARCH_CONFIG_SERVICE , useValue : new SearchConfigurationServiceStub ( ) } ,
7751 { provide : SequenceService , useValue : sequenceService } ,
7852 ] ,
79- schemas : [ NO_ERRORS_SCHEMA ]
53+ schemas : [ CUSTOM_ELEMENTS_SCHEMA ] ,
8054 } ) . overrideComponent ( SearchFilterComponent , {
8155 set : { changeDetection : ChangeDetectionStrategy . Default }
8256 } ) . compileComponents ( ) ;
8357 } ) ) ;
8458
8559 beforeEach ( ( ) => {
60+ spyOn ( searchService , 'getFacetValuesFor' ) . and . returnValue ( mockResults ) ;
8661 fixture = TestBed . createComponent ( SearchFilterComponent ) ;
8762 comp = fixture . componentInstance ; // SearchPageComponent test instance
8863 comp . filter = mockFilterConfig ;
8964 fixture . detectChanges ( ) ;
90- filterService = ( comp as any ) . filterService ;
9165 } ) ;
9266
9367 it ( 'should generate unique IDs' , ( ) => {
@@ -98,54 +72,30 @@ describe('SearchFilterComponent', () => {
9872
9973 describe ( 'when the toggle method is triggered' , ( ) => {
10074 beforeEach ( ( ) => {
101- spyOn ( filterService , 'toggle' ) ;
75+ spyOn ( searchFilterService , 'toggle' ) ;
10276 comp . toggle ( ) ;
10377 } ) ;
10478
10579 it ( 'should call toggle with the correct filter configuration name' , ( ) => {
106- expect ( filterService . toggle ) . toHaveBeenCalledWith ( mockFilterConfig . name ) ;
80+ expect ( searchFilterService . toggle ) . toHaveBeenCalledWith ( mockFilterConfig . name ) ;
10781 } ) ;
10882 } ) ;
10983
11084 describe ( 'when the initializeFilter method is triggered' , ( ) => {
11185 beforeEach ( ( ) => {
112- spyOn ( filterService , 'initializeFilter' ) ;
86+ spyOn ( searchFilterService , 'initializeFilter' ) ;
11387 comp . initializeFilter ( ) ;
11488 } ) ;
11589
11690 it ( 'should call initialCollapse with the correct filter configuration name' , ( ) => {
117- expect ( filterService . initializeFilter ) . toHaveBeenCalledWith ( mockFilterConfig ) ;
118- } ) ;
119- } ) ;
120-
121- describe ( 'when getSelectedValues is called' , ( ) => {
122- let valuesObservable : Observable < string [ ] > ;
123- beforeEach ( ( ) => {
124- valuesObservable = ( comp as any ) . getSelectedValues ( ) ;
125- } ) ;
126-
127- it ( 'should return an observable containing the existing filters' , ( ) => {
128- const sub = valuesObservable . subscribe ( ( values ) => {
129- expect ( values ) . toContain ( filterName1 ) ;
130- expect ( values ) . toContain ( filterName2 ) ;
131- expect ( values ) . toContain ( filterName3 ) ;
132- } ) ;
133- sub . unsubscribe ( ) ;
134- } ) ;
135-
136- it ( 'should return an observable that does not contain the non-existing filters' , ( ) => {
137- const sub = valuesObservable . subscribe ( ( values ) => {
138- expect ( values ) . not . toContain ( nonExistingFilter1 ) ;
139- expect ( values ) . not . toContain ( nonExistingFilter2 ) ;
140- } ) ;
141- sub . unsubscribe ( ) ;
91+ expect ( searchFilterService . initializeFilter ) . toHaveBeenCalledWith ( mockFilterConfig ) ;
14292 } ) ;
14393 } ) ;
14494
14595 describe ( 'when isCollapsed is called and the filter is collapsed' , ( ) => {
14696 let isActive : Observable < boolean > ;
14797 beforeEach ( ( ) => {
148- filterService . isCollapsed = ( ) => observableOf ( true ) ;
98+ searchFilterService . isCollapsed = ( ) => observableOf ( true ) ;
14999 isActive = ( comp as any ) . isCollapsed ( ) ;
150100 } ) ;
151101
@@ -160,7 +110,7 @@ describe('SearchFilterComponent', () => {
160110 describe ( 'when isCollapsed is called and the filter is not collapsed' , ( ) => {
161111 let isActive : Observable < boolean > ;
162112 beforeEach ( ( ) => {
163- filterService . isCollapsed = ( ) => observableOf ( false ) ;
113+ searchFilterService . isCollapsed = ( ) => observableOf ( false ) ;
164114 isActive = ( comp as any ) . isCollapsed ( ) ;
165115 } ) ;
166116
0 commit comments