@@ -15,21 +15,42 @@ import { PaginationComponentOptions } from '../../../pagination/pagination-compo
1515import { PaginationService } from '../../../../core/pagination/pagination.service' ;
1616import { SearchConfigurationService } from '../../../../core/shared/search/search-configuration.service' ;
1717import { PaginationServiceStub } from '../../../testing/pagination-service.stub' ;
18+ import { ItemDataService } from '../../../../core/data/item-data.service' ;
19+ import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service' ;
20+ import { Item } from '../../../../core/shared/item.model' ;
21+ import {
22+ createFailedRemoteDataObject$ ,
23+ createSuccessfulRemoteDataObject$
24+ } from '../../../remote-data.utils' ;
1825
1926describe ( 'SearchLabelComponent' , ( ) => {
27+
28+ const item = Object . assign ( new Item ( ) , {
29+ uuid : 'itemUUID' ,
30+ } ) ;
31+ const name = 'itemName' ;
32+ const mockItemDataService = jasmine . createSpyObj ( 'ItemDataService' , {
33+ findById : jasmine . createSpy ( 'findById' ) ,
34+ } ) ;
35+ const mockDSODataService = jasmine . createSpyObj ( 'DSODataService' , {
36+ getName : jasmine . createSpy ( 'getName' ) ,
37+ } ) ;
2038 let comp : SearchLabelComponent ;
2139 let fixture : ComponentFixture < SearchLabelComponent > ;
2240
2341 const searchLink = '/search' ;
2442 let searchService ;
25-
2643 const key1 = 'author' ;
2744 const key2 = 'subject' ;
2845 const value1 = 'Test, Author' ;
2946 const normValue1 = 'Test, Author' ;
3047 const value2 = 'TestSubject' ;
31- const value3 = 'Test, Authority,authority' ;
32- const normValue3 = 'Test, Authority' ;
48+ const valueAuthority = 'Test, Authority,authority' ;
49+ const normValueAuthority = 'Test, Authority' ;
50+ const valueEquals = 'Test, Author,equals' ;
51+ const normValueEquals = 'Test, Author' ;
52+ const randomAuthor = 'Test Author' ;
53+ const normValue4 = 'Test, Authority' ;
3354 const filter1 = [ key1 , value1 ] ;
3455 const filter2 = [ key2 , value2 ] ;
3556 const mockFilters = [
@@ -49,7 +70,9 @@ describe('SearchLabelComponent', () => {
4970 { provide : SEARCH_CONFIG_SERVICE , useValue : new SearchConfigurationServiceStub ( ) } ,
5071 { provide : SearchConfigurationService , useValue : new SearchConfigurationServiceStub ( ) } ,
5172 { provide : PaginationService , useValue : paginationService } ,
52- { provide : Router , useValue : { } }
73+ { provide : Router , useValue : { } } ,
74+ { provide : ItemDataService , useValue : mockItemDataService } ,
75+ { provide : DSONameService , useValue : mockDSODataService }
5376 // { provide: SearchConfigurationService, useValue: {getCurrentFrontendFilters : () => observableOf({}) } }
5477 ] ,
5578 schemas : [ NO_ERRORS_SCHEMA ]
@@ -62,17 +85,18 @@ describe('SearchLabelComponent', () => {
6285 fixture = TestBed . createComponent ( SearchLabelComponent ) ;
6386 comp = fixture . componentInstance ;
6487 searchService = ( comp as any ) . searchService ;
65- comp . key = key1 ;
66- comp . value = value1 ;
6788 ( comp as any ) . appliedFilters = observableOf ( mockFilters ) ;
68- fixture . detectChanges ( ) ;
89+ mockDSODataService . getName . and . returnValue ( name ) ;
6990 } ) ;
7091
7192 describe ( 'when getRemoveParams is called' , ( ) => {
7293 let obs : Observable < Params > ;
7394
7495 beforeEach ( ( ) => {
7596 obs = comp . getRemoveParams ( ) ;
97+ comp . key = key1 ;
98+ comp . value = value1 ;
99+ fixture . detectChanges ( ) ;
76100 } ) ;
77101
78102 it ( 'should return all params but the provided filter' , ( ) => {
@@ -84,14 +108,59 @@ describe('SearchLabelComponent', () => {
84108 } ) ;
85109
86110 describe ( 'when normalizeFilterValue is called' , ( ) => {
111+ beforeEach ( ( ) => {
112+ comp . key = key1 ;
113+ comp . value = value1 ;
114+ fixture . detectChanges ( ) ;
115+ } ) ;
87116 it ( 'should return properly filter value' , ( ) => {
88117 let result : string ;
89118
90119 result = comp . normalizeFilterValue ( value1 ) ;
91120 expect ( result ) . toBe ( normValue1 ) ;
92121
93- result = comp . normalizeFilterValue ( value3 ) ;
94- expect ( result ) . toBe ( normValue3 ) ;
122+ result = comp . normalizeFilterValue ( valueAuthority ) ;
123+ expect ( result ) . toBe ( normValueAuthority ) ;
124+ } ) ;
125+ } ) ;
126+
127+ describe ( 'when value is set as authority' , ( ) => {
128+ beforeEach ( ( ) => {
129+ comp . key = key1 ;
130+ comp . value = valueAuthority ;
131+ } ) ;
132+ it ( 'should return the value retrieved from Item' , ( ) => {
133+ mockItemDataService . findById . and . returnValue ( createSuccessfulRemoteDataObject$ ( item ) ) ;
134+ fixture . detectChanges ( ) ;
135+ expect ( comp . filterValue . getValue ( ) ) . toBe ( name ) ;
136+ } ) ;
137+ it ( 'should return the given value' , ( ) => {
138+ mockItemDataService . findById . and . returnValue ( createFailedRemoteDataObject$ ( ) ) ;
139+ fixture . detectChanges ( ) ;
140+ expect ( comp . filterValue . getValue ( ) ) . toBe ( normValueAuthority ) ;
141+ } ) ;
142+ } ) ;
143+
144+ describe ( 'when value is not set as authority' , ( ) => {
145+ beforeEach ( ( ) => {
146+ comp . key = key1 ;
147+ comp . value = valueEquals ;
148+ fixture . detectChanges ( ) ;
149+ } ) ;
150+ it ( 'should return the given value' , ( ) => {
151+ expect ( comp . filterValue . getValue ( ) ) . toBe ( normValueEquals ) ;
152+ } ) ;
153+ } ) ;
154+
155+ describe ( 'when value is random' , ( ) => {
156+ beforeEach ( ( ) => {
157+ comp . key = key1 ;
158+ comp . value = randomAuthor ;
159+ fixture . detectChanges ( ) ;
160+ } ) ;
161+ it ( 'should return the value' , ( ) => {
162+ expect ( comp . filterValue . getValue ( ) ) . toBe ( randomAuthor ) ;
95163 } ) ;
96164 } ) ;
165+
97166} ) ;
0 commit comments