@@ -23,6 +23,8 @@ import {FileSizePipe} from '../../shared/utils/file-size-pipe';
2323import { HardRedirectService } from '../../core/services/hard-redirect.service' ;
2424import { getBitstreamDownloadRoute } from '../../app-routing-paths' ;
2525import { PLATFORM_ID } from '@angular/core' ;
26+ import { NotificationsService } from '../../shared/notifications/notifications.service' ;
27+ import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub' ;
2628
2729describe ( 'LuckySearchComponent' , ( ) => {
2830 let fixture : ComponentFixture < LuckySearchComponent > ;
@@ -98,6 +100,7 @@ describe('LuckySearchComponent', () => {
98100 { provide : BitstreamDataService , useValue : bitstreamDataService } ,
99101 { provide : HardRedirectService , useValue : hardRedirectService } ,
100102 { provide : PLATFORM_ID , useValue : 'browser' } ,
103+ { provide : NotificationsService , useValue : new NotificationsServiceStub ( ) } ,
101104 ] ,
102105 } )
103106 . compileComponents ( ) ;
@@ -195,7 +198,7 @@ describe('LuckySearchComponent', () => {
195198 bitstreamDataService . findByItem . withArgs ( itemUUID , 'ORIGINAL' , metadataFilters , { } )
196199 . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream ] ) ) ) ;
197200
198- component . currentFilter = { identifier : 'test' , value : 'test' } ;
201+ component . currentFilter = { identifier : 'test' , value : 'test' , bitstreamValue : 'test' } ;
199202 component . searchOptions$ = observableOf ( defaultPagination ) ;
200203
201204 spyOn ( ( component as any ) , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( data ) ) ;
@@ -227,94 +230,81 @@ describe('LuckySearchComponent', () => {
227230 } ) ;
228231
229232 describe ( 'one item is available' , ( ) => {
230- beforeEach ( ( ) => {
231- fixture = TestBed . createComponent ( LuckySearchComponent ) ;
232- component = fixture . componentInstance ;
233-
234- const bitstreamSearchTree = new UrlTree ( ) ;
235- bitstreamSearchTree . queryParams = {
236- index : 'testIndex' ,
237- value : 'testValue' ,
238- bitstreamMetadata : 'testMetadata' ,
239- bitstreamValue : 'testMetadataValue'
240- } ;
241-
242- const itemUUID = 'd317835d-7b06-4219-91e2-1191900cb897' ;
243- const firstSearchResult = Object . assign ( new SearchResult ( ) , {
244- indexableObject : Object . assign ( new DSpaceObject ( ) , {
245- id : 'd317835d-7b06-4219-91e2-1191900cb897' ,
246- uuid : itemUUID ,
247- name : 'My first publication' ,
248- metadata : {
249- 'dspace.entity.type' : [
250- { value : 'Publication' }
251- ]
252- }
253- } )
254- } ) ;
255- const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [ firstSearchResult ] ) ) ;
256- const metadataFilters = [ { metadataName : 'dc.title' , metadataValue : 'test.pdf' } ] as MetadataFilter [ ] ;
257- component . bitstreamFilters$ . next ( metadataFilters ) ;
258- bitstreamDataService . findByItem . withArgs ( itemUUID , 'ORIGINAL' , metadataFilters , { } )
259- . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream ] ) ) ) ;
260-
261- component . currentFilter = { identifier : 'test' , value : 'test' } ;
262- component . searchOptions$ = observableOf ( defaultPagination ) ;
263-
264- spyOn ( ( component as any ) , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( data ) ) ;
265- spyOn ( ( component as any ) , 'loadBitstreamsAndRedirectIfNeeded' ) . and . returnValue ( observableOf ( [ bitstream ] ) ) ;
266- spyOn ( ( component as any ) , 'hasBitstreamFilters' ) . and . returnValue ( true ) ;
267- spyOn ( component , 'redirect' ) ;
268- spyOn ( routerStub , 'parseUrl' ) . and . returnValue ( bitstreamSearchTree ) ;
269-
270- component . resultsRD$ . next ( data ) ;
271-
272- fixture . detectChanges ( ) ;
273- } ) ;
233+ beforeEach ( ( ) => {
234+ fixture = TestBed . createComponent ( LuckySearchComponent ) ;
235+ component = fixture . componentInstance ;
274236
275- it ( 'should create' , ( ) => {
276- expect ( component ) . toBeTruthy ( ) ;
277- } ) ;
237+ const bitstreamSearchTree = new UrlTree ( ) ;
238+ bitstreamSearchTree . queryParams = {
239+ index : 'testIndex' ,
240+ value : 'testValue' ,
241+ bitstreamMetadata : 'testMetadata' ,
242+ bitstreamValue : 'testMetadataValue'
243+ } ;
278244
279- it ( 'should redirect to item page when only one result is found' , ( ) => {
280- expect ( component . redirect ) . toHaveBeenCalled ( ) ;
245+ const itemUUID = 'd317835d-7b06-4219-91e2-1191900cb897' ;
246+ const firstSearchResult = Object . assign ( new SearchResult ( ) , {
247+ indexableObject : Object . assign ( new DSpaceObject ( ) , {
248+ id : 'd317835d-7b06-4219-91e2-1191900cb897' ,
249+ uuid : itemUUID ,
250+ name : 'My first publication' ,
251+ metadata : {
252+ 'dspace.entity.type' : [
253+ { value : 'Publication' }
254+ ]
255+ }
256+ } )
281257 } ) ;
282- } ) ;
258+ const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [ firstSearchResult ] ) ) ;
259+ const metadataFilters = [ { metadataName : 'dc.title' , metadataValue : 'test.pdf' } ] as MetadataFilter [ ] ;
260+ component . bitstreamFilters$ . next ( metadataFilters ) ;
261+ bitstreamDataService . findByItem . withArgs ( itemUUID , 'ORIGINAL' , metadataFilters , { } )
262+ . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream ] ) ) ) ;
283263
284- it ( 'should not redirect when no bitstreams are found' , ( ) => {
285- const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid-1' , name : 'Test item 1' } ) ;
286- const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [
287- { indexableObject : item , hitHighlights : { } }
288- ] ) ) as any ;
289- component . resultsRD$ . next ( data ) ;
290- component . bitstreamFilters$ . next ( [ { metadataName : 'dc.title' , metadataValue : 'Non-existent bitstream' } ] ) ;
291- bitstreamDataService . findByItem . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ) ;
264+ component . currentFilter = { identifier : 'test' , value : 'test' , bitstreamValue : 'test' } ;
265+ component . searchOptions$ = observableOf ( defaultPagination ) ;
266+
267+ spyOn ( ( component as any ) , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( data ) ) ;
268+ spyOn ( ( component as any ) , 'loadBitstreamsAndRedirectIfNeeded' ) . and . returnValue ( observableOf ( [ bitstream ] ) ) ;
269+ spyOn ( ( component as any ) , 'hasBitstreamFilters' ) . and . returnValue ( true ) ;
292270 spyOn ( component , 'redirect' ) ;
271+ spyOn ( routerStub , 'parseUrl' ) . and . returnValue ( bitstreamSearchTree ) ;
272+
273+ component . resultsRD$ . next ( data ) ;
274+
293275 fixture . detectChanges ( ) ;
294- expect ( component . redirect ) . not . toHaveBeenCalled ( ) ;
295276 } ) ;
296277
297- it ( 'should update showEmptySearchSection$ and showMultipleSearchSection$ based on search results' , ( ) => {
278+ it ( 'should create' , ( ) => {
279+ expect ( component ) . toBeTruthy ( ) ;
280+ } ) ;
281+
282+ it ( 'should redirect to item page when only one result is found' , ( ) => {
283+ expect ( component . redirect ) . toHaveBeenCalled ( ) ;
284+ } ) ;
285+ } ) ;
286+
287+ it ( 'should not redirect when no bitstreams are found' , ( ) => {
288+ const item = Object . assign ( new Item ( ) , { uuid : 'item-uuid-1' , name : 'Test item 1' } ) ;
289+ const data = createSuccessfulRemoteDataObject ( createPaginatedList ( [
290+ { indexableObject : item , hitHighlights : { } }
291+ ] ) ) as any ;
292+ component . resultsRD$ . next ( data ) ;
293+ component . bitstreamFilters$ . next ( [ { metadataName : 'dc.title' , metadataValue : 'Non-existent bitstream' } ] ) ;
294+ bitstreamDataService . findByItem . and . returnValue ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ ] ) ) ) ;
295+ spyOn ( component , 'redirect' ) ;
296+ fixture . detectChanges ( ) ;
297+ expect ( component . redirect ) . not . toHaveBeenCalled ( ) ;
298+ } ) ;
299+
300+ it ( 'should update showEmptySearchSection$ when no results are found' , ( ) => {
298301 const emptyResults = createSuccessfulRemoteDataObject ( createPaginatedList ( [ ] ) ) ;
299- const multipleResults = createSuccessfulRemoteDataObject ( createPaginatedList ( [
300- new SearchResult < DSpaceObject > ( ) ,
301- new SearchResult < DSpaceObject > ( )
302- ] ) ) ;
303302
304303 spyOn ( component as any , 'getLuckySearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
305304 spyOn ( component as any , 'processSearchResults' ) . and . returnValue ( observableOf ( emptyResults ) ) ;
306305
307306 component . getSearchResults ( ) ;
308307
309308 expect ( component . showEmptySearchSection$ . getValue ( ) ) . toBe ( true ) ;
310- expect ( component . showMultipleSearchSection$ . getValue ( ) ) . toBe ( false ) ;
311-
312- ( component as any ) . getLuckySearchResults . and . returnValue ( observableOf ( multipleResults ) ) ;
313- ( component as any ) . processSearchResults . and . returnValue ( observableOf ( multipleResults ) ) ;
314-
315- component . getSearchResults ( ) ;
316-
317- expect ( component . showEmptySearchSection$ . getValue ( ) ) . toBe ( false ) ;
318- expect ( component . showMultipleSearchSection$ . getValue ( ) ) . toBe ( true ) ;
319309 } ) ;
320310} ) ;
0 commit comments