Skip to content

Commit 7ad401d

Browse files
[DURACOM-455] set default as false, fix issue with missing default link, add tests
1 parent a77a7a4 commit 7ad401d

4 files changed

Lines changed: 131 additions & 2 deletions

File tree

src/app/item-page/simple/item-types/publication/publication.component.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ describe('PublicationComponent', () => {
9595
getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
9696
return createSuccessfulRemoteDataObject$(new Bitstream());
9797
},
98+
findPrimaryBitstreamByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable: boolean, reRequestOnStale: boolean): Observable<Bitstream | null> {
99+
return of(null);
100+
},
101+
findAllByItemAndBundleName(item: Item, bundleName: string, options: any, useCachedVersionIfAvailable: boolean, reRequestOnStale: boolean, ...linksToFollow: any[]): Observable<RemoteData<any>> {
102+
return createSuccessfulRemoteDataObject$(createPaginatedList([]));
103+
},
98104
};
99105
TestBed.configureTestingModule({
100106
imports: [
@@ -270,4 +276,63 @@ describe('PublicationComponent', () => {
270276
}));
271277

272278
});
279+
280+
describe('when showDownloadLinkAsAttachment is false', () => {
281+
beforeEach(waitForAsync(() => {
282+
TestBed.overrideComponent(PublicationComponent, {
283+
add: { changeDetection: ChangeDetectionStrategy.Default },
284+
remove: {
285+
imports: [
286+
ThemedFileSectionComponent,
287+
],
288+
},
289+
});
290+
TestBed.compileComponents();
291+
fixture = TestBed.createComponent(PublicationComponent);
292+
comp = fixture.componentInstance;
293+
comp.object = getItem(noMetadata);
294+
comp.showDownloadLinkAsAttachment = false;
295+
fixture.detectChanges();
296+
}));
297+
298+
it('should display the file section component', () => {
299+
const fileSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-file-section'));
300+
expect(fileSectionElements.length).toBe(1);
301+
});
302+
303+
it('should not display the attachment section component', () => {
304+
const attachmentSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-attachment-section'));
305+
expect(attachmentSectionElements.length).toBe(0);
306+
});
307+
});
308+
309+
describe('when showDownloadLinkAsAttachment is true', () => {
310+
beforeEach(waitForAsync(() => {
311+
TestBed.overrideComponent(PublicationComponent, {
312+
add: { changeDetection: ChangeDetectionStrategy.Default },
313+
remove: {
314+
imports: [
315+
ThemedFileSectionComponent,
316+
],
317+
},
318+
});
319+
TestBed.compileComponents();
320+
fixture = TestBed.createComponent(PublicationComponent);
321+
comp = fixture.componentInstance;
322+
comp.object = getItem(noMetadata);
323+
comp.showDownloadLinkAsAttachment = true;
324+
fixture.detectChanges();
325+
}));
326+
327+
it('should display the attachment section component', () => {
328+
const attachmentSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-attachment-section'));
329+
expect(attachmentSectionElements.length).toBe(1);
330+
});
331+
332+
it('should not display the file section component', () => {
333+
const fileSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-file-section'));
334+
expect(fileSectionElements.length).toBe(0);
335+
});
336+
});
337+
273338
});

src/app/item-page/simple/item-types/untyped-item/untyped-item.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ds-media-viewer [item]="object"></ds-media-viewer>
3131
</div>
3232
}
33-
@if (showDownloadLinkAsAttachment) {
33+
@if (showDownloadLinkAsAttachment !== true) {
3434
<ds-item-page-file-section [item]="object"></ds-item-page-file-section>
3535
}
3636
<ds-item-page-date-field [item]="object"></ds-item-page-date-field>

src/app/item-page/simple/item-types/untyped-item/untyped-item.component.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ describe('UntypedItemComponent', () => {
9797
getThumbnailFor(item: Item): Observable<RemoteData<Bitstream>> {
9898
return createSuccessfulRemoteDataObject$(new Bitstream());
9999
},
100+
findPrimaryBitstreamByItemAndName(item: Item, bundleName: string, useCachedVersionIfAvailable: boolean, reRequestOnStale: boolean): Observable<Bitstream | null> {
101+
return of(null);
102+
},
103+
findAllByItemAndBundleName(item: Item, bundleName: string, options: any, useCachedVersionIfAvailable: boolean, reRequestOnStale: boolean, ...linksToFollow: any[]): Observable<RemoteData<any>> {
104+
return createSuccessfulRemoteDataObject$(createPaginatedList([]));
105+
},
100106
};
101107
TestBed.configureTestingModule({
102108
imports: [
@@ -295,4 +301,62 @@ describe('UntypedItemComponent', () => {
295301

296302
});
297303

304+
describe('when showDownloadLinkAsAttachment is false', () => {
305+
beforeEach(waitForAsync(() => {
306+
TestBed.overrideComponent(UntypedItemComponent, {
307+
add: { changeDetection: ChangeDetectionStrategy.Default },
308+
remove: {
309+
imports: [
310+
ThemedFileSectionComponent,
311+
],
312+
},
313+
});
314+
TestBed.compileComponents();
315+
fixture = TestBed.createComponent(UntypedItemComponent);
316+
comp = fixture.componentInstance;
317+
comp.object = getItem(noMetadata);
318+
comp.showDownloadLinkAsAttachment = false;
319+
fixture.detectChanges();
320+
}));
321+
322+
it('should display the file section component', () => {
323+
const fileSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-file-section'));
324+
expect(fileSectionElements.length).toBe(1);
325+
});
326+
327+
it('should not display the attachment section component', () => {
328+
const attachmentSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-attachment-section'));
329+
expect(attachmentSectionElements.length).toBe(0);
330+
});
331+
});
332+
333+
describe('when showDownloadLinkAsAttachment is true', () => {
334+
beforeEach(waitForAsync(() => {
335+
TestBed.overrideComponent(UntypedItemComponent, {
336+
add: { changeDetection: ChangeDetectionStrategy.Default },
337+
remove: {
338+
imports: [
339+
ThemedFileSectionComponent,
340+
],
341+
},
342+
});
343+
TestBed.compileComponents();
344+
fixture = TestBed.createComponent(UntypedItemComponent);
345+
comp = fixture.componentInstance;
346+
comp.object = getItem(noMetadata);
347+
comp.showDownloadLinkAsAttachment = true;
348+
fixture.detectChanges();
349+
}));
350+
351+
it('should display the attachment section component', () => {
352+
const attachmentSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-attachment-section'));
353+
expect(attachmentSectionElements.length).toBe(1);
354+
});
355+
356+
it('should not display the file section component', () => {
357+
const fileSectionElements = fixture.debugElement.queryAll(By.css('ds-item-page-file-section'));
358+
expect(fileSectionElements.length).toBe(0);
359+
});
360+
});
361+
298362
});

src/config/default-app-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ export class DefaultAppConfig implements AppConfig {
748748
},
749749
},
750750
],
751-
showDownloadLinkAsAttachment: true,
751+
showDownloadLinkAsAttachment: false,
752752
advancedAttachmentRendering: {
753753
pagination: {
754754
enabled: true,

0 commit comments

Comments
 (0)