@@ -130,6 +130,7 @@ describe('AdvancedAttachmentComponent', () => {
130130 return createSuccessfulRemoteDataObject$ ( new Bitstream ( ) ) ;
131131 } ,
132132 findAllByItemAndBundleName : jasmine . createSpy ( 'findAllByItemAndBundleName' ) ,
133+ findByItem : jasmine . createSpy ( 'findByItem' ) ,
133134 } ) ;
134135
135136 const mockAuthorizedService = jasmine . createSpyObj ( 'AuthorizationDataService' , {
@@ -169,7 +170,8 @@ describe('AdvancedAttachmentComponent', () => {
169170 mockAuthorizedService . isAuthorized . and . returnValues ( of ( true ) , of ( true ) ) ;
170171 component . envPagination . enabled = false ;
171172 mockBitstreamDataService . findAllByItemAndBundleName . and . returnValues ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream1 ] ) ) ) ;
172- let spy = spyOn ( component , 'getBitstreams' ) ;
173+ mockBitstreamDataService . findByItem . and . returnValues ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream1 ] ) ) ) ;
174+ let spy = spyOn ( component , 'getBitstreamsByItem' ) ;
173175 spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
174176 component . item = testItem ;
175177 fixture . detectChanges ( ) ;
@@ -181,7 +183,7 @@ describe('AdvancedAttachmentComponent', () => {
181183
182184 it ( 'should retrieve bitstreams without pagination' , fakeAsync ( ( ) => {
183185 flush ( ) ;
184- expect ( component . getBitstreams ) . toHaveBeenCalledWith ( ) ;
186+ expect ( component . getBitstreamsByItem ) . toHaveBeenCalled ( ) ;
185187 } ) ) ;
186188
187189 it ( 'should not show view more button' , fakeAsync ( ( ) => {
@@ -214,8 +216,8 @@ describe('AdvancedAttachmentComponent', () => {
214216 fixture = TestBed . createComponent ( AdvancedAttachmentComponent ) ;
215217 component = fixture . componentInstance ;
216218 de = fixture . debugElement ;
217- let spy = spyOn ( component , 'getBitstreams ' ) ;
218- spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
219+ let spy = spyOn ( component , 'getBitstreamsByItem ' ) ;
220+ spy . and . returnValue ( of ( createPaginatedList ( [ attachmentsMock [ 1 ] ] ) ) ) ;
219221 component . item = testItem ;
220222 fixture . detectChanges ( ) ;
221223 } ) ;
@@ -226,26 +228,6 @@ describe('AdvancedAttachmentComponent', () => {
226228
227229 } ) ;
228230
229- describe ( 'when the field has metadata key and value set as regex' , ( ) => {
230- beforeEach ( ( ) => {
231- // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
232- TestBed . resetTestingModule ( ) ;
233- TestBed . configureTestingModule ( getDefaultTestBedConf ( ) ) ;
234- TestBed . overrideProvider ( 'fieldProvider' , { useValue : mockFieldWithRegexMetadata } ) ;
235- fixture = TestBed . createComponent ( AdvancedAttachmentComponent ) ;
236- component = fixture . componentInstance ;
237- de = fixture . debugElement ;
238- let spy = spyOn ( component , 'getBitstreams' ) ;
239- spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
240- component . item = testItem ;
241- fixture . detectChanges ( ) ;
242- } ) ;
243-
244- it ( 'should show regex article attachment' , ( ) => {
245- expect ( de . query ( By . css ( '[data-test="dc.title"]' ) ) . nativeElement . innerHTML ) . toContain ( 'main-regex.pdf' ) ;
246- } ) ;
247-
248- } ) ;
249231 } ) ;
250232
251233 describe ( 'when pagination is enabled' , ( ) => {
@@ -256,8 +238,8 @@ describe('AdvancedAttachmentComponent', () => {
256238 de = fixture . debugElement ;
257239 mockAuthorizedService . isAuthorized . and . returnValues ( of ( true ) , of ( true ) ) ;
258240 component . envPagination . enabled = true ;
259- let spy = spyOn ( component , 'getBitstreams ' ) ;
260- spy . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 , bitstream1 , bitstream1 ] ) ) ) ;
241+ let spy = spyOn ( component , 'getBitstreamsByItem ' ) ;
242+ spy . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 ] ) ) ) ;
261243 component . item = testItem ;
262244 fixture . detectChanges ( ) ;
263245 } ) ;
@@ -271,7 +253,9 @@ describe('AdvancedAttachmentComponent', () => {
271253 } ) ;
272254
273255 it ( 'and view more button is clicked it should show 4 elements' , ( ) => {
256+ ( component . getBitstreamsByItem as any ) . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 ] ) ) ) ;
274257 const btn = fixture . debugElement . query ( By . css ( 'button[data-test="view-more"]' ) ) ;
258+ fixture . detectChanges ( ) ;
275259 btn . nativeElement . click ( ) ;
276260 fixture . detectChanges ( ) ;
277261 expect ( fixture . debugElement . queryAll ( By . css ( '[data-test="attachment-info"]' ) ) . length ) . toEqual ( 4 ) ;
@@ -292,7 +276,7 @@ describe('AdvancedAttachmentComponent', () => {
292276 component . envPagination . enabled = false ;
293277 component . envMetadata = [ ] ;
294278 mockBitstreamDataService . findAllByItemAndBundleName . and . returnValues ( createSuccessfulRemoteDataObject$ ( createPaginatedList ( [ bitstream1 ] ) ) ) ;
295- let spy = spyOn ( component , 'getBitstreams ' ) ;
279+ let spy = spyOn ( component , 'getBitstreamsByItem ' ) ;
296280 spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
297281 component . item = testItem ;
298282 fixture . detectChanges ( ) ;
@@ -304,7 +288,7 @@ describe('AdvancedAttachmentComponent', () => {
304288
305289 it ( 'should retrieve bitstreams without pagination' , fakeAsync ( ( ) => {
306290 flush ( ) ;
307- expect ( component . getBitstreams ) . toHaveBeenCalledWith ( ) ;
291+ expect ( component . getBitstreamsByItem ) . toHaveBeenCalled ( ) ;
308292 } ) ) ;
309293
310294 it ( 'should not show view more button' , fakeAsync ( ( ) => {
@@ -338,8 +322,8 @@ describe('AdvancedAttachmentComponent', () => {
338322 component = fixture . componentInstance ;
339323 component . envMetadata = [ ] ;
340324 de = fixture . debugElement ;
341- let spy = spyOn ( component , 'getBitstreams ' ) ;
342- spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
325+ let spy = spyOn ( component , 'getBitstreamsByItem ' ) ;
326+ spy . and . returnValue ( of ( createPaginatedList ( [ attachmentsMock [ 1 ] ] ) ) ) ;
343327 component . item = testItem ;
344328 fixture . detectChanges ( ) ;
345329 } ) ;
@@ -351,28 +335,6 @@ describe('AdvancedAttachmentComponent', () => {
351335
352336 } ) ;
353337
354- describe ( 'when the field has metadata key and value set as regex' , ( ) => {
355- beforeEach ( ( ) => {
356- // NOTE: Cannot override providers once components have been compiled, so TestBed needs to be reset
357- TestBed . resetTestingModule ( ) ;
358- TestBed . configureTestingModule ( getDefaultTestBedConf ( ) ) ;
359- TestBed . overrideProvider ( 'fieldProvider' , { useValue : mockFieldWithRegexMetadata } ) ;
360- fixture = TestBed . createComponent ( AdvancedAttachmentComponent ) ;
361- component = fixture . componentInstance ;
362- component . envMetadata = [ ] ;
363- de = fixture . debugElement ;
364- let spy = spyOn ( component , 'getBitstreams' ) ;
365- spy . and . returnValue ( of ( createPaginatedList ( attachmentsMock ) ) ) ;
366- component . item = testItem ;
367- fixture . detectChanges ( ) ;
368- } ) ;
369-
370- it ( 'should show regex article attachment' , ( ) => {
371- expect ( de . queryAll ( By . css ( '[data-test="attachment-info"]' ) ) . length ) . toBe ( 1 ) ;
372- expect ( de . query ( By . css ( '[data-test="dc.title"]' ) ) ) . toBeFalsy ( ) ;
373- } ) ;
374-
375- } ) ;
376338 } ) ;
377339
378340 describe ( 'when pagination is enabled' , ( ) => {
@@ -384,8 +346,8 @@ describe('AdvancedAttachmentComponent', () => {
384346 de = fixture . debugElement ;
385347 mockAuthorizedService . isAuthorized . and . returnValues ( of ( true ) , of ( true ) ) ;
386348 component . envPagination . enabled = true ;
387- let spy = spyOn ( component , 'getBitstreams ' ) ;
388- spy . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 , bitstream1 , bitstream1 ] ) ) ) ;
349+ let spy = spyOn ( component , 'getBitstreamsByItem ' ) ;
350+ spy . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 ] ) ) ) ;
389351 component . item = testItem ;
390352 fixture . detectChanges ( ) ;
391353 } ) ;
@@ -400,6 +362,8 @@ describe('AdvancedAttachmentComponent', () => {
400362
401363 it ( 'and view more button is clicked it should show 4 elements' , ( ) => {
402364 const btn = fixture . debugElement . query ( By . css ( 'button[data-test="view-more"]' ) ) ;
365+ ( component . getBitstreamsByItem as any ) . and . returnValue ( of ( createPaginatedList ( [ bitstream1 , bitstream1 ] ) ) ) ;
366+ fixture . detectChanges ( ) ;
403367 btn . nativeElement . click ( ) ;
404368 fixture . detectChanges ( ) ;
405369 expect ( fixture . debugElement . queryAll ( By . css ( '[data-test="attachment-info"]' ) ) . length ) . toEqual ( 4 ) ;
0 commit comments